|
28 | 28 | fromgit.utilimportcwd,finalize_process
|
29 | 29 | fromtest.libimportTestBase,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)forfieldin_FAKE_GIT_VERSION_INFO) |
| 75 | +fake_output=f"git version{fake_version} (fake)" |
73 | 76 |
|
74 | 77 | withtempfile.TemporaryDirectory()astdir:
|
75 | 78 | ifos.name=="nt":
|
@@ -506,10 +509,21 @@ def test_version_info_is_cached(self):
|
506 | 509 | with_fake_git()aspath:
|
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 | +deftest_version_info_cache_is_per_instance(self): |
| 517 | +with_rollback_refresh(): |
| 518 | +with_fake_git()aspath: |
| 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 | +withself.assertRaises(GitCommandNotFound): |
| 525 | +git2.version_info |
| 526 | +git1.version_info |
513 | 527 |
|
514 | 528 | deftest_options_are_passed_to_git(self):
|
515 | 529 | # This works because any command after git --version is ignored.
|
|