Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitee385bd

Browse files
committed
Make "install" and refresh version_info test portable
This enables it to run on Windows, removing the xfail marking.+ Rename the test.+ Add comments and reformat.The test still does not pass (on any platform) because it is one ofthe tests of the invalidation feature that is not yet implemented.
1 parentc2d72ff commitee385bd

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

‎test/test_git.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
importmock# To be able to examine call_args.kwargs on a mock.
2525

2626
importddt
27-
importpytest
2827

2928
fromgitimportGit,refresh,GitCommandError,GitCommandNotFound,Repo,cmd
3029
fromgit.utilimportcwd,finalize_process
@@ -612,25 +611,34 @@ def test_successful_refresh_with_same_env_invalidates_cached_version_info(self):
612611
refresh()# The fake git at path1 has a different version now.
613612
self.assertEqual(new_git.version_info, (22,222,2))
614613

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):
621615
"""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.
622617
withcontextlib.ExitStack()asstack:
623618
stack.enter_context(_rollback_refresh())
619+
624620
path1=Path(stack.enter_context(_fake_git(11,111,1)))
625621
path2=Path(stack.enter_context(_fake_git(22,222,2)))
622+
626623
new_path_var=f"{path1.parent}{os.pathsep}{path2.parent}"
627624
stack.enter_context(mock.patch.dict(os.environ, {"PATH":new_path_var}))
628625
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+
629637
new_git=Git()
630-
path2.rename(path2.with_stem("git"))
638+
path2.rename(path2.with_stem("git"))# "Install" git, "late" in the PATH.
631639
refresh()
632640
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.
634642
self.assertEqual(new_git.version_info, (22,222,2),"stale version")
635643
refresh()
636644
self.assertEqual(new_git.version_info, (11,111,1),"fresh version")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp