@@ -366,58 +366,65 @@ def test_git_checkout(
366366 mock_stdin ,
367367 run_task_mod ,
368368 mock_git_repo ,
369+ tmp_path ,
369370 base_rev ,
370371 head_ref ,
371372 files ,
372373 hash_key ,
373374):
374- with tempfile .TemporaryDirectory () as workdir :
375- destination = os .path .join (workdir , "destination" )
376- run_task_mod .git_checkout (
377- destination_path = destination ,
378- head_repo = mock_git_repo ["path" ],
379- base_repo = mock_git_repo ["path" ],
380- base_rev = base_rev ,
381- head_ref = head_ref ,
382- head_rev = None ,
383- ssh_key_file = None ,
384- ssh_known_hosts_file = None ,
385- )
375+ destination = tmp_path / "destination"
376+ run_task_mod .git_checkout (
377+ destination_path = destination ,
378+ head_repo = mock_git_repo ["path" ],
379+ base_repo = mock_git_repo ["path" ],
380+ base_rev = base_rev ,
381+ head_ref = head_ref ,
382+ head_rev = None ,
383+ ssh_key_file = None ,
384+ ssh_known_hosts_file = None ,
385+ )
386386
387- # Check desired files exist
388- for filename in files :
389- assert os .path .exists (os .path .join (destination , filename ))
387+ # Check desired files exist
388+ for filename in files :
389+ assert os .path .exists (os .path .join (destination , filename ))
390390
391- # Check repo is on the right branch
392- if head_ref :
393- current_branch = subprocess .check_output (
394- args = ["git" , "rev-parse" , "--abbrev-ref" , "HEAD" ],
395- cwd = destination ,
396- universal_newlines = True ,
397- ).strip ()
398- assert current_branch == head_ref
391+ # Check repo is on the right branch
392+ if head_ref :
393+ current_branch = subprocess .check_output (
394+ args = ["git" , "rev-parse" , "--abbrev-ref" , "HEAD" ],
395+ cwd = destination ,
396+ universal_newlines = True ,
397+ ).strip ()
398+ assert current_branch == head_ref
399399
400- current_rev = git_current_rev (destination )
401- assert current_rev == mock_git_repo [hash_key ]
400+ current_rev = git_current_rev (destination )
401+ assert current_rev == mock_git_repo [hash_key ]
402402
403403
404404def test_git_checkout_with_commit (
405405 mock_stdin ,
406406 run_task_mod ,
407407 mock_git_repo ,
408+ tmp_path ,
408409):
409- with tempfile .TemporaryDirectory () as workdir :
410- destination = os .path .join (workdir , "destination" )
411- run_task_mod .git_checkout (
412- destination_path = destination ,
413- head_repo = mock_git_repo ["path" ],
414- base_repo = mock_git_repo ["path" ],
415- base_rev = mock_git_repo ["main" ],
416- head_ref = mock_git_repo ["branch" ],
417- head_rev = mock_git_repo ["branch" ],
418- ssh_key_file = None ,
419- ssh_known_hosts_file = None ,
420- )
410+ destination = tmp_path / "destination"
411+ run_task_mod .git_checkout (
412+ destination_path = str (destination ),
413+ head_repo = mock_git_repo ["path" ],
414+ base_repo = mock_git_repo ["path" ],
415+ base_rev = mock_git_repo ["main" ],
416+ head_ref = "mybranch" ,
417+ head_rev = mock_git_repo ["branch" ],
418+ ssh_key_file = None ,
419+ ssh_known_hosts_file = None ,
420+ )
421+
422+ current_rev = subprocess .check_output (
423+ args = ["git" , "rev-parse" , "HEAD" ],
424+ cwd = str (destination ),
425+ universal_newlines = True ,
426+ ).strip ()
427+ assert current_rev == mock_git_repo ["branch" ]
421428
422429
423430def test_display_python_version_should_output_python_versions_title (
0 commit comments