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

Commit626a550

Browse files
committed
Test that refreshing invalidates cached version_info
Most of these don't pass yet, as such invalidation isn'timplemented yet (#1829).
1 parent634b618 commit626a550

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

‎test/test_git.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,84 @@ def test_version_info_cache_is_per_instance(self):
533533
git2.version_info
534534
git1.version_info
535535

536+
deftest_successful_refresh_with_arg_invalidates_cached_version_info(self):
537+
with_rollback_refresh():
538+
with_fake_git(11,111,1)aspath1:
539+
with_fake_git(22,222,2)aspath2:
540+
new_git=Git()
541+
refresh(path1)
542+
new_git.version_info
543+
refresh(path2)
544+
self.assertEqual(new_git.version_info, (22,222,2))
545+
546+
deftest_failed_refresh_with_arg_does_not_invalidate_cached_version_info(self):
547+
with_rollback_refresh():
548+
with_fake_git(11,111,1)aspath1:
549+
with_fake_git(22,222,2)aspath2:
550+
new_git=Git()
551+
refresh(path1)
552+
new_git.version_info
553+
os.remove(path1)# Arrange that a repeat call for path1 would fail.
554+
os.remove(path2)# Arrange that the new call for path2 will fail.
555+
withself.assertRaises(GitCommandNotFound):
556+
refresh(path2)
557+
self.assertEqual(new_git.version_info, (11,111,1))
558+
559+
deftest_successful_refresh_with_same_arg_invalidates_cached_version_info(self):
560+
"""Changing git at the same path and refreshing affects version_info."""
561+
with_rollback_refresh():
562+
with_fake_git(11,111,1)aspath1:
563+
with_fake_git(22,222,2)aspath2:
564+
new_git=Git()
565+
refresh(path1)
566+
new_git.version_info
567+
shutil.copy(path2,path1)
568+
refresh(path1)# The fake git at path1 has a different version now.
569+
self.assertEqual(new_git.version_info, (22,222,2))
570+
571+
deftest_successful_refresh_with_env_invalidates_cached_version_info(self):
572+
withcontextlib.ExitStack()asstack:
573+
stack.enter_context(_rollback_refresh())
574+
path1=stack.enter_context(_fake_git(11,111,1))
575+
path2=stack.enter_context(_fake_git(22,222,2))
576+
withmock.patch.dict(os.environ, {"GIT_PYTHON_GIT_EXECUTABLE":path1}):
577+
new_git=Git()
578+
refresh()
579+
new_git.version_info
580+
withmock.patch.dict(os.environ, {"GIT_PYTHON_GIT_EXECUTABLE":path2}):
581+
refresh()
582+
self.assertEqual(new_git.version_info, (22,222,2))
583+
584+
deftest_failed_refresh_with_env_does_not_invalidate_cached_version_info(self):
585+
withcontextlib.ExitStack()asstack:
586+
stack.enter_context(_rollback_refresh())
587+
path1=stack.enter_context(_fake_git(11,111,1))
588+
path2=stack.enter_context(_fake_git(22,222,2))
589+
withmock.patch.dict(os.environ, {"GIT_PYTHON_GIT_EXECUTABLE":path1}):
590+
new_git=Git()
591+
refresh()
592+
new_git.version_info
593+
os.remove(path1)# Arrange that a repeat call for path1 would fail.
594+
os.remove(path2)# Arrange that the new call for path2 will fail.
595+
withmock.patch.dict(os.environ, {"GIT_PYTHON_GIT_EXECUTABLE":path2}):
596+
withself.assertRaises(GitCommandNotFound):
597+
refresh(path2)
598+
self.assertEqual(new_git.version_info, (11,111,1))
599+
600+
deftest_successful_refresh_with_same_env_invalidates_cached_version_info(self):
601+
"""Changing git at the same path/command and refreshing affects version_info."""
602+
withcontextlib.ExitStack()asstack:
603+
stack.enter_context(_rollback_refresh())
604+
path1=stack.enter_context(_fake_git(11,111,1))
605+
path2=stack.enter_context(_fake_git(22,222,2))
606+
withmock.patch.dict(os.environ, {"GIT_PYTHON_GIT_EXECUTABLE":path1}):
607+
new_git=Git()
608+
refresh()
609+
new_git.version_info
610+
shutil.copy(path2,path1)
611+
refresh()# The fake git at path1 has a different version now.
612+
self.assertEqual(new_git.version_info, (22,222,2))
613+
536614
deftest_options_are_passed_to_git(self):
537615
# This works because any command after git --version is ignored.
538616
git_version=self.git(version=True).NoOp()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp