@@ -174,7 +174,7 @@ impl Locator for Homebrew {
174174#[ cfg( all( test, unix) ) ]
175175mod tests {
176176 use super :: * ;
177- use std :: time :: { SystemTime , UNIX_EPOCH } ;
177+ use tempfile :: tempdir ;
178178
179179 struct TestEnvironment {
180180 homebrew_prefix : Option < String > ,
@@ -202,19 +202,6 @@ mod tests {
202202 }
203203 }
204204
205- fn create_test_dir ( name : & str ) -> PathBuf {
206- let unique = SystemTime :: now ( )
207- . duration_since ( UNIX_EPOCH )
208- . unwrap ( )
209- . as_nanos ( ) ;
210- let directory = std:: env:: temp_dir ( ) . join ( format ! (
211- "pet-homebrew-{name}-{}-{unique}" ,
212- std:: process:: id( )
213- ) ) ;
214- fs:: create_dir_all ( & directory) . unwrap ( ) ;
215- directory
216- }
217-
218205 #[ test]
219206 fn homebrew_locator_reports_kind_and_supported_category ( ) {
220207 let locator = Homebrew :: from ( & TestEnvironment {
@@ -273,24 +260,25 @@ mod tests {
273260 homebrew_prefix : None ,
274261 } ) ;
275262
276- let venv_root = create_test_dir ( "venv-reject" ) ;
277- let venv_bin = venv_root. join ( "bin" ) ;
263+ let venv_root = tempdir ( ) . unwrap ( ) ;
264+ let venv_bin = venv_root. path ( ) . join ( "bin" ) ;
278265 fs:: create_dir_all ( & venv_bin) . unwrap ( ) ;
279266 fs:: write ( venv_bin. join ( "activate" ) , b"" ) . unwrap ( ) ;
280267 let venv_executable = venv_bin. join ( "python3.12" ) ;
281268 fs:: write ( & venv_executable, b"" ) . unwrap ( ) ;
282- let venv = PythonEnv :: new ( venv_executable, Some ( venv_root. clone ( ) ) , None ) ;
269+ let venv = PythonEnv :: new ( venv_executable, Some ( venv_root. path ( ) . to_path_buf ( ) ) , None ) ;
283270 assert ! ( locator. try_from( & venv) . is_none( ) ) ;
284271
285- let conda_root = create_test_dir ( "conda-reject" ) ;
286- fs:: create_dir_all ( conda_root. join ( "conda-meta" ) ) . unwrap ( ) ;
287- let conda_executable = conda_root. join ( "bin" ) . join ( "python3.12" ) ;
272+ let conda_root = tempdir ( ) . unwrap ( ) ;
273+ fs:: create_dir_all ( conda_root. path ( ) . join ( "conda-meta" ) ) . unwrap ( ) ;
274+ let conda_executable = conda_root. path ( ) . join ( "bin" ) . join ( "python3.12" ) ;
288275 fs:: create_dir_all ( conda_executable. parent ( ) . unwrap ( ) ) . unwrap ( ) ;
289276 fs:: write ( & conda_executable, b"" ) . unwrap ( ) ;
290- let conda = PythonEnv :: new ( conda_executable, Some ( conda_root. clone ( ) ) , None ) ;
277+ let conda = PythonEnv :: new (
278+ conda_executable,
279+ Some ( conda_root. path ( ) . to_path_buf ( ) ) ,
280+ None ,
281+ ) ;
291282 assert ! ( locator. try_from( & conda) . is_none( ) ) ;
292-
293- fs:: remove_dir_all ( venv_root) . unwrap ( ) ;
294- fs:: remove_dir_all ( conda_root) . unwrap ( ) ;
295283 }
296284}
0 commit comments