From fca716382c630b4e08cab7eb4513128f6e4bd8b2 Mon Sep 17 00:00:00 2001 From: David Hotham Date: Sun, 24 Mar 2024 21:23:00 +0000 Subject: [PATCH] simplify handling of metadata locations --- tests/repositories/fixtures/python_hosted.py | 24 ++++++++++---------- tests/types.py | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/repositories/fixtures/python_hosted.py b/tests/repositories/fixtures/python_hosted.py index 0dfb5448625..a00f494e916 100644 --- a/tests/repositories/fixtures/python_hosted.py +++ b/tests/repositories/fixtures/python_hosted.py @@ -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"] @@ -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, diff --git a/tests/types.py b/tests/types.py index c334664af30..840545bf27f 100644 --- a/tests/types.py +++ b/tests/types.py @@ -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: ...