@@ -51,6 +51,92 @@ def test_seed_image_compiles_in_isolation(
5151 assert not marker .exists ()
5252
5353
54+ @pytest .mark .parametrize (
55+ ("metadata_file" , "content" ),
56+ [
57+ pytest .param ("top_level.txt" , "pip\n {dest}\n " , id = "top-level-env-root" ),
58+ pytest .param ("top_level.txt" , "pip\n \n " , id = "top-level-blank" ),
59+ pytest .param ("RECORD" , "{record}\n {outside},," , id = "record-traversal" ),
60+ ],
61+ )
62+ def test_seed_metadata_cleanup_stays_inside_package (
63+ tmp_path : Path , caplog : pytest .LogCaptureFixture , metadata_file : str , content : str
64+ ) -> None :
65+ args : Final = [str (tmp_path / "env" ), "--pip" , "embed" , "--no-periodic-update" ]
66+ session : Final = cli_run (args , setup_logging = False )
67+ purelib : Final = session .creator .purelib
68+ markers : Final = [tmp_path / "keep.txt" , session .creator .dest / "keep.txt" , purelib / "keep.txt" ]
69+ for marker in markers :
70+ marker .write_text ("keep" , encoding = "utf-8" )
71+ dist_info : Final = next (purelib .glob ("pip-*.dist-info" ))
72+ (dist_info / metadata_file ).write_text (
73+ content .format (
74+ dest = session .creator .dest ,
75+ outside = os .path .relpath (markers [0 ], purelib ),
76+ record = (dist_info / "RECORD" ).read_text (encoding = "utf-8" ),
77+ ),
78+ encoding = "utf-8" ,
79+ )
80+ cli_run (args , setup_logging = False )
81+ assert (
82+ [i .exists () for i in markers ],
83+ (purelib / "pip" / "__init__.py" ).is_file (),
84+ "skip removal of" in caplog .text ,
85+ ) == (
86+ [True , True , True ],
87+ True ,
88+ True ,
89+ )
90+
91+
92+ @pytest .mark .skipif (not fs_supports_symlink (), reason = "symlinks are unavailable" )
93+ def test_seed_metadata_unlinks_symlink_without_following (tmp_path : Path , caplog : pytest .LogCaptureFixture ) -> None :
94+ args : Final = [str (tmp_path / "env" ), "--pip" , "embed" , "--no-periodic-update" ]
95+ session : Final = cli_run (args , setup_logging = False )
96+ outside : Final = tmp_path / "outside"
97+ outside .mkdir ()
98+ (outside / "keep.txt" ).write_text ("keep" , encoding = "utf-8" )
99+ link : Final = session .creator .purelib / "linked"
100+ link .symlink_to (outside , target_is_directory = True )
101+ record : Final = next (session .creator .purelib .glob ("pip-*.dist-info" )) / "RECORD"
102+ record .write_text (f"{ record .read_text (encoding = 'utf-8' )} \n linked,," , encoding = "utf-8" )
103+ cli_run (args , setup_logging = False )
104+ assert (link .is_symlink (), (outside / "keep.txt" ).exists (), "skip removal of" in caplog .text ) == (
105+ False ,
106+ True ,
107+ False ,
108+ )
109+
110+
111+ @pytest .mark .parametrize (
112+ "linked" ,
113+ [
114+ pytest .param (False , id = "copy" ),
115+ pytest .param (
116+ True , id = "symlink" , marks = pytest .mark .skipif (not fs_supports_symlink (), reason = "symlinks are unavailable" )
117+ ),
118+ ],
119+ )
120+ def test_seed_metadata_keeps_reseeding_supported (
121+ tmp_path : Path , linked : bool , caplog : pytest .LogCaptureFixture
122+ ) -> None :
123+ args : Final = [
124+ str (tmp_path / "env" ),
125+ "--pip" ,
126+ "embed" ,
127+ "--no-periodic-update" ,
128+ * (["--symlink-app-data" ] if linked else []),
129+ ]
130+ cli_run (args , setup_logging = False )
131+ session : Final = cli_run (args , setup_logging = False )
132+ package : Final = session .creator .purelib / "pip"
133+ assert ((package / "__init__.py" ).is_file (), package .is_symlink (), "skip removal of" in caplog .text ) == (
134+ True ,
135+ linked ,
136+ False ,
137+ )
138+
139+
54140@pytest .mark .slow
55141@pytest .mark .parametrize ("copies" , [False , True ] if fs_supports_symlink () else [True ])
56142def test_seed_link_via_app_data (tmp_path , coverage_env , current_fastest , copies ) -> None :
0 commit comments