-
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: add stubbed mock dists and improve mocking
- Loading branch information
Showing
94 changed files
with
182 additions
and
304 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
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
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.