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

Commit5ad7cb2

Browse files
committed
Start work on making refresh tests restore state
+ Test a successful refresh with a relative path, which will be safer to do once the refresh tests restore changed state.See#1811. This addresses it incompletely, because while it isprobably not necessary while running the test suite to preserve anold False value of git.GIT_OK (most tests can't work if thathappens anyway), the value of Git.GIT_PYTHON_GIT_EXECUTABLE is notthe only other global state that effects the behavior ofsubsequently run tests and that may be changed as a result of therefresh tests.1. After the git.refresh function calls git.cmd.Git.refresh, it calls git.remote.FetchInfo.refresh, which rebinds the git.remote.FetchInfo._flag_map attribute.2. Future changes to git.cmd.Git.refresh may mutate other state in the Git class, and ideally the coupling would be loose enough that the refresh tests wouldn't have to be updated for that if the behavior being tested does not change.3. Future changes to git.refresh may perform other refreshing actions, and ideally it would be easy (and obvious) what has to be done to patch it back. In particular, it will likely call another Git method that mutates class-wide state due to#1791, and for such state that is also of the Git class, ideally no further changes would have to be made to the code that restores state after the refresh tests.If we assume git.refresh is working at least in the case that it iscalled with no arguments, then the cleanup can just be a call togit.refresh(). Otherwise, sufficiently general cleanup may be morecomplicated.
1 parent3a34dee commit5ad7cb2

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

‎test/test_git.py

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ def _patch_out_env(name):
4444
os.environ[name]=old_value
4545

4646

47+
@contextlib.contextmanager
48+
def_restore_git_executable():
49+
old_git_executable=Git.GIT_PYTHON_GIT_EXECUTABLE
50+
try:
51+
yieldold_git_executable# Let test code run that may rebind the attribute.
52+
finally:
53+
Git.GIT_PYTHON_GIT_EXECUTABLE=old_git_executable
54+
55+
4756
@ddt.ddt
4857
classTestGit(TestBase):
4958
@classmethod
@@ -309,20 +318,36 @@ def test_cmd_override(self):
309318
deftest_refresh_bad_absolute_git_path(self):
310319
absolute_path=str(Path("yada").absolute())
311320
expected_pattern=rf"\n[ \t]*cmdline:{re.escape(absolute_path)}\Z"
312-
withself.assertRaisesRegex(GitCommandNotFound,expected_pattern):
313-
refresh(absolute_path)
321+
322+
with_restore_git_executable()asold_git_executable:
323+
withself.assertRaisesRegex(GitCommandNotFound,expected_pattern):
324+
refresh(absolute_path)
325+
self.assertEqual(self.git.GIT_PYTHON_GIT_EXECUTABLE,old_git_executable)
314326

315327
deftest_refresh_bad_relative_git_path(self):
316-
relative_path="yada"
317-
absolute_path=str(Path(relative_path).absolute())
328+
absolute_path=str(Path("yada").absolute())
318329
expected_pattern=rf"\n[ \t]*cmdline:{re.escape(absolute_path)}\Z"
319-
withself.assertRaisesRegex(GitCommandNotFound,expected_pattern):
320-
refresh(relative_path)
330+
331+
with_restore_git_executable()asold_git_executable:
332+
withself.assertRaisesRegex(GitCommandNotFound,expected_pattern):
333+
refresh("yada")
334+
self.assertEqual(self.git.GIT_PYTHON_GIT_EXECUTABLE,old_git_executable)
321335

322336
deftest_refresh_good_absolute_git_path(self):
323337
absolute_path=shutil.which("git")
324-
refresh(absolute_path)
325-
self.assertEqual(self.git.GIT_PYTHON_GIT_EXECUTABLE,absolute_path)
338+
339+
with_restore_git_executable():
340+
refresh(absolute_path)
341+
self.assertEqual(self.git.GIT_PYTHON_GIT_EXECUTABLE,absolute_path)
342+
343+
deftest_refresh_good_relative_git_path(self):
344+
absolute_path=shutil.which("git")
345+
dirname,basename=osp.split(absolute_path)
346+
347+
withcwd(dirname):
348+
with_restore_git_executable():
349+
refresh(basename)
350+
self.assertEqual(self.git.GIT_PYTHON_GIT_EXECUTABLE,absolute_path)
326351

327352
deftest_options_are_passed_to_git(self):
328353
# This works because any command after git --version is ignored.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp