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

Appearance settings

Commit 3f107d5

Browse filesBrowse files
committed
Test that version_info caching is per instance
This independence is also established caching behavior for version_info.
1 parent 1de2fdc commit 3f107d5
Copy full SHA for 3f107d5

File tree

Expand file treeCollapse file tree

1 file changed

+19
-5
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+19
-5
lines changed

‎test/test_git.py

Copy file name to clipboardExpand all lines: test/test_git.py
+19-5Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
from git.util import cwd, finalize_process
2929
from test.lib import TestBase, fixture_path, with_rw_directory
3030

31+
_FAKE_GIT_VERSION_INFO = (123, 456, 789)
32+
3133

3234
@contextlib.contextmanager
3335
def _patch_out_env(name):
@@ -69,7 +71,8 @@ def _rollback_refresh():
6971

7072
@contextlib.contextmanager
7173
def _fake_git():
72-
fake_output = "git version 123.456.789 (fake)"
74+
fake_version = ".".join(str(field) for field in _FAKE_GIT_VERSION_INFO)
75+
fake_output = f"git version {fake_version} (fake)"
7376

7477
with tempfile.TemporaryDirectory() as tdir:
7578
if os.name == "nt":
@@ -506,10 +509,21 @@ def test_version_info_is_cached(self):
506509
with _fake_git() as path:
507510
new_git = Git() # Not cached yet.
508511
refresh(path)
509-
version_info = new_git.version_info # Caches the value.
510-
self.assertEqual(version_info, (123, 456, 789))
511-
os.remove(path) # Arrange that reading a second time would fail.
512-
self.assertEqual(new_git.version_info, version_info) # Cached value.
512+
self.assertEqual(new_git.version_info, _FAKE_GIT_VERSION_INFO)
513+
os.remove(path) # Arrange that a second subprocess call would fail.
514+
self.assertEqual(new_git.version_info, _FAKE_GIT_VERSION_INFO)
515+
516+
def test_version_info_cache_is_per_instance(self):
517+
with _rollback_refresh():
518+
with _fake_git() as path:
519+
git1 = Git()
520+
git2 = Git()
521+
refresh(path)
522+
git1.version_info
523+
os.remove(path) # Arrange that the second subprocess call will fail.
524+
with self.assertRaises(GitCommandNotFound):
525+
git2.version_info
526+
git1.version_info
513527

514528
def test_options_are_passed_to_git(self):
515529
# This works because any command after git --version is ignored.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.