|
24 | 24 | importmock# To be able to examine call_args.kwargs on a mock.
|
25 | 25 |
|
26 | 26 | importddt
|
| 27 | +importpytest |
27 | 28 |
|
28 | 29 | fromgitimportGit,refresh,GitCommandError,GitCommandNotFound,Repo,cmd
|
29 | 30 | fromgit.utilimportcwd,finalize_process
|
@@ -611,6 +612,30 @@ def test_successful_refresh_with_same_env_invalidates_cached_version_info(self):
|
611 | 612 | refresh()# The fake git at path1 has a different version now.
|
612 | 613 | self.assertEqual(new_git.version_info, (22,222,2))
|
613 | 614 |
|
| 615 | +@pytest.mark.xfail( |
| 616 | +os.name=="nt", |
| 617 | +reason="""Name "git" won't find .bat/.cmd (need shim, custom name, or shell)""", |
| 618 | +raises=GitCommandNotFound, |
| 619 | + ) |
| 620 | +deftest_successful_refresh_in_default_scenario_invalidates_cached_version(self): |
| 621 | +"""Refreshing updates version after a filesystem change adds a git command.""" |
| 622 | +withcontextlib.ExitStack()asstack: |
| 623 | +stack.enter_context(_rollback_refresh()) |
| 624 | +path1=Path(stack.enter_context(_fake_git(11,111,1))) |
| 625 | +path2=Path(stack.enter_context(_fake_git(22,222,2))) |
| 626 | +sep=os.pathsep |
| 627 | +new_path_var=f"{path1.parent}{sep}{path2.parent}{sep}{os.environ['PATH']}" |
| 628 | +stack.enter_context(mock.patch.dict(os.environ, {"PATH":new_path_var})) |
| 629 | +stack.enter_context(_patch_out_env("GIT_PYTHON_GIT_EXECUTABLE")) |
| 630 | +new_git=Git() |
| 631 | +path2.rename(path2.with_stem("git")) |
| 632 | +refresh() |
| 633 | +self.assertEqual(new_git.version_info, (22,222,2),'before "downgrade"') |
| 634 | +path1.rename(path1.with_stem("git")) |
| 635 | +self.assertEqual(new_git.version_info, (22,222,2),"stale version") |
| 636 | +refresh() |
| 637 | +self.assertEqual(new_git.version_info, (11,111,1),"fresh version") |
| 638 | + |
614 | 639 | deftest_options_are_passed_to_git(self):
|
615 | 640 | # This works because any command after git --version is ignored.
|
616 | 641 | git_version=self.git(version=True).NoOp()
|
|