Skip to content

Commit

Permalink
simplify handling of metadata locations
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbleby authored and neersighted committed Mar 28, 2024
1 parent cb41518 commit 77d67b6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
24 changes: 12 additions & 12 deletions tests/repositories/fixtures/python_hosted.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@
@pytest.fixture
def mock_files_python_hosted_factory(http: type[httpretty]) -> PythonHostedFileMocker:
def factory(
distribution_locations: list[Path], metadata_locations: list[Path] | None = None
distribution_locations: list[Path], metadata_locations: list[Path]
) -> None:
def file_callback(
request: HTTPrettyRequest, uri: str, headers: dict[str, Any]
) -> list[int | dict[str, Any] | bytes | str]:
name = Path(urlparse(uri).path).name

if metadata_locations and name.endswith(".metadata"):
for location in metadata_locations:
fixture = location / name
if fixture.exists():
return [200, headers, fixture.read_bytes()]
else:
for location in distribution_locations:
fixture = location / name
if fixture.exists():
return [200, headers, fixture.read_bytes()]
locations = (
metadata_locations
if name.endswith(".metadata")
else distribution_locations
)

for location in locations:
fixture = location / name
if fixture.exists():
return [200, headers, fixture.read_bytes()]

return [404, headers, b"Not Found"]

Expand Down Expand Up @@ -68,7 +68,7 @@ def mock_file_callback(
def mock_files_python_hosted(
mock_files_python_hosted_factory: PythonHostedFileMocker,
package_distribution_locations: list[Path],
package_metadata_locations: list[Path] | None,
package_metadata_locations: list[Path],
) -> Iterator[None]:
mock_files_python_hosted_factory(
distribution_locations=package_distribution_locations,
Expand Down
2 changes: 1 addition & 1 deletion tests/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class PythonHostedFileMocker(Protocol):
def __call__(
self,
distribution_locations: list[Path],
metadata_locations: list[Path] | None = None,
metadata_locations: list[Path],
) -> None: ...


Expand Down

0 comments on commit 77d67b6

Please sign in to comment.