@@ -43,17 +43,22 @@ def all_files(top_path):
4343@pytest .mark .parametrize ("optimize" , [None , "0" , "1,2" , "all" ])
4444@pytest .mark .parametrize ("prefix" , ["/usr" , "/eprefix/usr" ])
4545@pytest .mark .parametrize ("overwrite" , [False , True ])
46+ @pytest .mark .parametrize ("symlink_pyc" , [False , True ])
4647def test_install_wheel (tmp_path ,
4748 optimize : typing .Optional [str ],
4849 prefix : str ,
49- overwrite : bool ):
50+ overwrite : bool ,
51+ symlink_pyc : bool ,
52+ ):
5053 args = (["" , "install-wheel" ,
5154 "--destdir" , str (tmp_path ),
5255 "--interpreter" , "/usr/bin/pythontest" ,
5356 "test/test-pkg/dist/test-1-py3-none-any.whl" ] +
5457 (["--prefix" , prefix ] if prefix != "/usr" else []) +
5558 (["--optimize" , optimize ]
56- if optimize is not None else []))
59+ if optimize is not None else []) +
60+ (["--symlink-pyc" ] if symlink_pyc else [])
61+ )
5762 assert 0 == main (args )
5863
5964 expected_overwrite = (contextlib .nullcontext () if overwrite
@@ -99,7 +104,10 @@ def test_install_wheel(tmp_path,
99104 pyc = importlib .util .cache_from_source (
100105 init_mod , optimization = opt if opt != 0 else "" )
101106 expected [pathlib .Path (pyc )] = (
102- nonexec , False , pathlib .Path (f"/{ init_mod } " ))
107+ nonexec ,
108+ # our only symlinking opportunity is 1 -> 0
109+ symlink_pyc and opt == 1 and 0 in opt_levels ,
110+ pathlib .Path (f"/{ init_mod } " ))
103111
104112 assert expected == dict (all_files (tmp_path ))
105113
@@ -129,14 +137,18 @@ def test_install_self(tmp_path):
129137 "remove-dir" ,
130138 "modify-file" ,
131139 ])
140+ @pytest .mark .parametrize ("symlink_pyc" , [False , True ])
132141def test_install_symlink_to (tmp_path ,
133142 optimize : typing .Optional [str ],
134143 modification : str ,
144+ symlink_pyc : bool ,
135145 ) -> None :
136146 args = (["" , "install-wheel" ,
137147 "--destdir" , str (tmp_path ),
138148 "test/symlink-pkg/dist/foo-0-py3-none-any.whl" ] +
139- (["--optimize" , optimize ] if optimize is not None else []))
149+ (["--optimize" , optimize ] if optimize is not None else []) +
150+ (["--symlink-pyc" ] if symlink_pyc else [])
151+ )
140152 assert 0 == main (args + ["--prefix" , "/first" ])
141153
142154 sitedir = pathlib .PurePath (
@@ -196,7 +208,10 @@ def test_install_symlink_to(tmp_path,
196208 pyc = importlib .util .cache_from_source (
197209 path , optimization = opt if opt != 0 else "" )
198210 expected [pathlib .Path (pyc )] = (
199- False , False , pathlib .Path ("/" , path ))
211+ False ,
212+ symlink_pyc and
213+ (opt == 1 or (opt != 0 and path .name == "__init__.py" )),
214+ pathlib .Path ("/" , path ))
200215
201216 if modification == "remove-files" :
202217 del expected [pathlib .Path (f"first/{ sitedir } /foo/a.py" )]
0 commit comments