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

Commit147e80b

Browse files
committed
Test current initial-refresh behavior
This adds tests of the initial refresh that is attemptedautomatically on import. All the refresh tests prior to this pointtest subsequent refreshes. Those tests are kept, and new ones areadded that simulate the condition of not having yet done theinitial refresh by setting Git.GIT_PYTHON_GIT_EXECUTABLE to None.Some current behavior these tests assert may change for#1808.
1 parent8dc8eb9 commit147e80b

File tree

1 file changed

+76
-1
lines changed

1 file changed

+76
-1
lines changed

‎test/test_git.py

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
importcontextlib
77
importgc
88
importinspect
9+
importio
910
importlogging
1011
importos
1112
importos.pathasosp
@@ -329,6 +330,80 @@ def test_cmd_override(self):
329330
):
330331
self.assertRaises(GitCommandNotFound,self.git.version)
331332

333+
deftest_git_exc_name_is_git(self):
334+
self.assertEqual(self.git.git_exec_name,"git")
335+
336+
@ddt.data(("0",), ("q",), ("quiet",), ("s",), ("silence",), ("n",), ("none",))
337+
deftest_initial_refresh_from_bad_git_path_env_quiet(self,case):
338+
"""In "q" mode, bad initial path sets "git" and is quiet."""
339+
(mode,)=case
340+
set_vars= {
341+
"GIT_PYTHON_GIT_EXECUTABLE":str(Path("yada").absolute()),# Any bad path.
342+
"GIT_PYTHON_REFRESH":mode,
343+
}
344+
with_rollback_refresh():
345+
type(self.git).GIT_PYTHON_GIT_EXECUTABLE=None# Simulate startup.
346+
347+
withmock.patch.dict(os.environ,set_vars):
348+
refresh()
349+
self.assertEqual(self.git.GIT_PYTHON_GIT_EXECUTABLE,"git")
350+
351+
@ddt.data(("1",), ("w",), ("warn",), ("warning",))
352+
deftest_initial_refresh_from_bad_git_path_env_warn(self,case):
353+
"""In "w" mode, bad initial path sets "git" and warns."""
354+
(mode,)=case
355+
env_vars= {
356+
"GIT_PYTHON_GIT_EXECUTABLE":str(Path("yada").absolute()),# Any bad path.
357+
"GIT_PYTHON_REFRESH":mode,
358+
}
359+
with_rollback_refresh():
360+
type(self.git).GIT_PYTHON_GIT_EXECUTABLE=None# Simulate startup.
361+
362+
withmock.patch.dict(os.environ,env_vars):
363+
withcontextlib.redirect_stdout(io.StringIO())asout:
364+
refresh()
365+
self.assertRegex(out.getvalue(),r"\AWARNING: Bad git executable.\n")
366+
self.assertEqual(self.git.GIT_PYTHON_GIT_EXECUTABLE,"git")
367+
368+
@ddt.data(("2",), ("r",), ("raise",), ("e",), ("error",))
369+
deftest_initial_refresh_from_bad_git_path_env_error(self,case):
370+
"""In "e" mode, bad initial path raises an exception."""
371+
(mode,)=case
372+
env_vars= {
373+
"GIT_PYTHON_GIT_EXECUTABLE":str(Path("yada").absolute()),# Any bad path.
374+
"GIT_PYTHON_REFRESH":mode,
375+
}
376+
with_rollback_refresh():
377+
type(self.git).GIT_PYTHON_GIT_EXECUTABLE=None# Simulate startup.
378+
379+
withmock.patch.dict(os.environ,env_vars):
380+
withself.assertRaisesRegex(ImportError,r"\ABad git executable.\n"):
381+
refresh()
382+
383+
deftest_initial_refresh_from_good_absolute_git_path_env(self):
384+
"""Good initial absolute path from environment is set."""
385+
absolute_path=shutil.which("git")
386+
387+
with_rollback_refresh():
388+
type(self.git).GIT_PYTHON_GIT_EXECUTABLE=None# Simulate startup.
389+
390+
withmock.patch.dict(os.environ, {"GIT_PYTHON_GIT_EXECUTABLE":absolute_path}):
391+
refresh()
392+
self.assertEqual(self.git.GIT_PYTHON_GIT_EXECUTABLE,absolute_path)
393+
394+
deftest_initial_refresh_from_good_relative_git_path_env(self):
395+
"""Good initial relative path from environment is kept relative and set."""
396+
with_rollback_refresh():
397+
# Set the fallback to a string that wouldn't work and isn't "git", so we are
398+
# more likely to detect if "git" is not set from the environment variable.
399+
withmock.patch.object(type(self.git),"git_exec_name",""):
400+
type(self.git).GIT_PYTHON_GIT_EXECUTABLE=None# Simulate startup.
401+
402+
# Now observe if setting the environment variable to "git" takes effect.
403+
withmock.patch.dict(os.environ, {"GIT_PYTHON_GIT_EXECUTABLE":"git"}):
404+
refresh()
405+
self.assertEqual(self.git.GIT_PYTHON_GIT_EXECUTABLE,"git")
406+
332407
deftest_refresh_from_bad_absolute_git_path_env(self):
333408
"""Bad absolute path from environment is reported and not set."""
334409
absolute_path=str(Path("yada").absolute())
@@ -365,7 +440,7 @@ def test_refresh_from_good_absolute_git_path_env(self):
365440
deftest_refresh_from_good_relative_git_path_env(self):
366441
"""Good relative path from environment is kept relative and set."""
367442
with_rollback_refresh():
368-
# Set a string that wouldn't work and isn't "git".
443+
# Setas the executable namea string that wouldn't work and isn't "git".
369444
type(self.git).GIT_PYTHON_GIT_EXECUTABLE=""
370445

371446
# Now observe if setting the environment variable to "git" takes effect.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp