@@ -8,7 +8,7 @@ load("//python/private:venv_runfiles.bzl", "build_link_map") # buildifier: disa
88
99_tests = []
1010
11- def _ctx (workspace_name ):
11+ def _ctx (workspace_name = "_main" ):
1212 return struct (
1313 workspace_name = workspace_name ,
1414 )
@@ -52,24 +52,160 @@ def _test_build_link_map(name):
5252
5353_tests .append (_test_build_link_map )
5454
55- def _test_build_link_map_impl (env , _ ):
55+ def _test_overlapping_and_merging (env , _ ):
5656 entries = [
5757 _entry ("a" , "+pypi_a/site-packages/a" , ["a.txt" ]),
5858 _entry ("a/b" , "+pypi_a_b/site-packages/a/b" , ["b.txt" ]),
5959 _entry ("x" , "_main/src/x" , ["x.txt" ]),
6060 _entry ("x/p" , "_main/src-dev/x/p" , ["p.txt" ]),
61+ _entry ("duplicate" , "+dupe_a/site-packages/duplicate" , ["d.py" ]),
62+ # This entry also provides a/x.py, but since the "a" entry is shorter
63+ # and comes first, its version of x.py should win.
64+ _entry ("duplicate" , "+dupe_b/site-packages/duplicate" , ["d.py" ]),
6165 ]
6266
63- actual = build_link_map (_ctx ("_main" ), entries )
67+ actual = build_link_map (_ctx (), entries )
6468 expected_libs = {
6569 "a/a.txt" : _file ("../+pypi_a/site-packages/a/a.txt" ),
6670 "a/b/b.txt" : _file ("../+pypi_a_b/site-packages/a/b/b.txt" ),
6771 "x/p/p.txt" : _file ("src-dev/x/p/p.txt" ),
6872 "x/x.txt" : _file ("src/x/x.txt" ),
73+ "duplicate/d.py" : _file ("../+dupe_a/site-packages/duplicate/d.py" ),
6974 }
7075 env .expect .that_dict (actual [VenvSymlinkKind .LIB ]).contains_exactly (expected_libs )
7176 env .expect .that_dict (actual ).keys ().contains_exactly ([VenvSymlinkKind .LIB ])
7277
78+ def _test_package_version_filtering (name ):
79+ analysis_test (
80+ name = name ,
81+ impl = _test_package_version_filtering_impl ,
82+ target = "//python:none" ,
83+ )
84+
85+ _tests .append (_test_package_version_filtering )
86+
87+ def _test_package_version_filtering_impl (env , _ ):
88+ entries = [
89+ _entry ("foo" , "+pypi_foo_v1/site-packages/foo" , ["foo.txt" ], package = "foo" , version = "1.0" ),
90+ _entry ("foo" , "+pypi_foo_v2/site-packages/foo" , ["bar.txt" ], package = "foo" , version = "2.0" ),
91+ ]
92+
93+ actual = build_link_map (_ctx (), entries )
94+ expected_libs = {
95+ "foo/foo.txt" : _file ("../+pypi_foo/site-packages/foo/foo.txt" ),
96+ }
97+ env .expect .that_dict (actual [VenvSymlinkKind .LIB ]).contains_exactly (expected_libs )
98+
99+ actual = build_link_map (_ctx (), entries )
100+ expected_libs = {
101+ "a/x.py" : _file ("../+pypi_a/site-packages/a/x.py" ),
102+ }
103+ env .expect .that_dict (actual [VenvSymlinkKind .LIB ]).contains_exactly (expected_libs )
104+
105+ def _test_malformed_entry (name ):
106+ analysis_test (
107+ name = name ,
108+ impl = _test_malformed_entry_impl ,
109+ target = "//python:none" ,
110+ )
111+
112+ _tests .append (_test_malformed_entry )
113+
114+ def _test_malformed_entry_impl (env , _ ):
115+ entries = [
116+ _entry (
117+ "a" ,
118+ "+pypi_a/site-packages/a" ,
119+ # This file is outside the link_to_path, so it should be ignored.
120+ ["../outside.txt" ],
121+ ),
122+ ]
123+
124+ actual = build_link_map (_ctx (), entries )
125+ env .expect .that_dict (actual ).is_empty ()
126+
127+ def _test_complex_namespace_packages (name ):
128+ analysis_test (
129+ name = name ,
130+ impl = _test_complex_namespace_packages_impl ,
131+ target = "//python:none" ,
132+ )
133+
134+ _tests .append (_test_complex_namespace_packages )
135+
136+ def _test_complex_namespace_packages_impl (env , _ ):
137+ entries = [
138+ _entry ("a/b" , "+pypi_a_b/site-packages/a/b" , ["b.txt" ]),
139+ _entry ("a/c" , "+pypi_a_c/site-packages/a/c" , ["c.txt" ]),
140+ _entry ("x/y/z" , "+pypi_x_y_z/site-packages/x/y/z" , ["z.txt" ]),
141+ _entry ("foo" , "+pypi_foo/site-packages/foo" , ["foo.txt" ]),
142+ _entry ("foobar" , "+pypi_foobar/site-packages/foobar" , ["foobar.txt" ]),
143+ ]
144+
145+ actual = build_link_map (_ctx (), entries )
146+ expected_libs = {
147+ "a/b/b.txt" : _file ("../+pypi_a_b/site-packages/a/b/b.txt" ),
148+ "a/c/c.txt" : _file ("../+pypi_a_c/site-packages/a/c/c.txt" ),
149+ "x/y/z/z.txt" : _file ("../+pypi_x_y_z/site-packages/x/y/z/z.txt" ),
150+ "foo/foo.txt" : _file ("../+pypi_foo/site-packages/foo/foo.txt" ),
151+ "foobar/foobar.txt" : _file ("../+pypi_foobar/site-packages/foobar/foobar.txt" ),
152+ }
153+ env .expect .that_dict (actual [VenvSymlinkKind .LIB ]).contains_exactly (expected_libs )
154+
155+ def _test_empty_and_trivial_inputs (name ):
156+ analysis_test (
157+ name = name ,
158+ impl = _test_empty_and_trivial_inputs_impl ,
159+ target = "//python:none" ,
160+ )
161+
162+ _tests .append (_test_empty_and_trivial_inputs )
163+
164+ def _test_empty_and_trivial_inputs_impl (env , _ ):
165+ # Test with empty list of entries
166+ actual = build_link_map (_ctx (), [])
167+ env .expect .that_dict (actual ).is_empty ()
168+
169+ # Test with an entry with no files
170+ entries = [_entry ("a" , "+pypi_a/site-packages/a" , [])]
171+ actual = build_link_map (_ctx (), entries )
172+ env .expect .that_dict (actual ).is_empty ()
173+
174+ def _test_multiple_venv_symlink_kinds (name ):
175+ analysis_test (
176+ name = name ,
177+ impl = _test_multiple_venv_symlink_kinds_impl ,
178+ target = "//python:none" ,
179+ )
180+
181+ _tests .append (_test_multiple_venv_symlink_kinds )
182+
183+ def _test_multiple_venv_symlink_kinds_impl (env , _ ):
184+ entries = [
185+ _entry ("libfile" , "+pypi_lib/site-packages/libfile" , ["lib.txt" ], kind = VenvSymlinkKind .LIB ),
186+ _entry ("binfile" , "+pypi_bin/bin/binfile" , ["bin.txt" ], kind = VenvSymlinkKind .BIN ),
187+ _entry ("includefile" , "+pypi_include/include/includefile" , ["include.h" ], kind = VenvSymlinkKind .INCLUDE ),
188+ ]
189+
190+ actual = build_link_map (_ctx (), entries )
191+ expected_libs = {
192+ "libfile/lib.txt" : _file ("../+pypi_lib/site-packages/libfile/lib.txt" ),
193+ }
194+ expected_bins = {
195+ "binfile/bin.txt" : _file ("../+pypi_bin/bin/binfile/bin.txt" ),
196+ }
197+ expected_includes = {
198+ "includefile/include.h" : _file ("../+pypi_include/include/includefile/include.h" ),
199+ }
200+ env .expect .that_dict (actual [VenvSymlinkKind .LIB ]).contains_exactly (expected_libs )
201+ env .expect .that_dict (actual [VenvSymlinkKind .BIN ]).contains_exactly (expected_bins )
202+ env .expect .that_dict (actual [VenvSymlinkKind .INCLUDE ]).contains_exactly (expected_includes )
203+ env .expect .that_dict (actual ).keys ().contains_exactly ([
204+ VenvSymlinkKind .LIB ,
205+ VenvSymlinkKind .BIN ,
206+ VenvSymlinkKind .INCLUDE ,
207+ ])
208+
73209def app_files_building_test_suite (name ):
74210 test_suite (
75211 name = name ,
0 commit comments