|
28 | 28 | from git.util import cwd, finalize_process |
29 | 29 | from test.lib import TestBase, fixture_path, with_rw_directory |
30 | 30 |
|
| 31 | +_FAKE_GIT_VERSION_INFO = (123, 456, 789) |
| 32 | + |
31 | 33 |
|
32 | 34 | @contextlib.contextmanager |
33 | 35 | def _patch_out_env(name): |
@@ -69,7 +71,8 @@ def _rollback_refresh(): |
69 | 71 |
|
70 | 72 | @contextlib.contextmanager |
71 | 73 | 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)" |
73 | 76 |
|
74 | 77 | with tempfile.TemporaryDirectory() as tdir: |
75 | 78 | if os.name == "nt": |
@@ -506,10 +509,21 @@ def test_version_info_is_cached(self): |
506 | 509 | with _fake_git() as path: |
507 | 510 | new_git = Git() # Not cached yet. |
508 | 511 | 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 |
513 | 527 |
|
514 | 528 | def test_options_are_passed_to_git(self): |
515 | 529 | # This works because any command after git --version is ignored. |
|
0 commit comments