|
24 | 24 | importmock# To be able to examine call_args.kwargs on a mock.
|
25 | 25 |
|
26 | 26 | importddt
|
27 |
| -importpytest |
28 | 27 |
|
29 | 28 | fromgitimportGit,refresh,GitCommandError,GitCommandNotFound,Repo,cmd
|
30 | 29 | fromgit.utilimportcwd,finalize_process
|
@@ -612,25 +611,34 @@ def test_successful_refresh_with_same_env_invalidates_cached_version_info(self):
|
612 | 611 | refresh()# The fake git at path1 has a different version now.
|
613 | 612 | self.assertEqual(new_git.version_info, (22,222,2))
|
614 | 613 |
|
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): |
| 614 | +deftest_successful_default_refresh_invalidates_cached_version_info(self): |
621 | 615 | """Refreshing updates version after a filesystem change adds a git command."""
|
| 616 | +# The key assertion here is the last. The others mainly verify the test itself. |
622 | 617 | withcontextlib.ExitStack()asstack:
|
623 | 618 | stack.enter_context(_rollback_refresh())
|
| 619 | + |
624 | 620 | path1=Path(stack.enter_context(_fake_git(11,111,1)))
|
625 | 621 | path2=Path(stack.enter_context(_fake_git(22,222,2)))
|
| 622 | + |
626 | 623 | new_path_var=f"{path1.parent}{os.pathsep}{path2.parent}"
|
627 | 624 | stack.enter_context(mock.patch.dict(os.environ, {"PATH":new_path_var}))
|
628 | 625 | stack.enter_context(_patch_out_env("GIT_PYTHON_GIT_EXECUTABLE"))
|
| 626 | + |
| 627 | +ifos.name=="nt": |
| 628 | +# On Windows, use a shell so "git" finds "git.cmd". (In the infrequent |
| 629 | +# case that this effect is desired in production code, it should not be |
| 630 | +# done with this technique. USE_SHELL=True is less secure and reliable, |
| 631 | +# as unintended shell expansions can occur, and is deprecated. Instead, |
| 632 | +# use a custom command, by setting the GIT_PYTHON_GIT_EXECUTABLE |
| 633 | +# environment variable to git.cmd or by passing git.cmd's full path to |
| 634 | +# git.refresh. Or wrap the script with a .exe shim. |
| 635 | +stack.enter_context(mock.patch.object(Git,"USE_SHELL",True)) |
| 636 | + |
629 | 637 | new_git=Git()
|
630 |
| -path2.rename(path2.with_stem("git")) |
| 638 | +path2.rename(path2.with_stem("git"))# "Install" git, "late" in the PATH. |
631 | 639 | refresh()
|
632 | 640 | self.assertEqual(new_git.version_info, (22,222,2),'before "downgrade"')
|
633 |
| -path1.rename(path1.with_stem("git")) |
| 641 | +path1.rename(path1.with_stem("git"))# "Install" another, higher priority. |
634 | 642 | self.assertEqual(new_git.version_info, (22,222,2),"stale version")
|
635 | 643 | refresh()
|
636 | 644 | self.assertEqual(new_git.version_info, (11,111,1),"fresh version")
|
|