-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: refactor and fix repository fixtures
This change introduces httpretty based mocking for tests using mocked legacy or pypi repositories. This also fixes various issues with tests incorrectly relying on remote versions for metadata and distributions instead of expected mocked versions. Additionally, we also auto enables PyPI repository mocking to ensure no external requests are made without explicit handling. Further, a new `generate.py` script has now been added to help regenerate existing repository json and distribution fixtures; or add/remove release versions to the fixtures.
- Loading branch information
Showing
194 changed files
with
3,166 additions
and
1,817 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +0,0 @@ | ||
from __future__ import annotations | ||
|
||
import re | ||
|
||
from pathlib import Path | ||
from typing import TYPE_CHECKING | ||
from typing import Any | ||
from urllib.parse import urlparse | ||
|
||
import pytest | ||
|
||
|
||
if TYPE_CHECKING: | ||
from httpretty import httpretty | ||
from httpretty.core import HTTPrettyRequest | ||
|
||
from tests.types import FixtureDirGetter | ||
|
||
|
||
@pytest.fixture | ||
def mock_file_downloads(http: type[httpretty], fixture_dir: FixtureDirGetter) -> None: | ||
def callback( | ||
request: HTTPrettyRequest, uri: str, headers: dict[str, Any] | ||
) -> list[int | dict[str, Any] | bytes]: | ||
name = Path(urlparse(uri).path).name | ||
|
||
fixture = Path(__file__).parent.parent.joinpath( | ||
"repositories/fixtures/pypi.org/dists/" + name | ||
) | ||
|
||
if not fixture.exists(): | ||
fixture = fixture_dir("distributions") / name | ||
|
||
if not fixture.exists(): | ||
fixture = ( | ||
fixture_dir("distributions") / "demo-0.1.0-py2.py3-none-any.whl" | ||
) | ||
|
||
return [200, headers, fixture.read_bytes()] | ||
|
||
http.register_uri( | ||
http.GET, | ||
re.compile("^https://files.pythonhosted.org/.*$"), | ||
body=callback, | ||
) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.