swh.core.github.pytest_plugin module#

swh.core.github.pytest_plugin.fake_time_sleep(duration: float, sleep_calls: Optional[List[float]] = None)[source]#

Record calls to time.sleep in the sleep_calls list.


Return 0 when running time.time()

swh.core.github.pytest_plugin.monkeypatch_sleep_calls(monkeypatch) Iterator[List[float]][source]#

Monkeypatch time.time and time.sleep. Returns a list cumulating the arguments passed to time.sleep().

swh.core.github.pytest_plugin.num_before_ratelimit() int[source]#

Number of successful requests before the ratelimit hits

swh.core.github.pytest_plugin.num_ratelimit() Optional[int][source]#

Number of rate-limited requests; None means infinity

swh.core.github.pytest_plugin.ratelimit_reset() Optional[int][source]#

Value of the X-Ratelimit-Reset header on ratelimited responses

swh.core.github.pytest_plugin.github_ratelimit_callback(request: _RequestObjectProxy, context: _Context, remaining_requests: int, ratelimit_reset: Optional[int]) Dict[str, str][source]#

Return a rate-limited GitHub API response.

swh.core.github.pytest_plugin.github_repo(i: int) Dict[str, Union[int, str]][source]#

Basic repository information returned by the GitHub API

swh.core.github.pytest_plugin.github_response_callback(request: _RequestObjectProxy, context: _Context, remaining_requests: int, page_size: int = 1000, origin_count: int = 10000) List[Dict[str, Union[int, str]]][source]#

Return minimal GitHub API responses for the common case where the loader hasn’t been rate-limited

swh.core.github.pytest_plugin.github_requests_ratelimited(num_before_ratelimit: int, num_ratelimit: Optional[int], ratelimit_reset: Optional[int]) Iterator[Mocker][source]#

Mock requests to the GitHub API, returning a rate-limiting status code after num_before_ratelimit requests.

GitHub does inconsistent rate-limiting:

  • Anonymous requests return a 403 status code

  • Authenticated requests return a 429 status code, with an X-Ratelimit-Reset header.

This fixture takes multiple arguments (which can be overridden with a pytest.mark.parametrize() parameter):

  • num_before_ratelimit: the global number of requests until the ratelimit triggers

  • num_ratelimit: the number of requests that return a rate-limited response.

  • ratelimit_reset: the timestamp returned in X-Ratelimit-Reset if the request is authenticated.

The default values set in the previous fixtures make all requests return a rate limit response.

swh.core.github.pytest_plugin.github_credentials() List[Dict[str, str]][source]#

Return a static list of GitHub credentials

swh.core.github.pytest_plugin.all_tokens(github_credentials) List[str][source]#

Return the list of tokens matching the static credential