Skip to content

Commit 125ce54

Browse files
committed
Fix and add tests for optimized _FlatDirectorySource
1 parent 3fb2637 commit 125ce54

File tree

3 files changed

+54
-12
lines changed

3 files changed

+54
-12
lines changed

tests/functional/test_install_config.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,6 @@ def test_command_line_append_flags(
125125
"Fetching project page and analyzing links: https://test.pypi.org"
126126
in result.stdout
127127
)
128-
assert (
129-
f"Skipping link: not a file: {data.find_links}" in result.stdout
130-
), f"stdout: {result.stdout}"
131128

132129

133130
@pytest.mark.network
@@ -151,9 +148,6 @@ def test_command_line_appends_correctly(
151148
"Fetching project page and analyzing links: https://test.pypi.org"
152149
in result.stdout
153150
), result.stdout
154-
assert (
155-
f"Skipping link: not a file: {data.find_links}" in result.stdout
156-
), f"stdout: {result.stdout}"
157151

158152

159153
def test_config_file_override_stack(

tests/unit/test_collector.py

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ def test_collect_sources__file_expand_dir(data: TestData) -> None:
862862
)
863863
sources = collector.collect_sources(
864864
# Shouldn't be used.
865-
project_name=None, # type: ignore[arg-type]
865+
project_name="",
866866
candidates_from_page=None, # type: ignore[arg-type]
867867
)
868868
assert (
@@ -960,7 +960,7 @@ def test_fetch_response(self, mock_get_simple_response: mock.Mock) -> None:
960960
session=link_collector.session,
961961
)
962962

963-
def test_collect_sources(
963+
def test_collect_page_sources(
964964
self, caplog: pytest.LogCaptureFixture, data: TestData
965965
) -> None:
966966
caplog.set_level(logging.DEBUG)
@@ -993,9 +993,8 @@ def test_collect_sources(
993993
files = list(files_it)
994994
pages = list(pages_it)
995995

996-
# Spot-check the returned sources.
997-
assert len(files) > 20
998-
check_links_include(files, names=["simple-1.0.tar.gz"])
996+
# Only "twine" should return from collecting sources
997+
assert len(files) == 1
999998

1000999
assert [page.link for page in pages] == [Link("https://pypi.org/simple/twine/")]
10011000
# Check that index URLs are marked as *un*cacheable.
@@ -1010,6 +1009,52 @@ def test_collect_sources(
10101009
("pip._internal.index.collector", logging.DEBUG, expected_message),
10111010
]
10121011

1012+
def test_collect_file_sources(
1013+
self, caplog: pytest.LogCaptureFixture, data: TestData
1014+
) -> None:
1015+
caplog.set_level(logging.DEBUG)
1016+
1017+
link_collector = make_test_link_collector(
1018+
find_links=[data.find_links],
1019+
# Include two copies of the URL to check that the second one
1020+
# is skipped.
1021+
index_urls=[PyPI.simple_url, PyPI.simple_url],
1022+
)
1023+
collected_sources = link_collector.collect_sources(
1024+
"singlemodule",
1025+
candidates_from_page=lambda link: [
1026+
InstallationCandidate("singlemodule", "0.0.1", link)
1027+
],
1028+
)
1029+
1030+
files_it = itertools.chain.from_iterable(
1031+
source.file_links()
1032+
for sources in collected_sources
1033+
for source in sources
1034+
if source is not None
1035+
)
1036+
pages_it = itertools.chain.from_iterable(
1037+
source.page_candidates()
1038+
for sources in collected_sources
1039+
for source in sources
1040+
if source is not None
1041+
)
1042+
files = list(files_it)
1043+
_ = list(pages_it)
1044+
1045+
# singlemodule should return files
1046+
assert len(files) > 0
1047+
check_links_include(files, names=["singlemodule-0.0.1.tar.gz"])
1048+
1049+
expected_message = dedent(
1050+
"""\
1051+
1 location(s) to search for versions of singlemodule:
1052+
* https://pypi.org/simple/singlemodule/"""
1053+
)
1054+
assert caplog.record_tuples == [
1055+
("pip._internal.index.collector", logging.DEBUG, expected_message),
1056+
]
1057+
10131058

10141059
@pytest.mark.parametrize(
10151060
"find_links, no_index, suppress_no_index, expected",

tests/unit/test_finder.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ def test_skip_invalid_wheel_link(
128128
with pytest.raises(DistributionNotFound):
129129
finder.find_requirement(req, True)
130130

131-
assert "Skipping link: invalid wheel filename:" in caplog.text
131+
assert (
132+
"Could not find a version that satisfies the requirement invalid"
133+
" (from versions:" in caplog.text
134+
)
132135

133136
def test_not_find_wheel_not_supported(self, data: TestData) -> None:
134137
"""

0 commit comments

Comments
 (0)