@@ -862,7 +862,7 @@ def test_collect_sources__file_expand_dir(data: TestData) -> None:
862
862
)
863
863
sources = collector .collect_sources (
864
864
# Shouldn't be used.
865
- project_name = None , # type: ignore[arg-type]
865
+ project_name = "" ,
866
866
candidates_from_page = None , # type: ignore[arg-type]
867
867
)
868
868
assert (
@@ -960,7 +960,7 @@ def test_fetch_response(self, mock_get_simple_response: mock.Mock) -> None:
960
960
session = link_collector .session ,
961
961
)
962
962
963
- def test_collect_sources (
963
+ def test_collect_page_sources (
964
964
self , caplog : pytest .LogCaptureFixture , data : TestData
965
965
) -> None :
966
966
caplog .set_level (logging .DEBUG )
@@ -993,9 +993,8 @@ def test_collect_sources(
993
993
files = list (files_it )
994
994
pages = list (pages_it )
995
995
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
999
998
1000
999
assert [page .link for page in pages ] == [Link ("https://pypi.org/simple/twine/" )]
1001
1000
# Check that index URLs are marked as *un*cacheable.
@@ -1010,6 +1009,52 @@ def test_collect_sources(
1010
1009
("pip._internal.index.collector" , logging .DEBUG , expected_message ),
1011
1010
]
1012
1011
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
+
1013
1058
1014
1059
@pytest .mark .parametrize (
1015
1060
"find_links, no_index, suppress_no_index, expected" ,
0 commit comments