Skip to content

Commit

Permalink
Have _fake_git fixture take version_info
Browse files Browse the repository at this point in the history
This reorganization is to facilitate using two separate fake git
commands with different versions, in forthcoming tests.
  • Loading branch information
EliahKagan committed Feb 21, 2024
1 parent 3f107d5 commit 2eac36c
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions test/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
from git.util import cwd, finalize_process
from test.lib import TestBase, fixture_path, with_rw_directory

_FAKE_GIT_VERSION_INFO = (123, 456, 789)


@contextlib.contextmanager
def _patch_out_env(name):
Expand Down Expand Up @@ -70,8 +68,8 @@ def _rollback_refresh():


@contextlib.contextmanager
def _fake_git():
fake_version = ".".join(str(field) for field in _FAKE_GIT_VERSION_INFO)
def _fake_git(*version_info):
fake_version = ".".join(map(str, version_info))
fake_output = f"git version {fake_version} (fake)"

with tempfile.TemporaryDirectory() as tdir:
Expand Down Expand Up @@ -505,17 +503,18 @@ def test_refresh_with_good_relative_git_path_arg(self):
self.assertEqual(self.git.GIT_PYTHON_GIT_EXECUTABLE, absolute_path)

def test_version_info_is_cached(self):
fake_version_info = (123, 456, 789)
with _rollback_refresh():
with _fake_git() as path:
with _fake_git(*fake_version_info) as path:
new_git = Git() # Not cached yet.
refresh(path)
self.assertEqual(new_git.version_info, _FAKE_GIT_VERSION_INFO)
self.assertEqual(new_git.version_info, fake_version_info)
os.remove(path) # Arrange that a second subprocess call would fail.
self.assertEqual(new_git.version_info, _FAKE_GIT_VERSION_INFO)
self.assertEqual(new_git.version_info, fake_version_info)

def test_version_info_cache_is_per_instance(self):
with _rollback_refresh():
with _fake_git() as path:
with _fake_git(123, 456, 789) as path:
git1 = Git()
git2 = Git()
refresh(path)
Expand Down

0 comments on commit 2eac36c

Please sign in to comment.