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

Commit8dc8eb9

Browse files
committed
Test established zero-argument refresh() behavior
This adds tests like the existing ones but for when git.refresh iscalled with no arguments and the path is provided as the value ofthe GIT_PYTHON_GIT_EXECUTABLE environment variable.The preexisting tests, which this retains unchanged except withslightly more specific names to avoid confusion with the new tests,are of git.refresh(path).One benefit of these tests is to make a subtle but important aspectof the established behavior clear: relative paths are immediatelyresolved when passed as a path argument, but they are kept relativewhen given as the value of the environment variable.
1 parentf4ce709 commit8dc8eb9

File tree

1 file changed

+64
-5
lines changed

1 file changed

+64
-5
lines changed

‎test/test_git.py

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,24 @@ def _patch_out_env(name):
4646

4747
@contextlib.contextmanager
4848
def_rollback_refresh():
49+
old_git_executable=Git.GIT_PYTHON_GIT_EXECUTABLE
50+
51+
ifold_git_executableisNone:
52+
raiseRuntimeError("no executable string (need initial refresh before test)")
53+
4954
try:
50-
yieldGit.GIT_PYTHON_GIT_EXECUTABLE# Provide the old value for convenience.
55+
yieldold_git_executable# Provide the old value for convenience.
5156
finally:
57+
# The cleanup refresh should always raise an exception if it fails, since if it
58+
# fails then previously discovered test results could be misleading and, more
59+
# importantly, subsequent tests may be unable to run or give misleading results.
60+
# So pre-set a non-None value, so that the cleanup will be a "second" refresh.
61+
# This covers cases where a test has set it to None to test a "first" refresh.
62+
Git.GIT_PYTHON_GIT_EXECUTABLE=Git.git_exec_name
63+
64+
# Do the cleanup refresh. This sets Git.GIT_PYTHON_GIT_EXECUTABLE to old_value
65+
# in most cases. The reason to call it is to achieve other associated state
66+
# changes as well, which include updating attributes of the FetchInfo class.
5267
refresh()
5368

5469

@@ -314,7 +329,51 @@ def test_cmd_override(self):
314329
):
315330
self.assertRaises(GitCommandNotFound,self.git.version)
316331

317-
deftest_refresh_bad_absolute_git_path(self):
332+
deftest_refresh_from_bad_absolute_git_path_env(self):
333+
"""Bad absolute path from environment is reported and not set."""
334+
absolute_path=str(Path("yada").absolute())
335+
expected_pattern=rf"\n[ \t]*cmdline:{re.escape(absolute_path)}\Z"
336+
337+
with_rollback_refresh()asold_git_executable:
338+
withmock.patch.dict(os.environ, {"GIT_PYTHON_GIT_EXECUTABLE":absolute_path}):
339+
withself.assertRaisesRegex(GitCommandNotFound,expected_pattern):
340+
refresh()
341+
self.assertEqual(self.git.GIT_PYTHON_GIT_EXECUTABLE,old_git_executable)
342+
343+
deftest_refresh_from_bad_relative_git_path_env(self):
344+
"""Bad relative path from environment is kept relative and reported, not set."""
345+
# Relative paths are not resolved when refresh() is called with no arguments, so
346+
# use a string that's very unlikely to be a command name found in a path lookup.
347+
relative_path="yada-e47e70c6-acbf-40f8-ad65-13af93c2195b"
348+
expected_pattern=rf"\n[ \t]*cmdline:{re.escape(relative_path)}\Z"
349+
350+
with_rollback_refresh()asold_git_executable:
351+
withmock.patch.dict(os.environ, {"GIT_PYTHON_GIT_EXECUTABLE":relative_path}):
352+
withself.assertRaisesRegex(GitCommandNotFound,expected_pattern):
353+
refresh()
354+
self.assertEqual(self.git.GIT_PYTHON_GIT_EXECUTABLE,old_git_executable)
355+
356+
deftest_refresh_from_good_absolute_git_path_env(self):
357+
"""Good absolute path from environment is set."""
358+
absolute_path=shutil.which("git")
359+
360+
with_rollback_refresh():
361+
withmock.patch.dict(os.environ, {"GIT_PYTHON_GIT_EXECUTABLE":absolute_path}):
362+
refresh()
363+
self.assertEqual(self.git.GIT_PYTHON_GIT_EXECUTABLE,absolute_path)
364+
365+
deftest_refresh_from_good_relative_git_path_env(self):
366+
"""Good relative path from environment is kept relative and set."""
367+
with_rollback_refresh():
368+
# Set a string that wouldn't work and isn't "git".
369+
type(self.git).GIT_PYTHON_GIT_EXECUTABLE=""
370+
371+
# Now observe if setting the environment variable to "git" takes effect.
372+
withmock.patch.dict(os.environ, {"GIT_PYTHON_GIT_EXECUTABLE":"git"}):
373+
refresh()
374+
self.assertEqual(self.git.GIT_PYTHON_GIT_EXECUTABLE,"git")
375+
376+
deftest_refresh_with_bad_absolute_git_path_arg(self):
318377
"""Bad absolute path arg is reported and not set."""
319378
absolute_path=str(Path("yada").absolute())
320379
expected_pattern=rf"\n[ \t]*cmdline:{re.escape(absolute_path)}\Z"
@@ -324,7 +383,7 @@ def test_refresh_bad_absolute_git_path(self):
324383
refresh(absolute_path)
325384
self.assertEqual(self.git.GIT_PYTHON_GIT_EXECUTABLE,old_git_executable)
326385

327-
deftest_refresh_bad_relative_git_path(self):
386+
deftest_refresh_with_bad_relative_git_path_arg(self):
328387
"""Bad relative path arg is resolved to absolute path and reported, not set."""
329388
absolute_path=str(Path("yada").absolute())
330389
expected_pattern=rf"\n[ \t]*cmdline:{re.escape(absolute_path)}\Z"
@@ -334,15 +393,15 @@ def test_refresh_bad_relative_git_path(self):
334393
refresh("yada")
335394
self.assertEqual(self.git.GIT_PYTHON_GIT_EXECUTABLE,old_git_executable)
336395

337-
deftest_refresh_good_absolute_git_path(self):
396+
deftest_refresh_with_good_absolute_git_path_arg(self):
338397
"""Good absolute path arg is set."""
339398
absolute_path=shutil.which("git")
340399

341400
with_rollback_refresh():
342401
refresh(absolute_path)
343402
self.assertEqual(self.git.GIT_PYTHON_GIT_EXECUTABLE,absolute_path)
344403

345-
deftest_refresh_good_relative_git_path(self):
404+
deftest_refresh_with_good_relative_git_path_arg(self):
346405
"""Good relative path arg is resolved to absolute path and set."""
347406
absolute_path=shutil.which("git")
348407
dirname,basename=osp.split(absolute_path)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp