Skip to content

Fix version_info cache invalidation, typing, parsing, and serialization #1838

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Feb 23, 2024
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Test that refreshing invalidates cached version_info
Most of these don't pass yet, as such invalidation isn't
implemented yet (#1829).
  • Loading branch information
EliahKagan committed Feb 22, 2024
commit 626a550d22d91dc94b7cc0bfda3fef3ab7f10189
78 changes: 78 additions & 0 deletions test/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,84 @@ def test_version_info_cache_is_per_instance(self):
git2.version_info
git1.version_info

def test_successful_refresh_with_arg_invalidates_cached_version_info(self):
with _rollback_refresh():
with _fake_git(11, 111, 1) as path1:
with _fake_git(22, 222, 2) as path2:
new_git = Git()
refresh(path1)
new_git.version_info
refresh(path2)
self.assertEqual(new_git.version_info, (22, 222, 2))

def test_failed_refresh_with_arg_does_not_invalidate_cached_version_info(self):
with _rollback_refresh():
with _fake_git(11, 111, 1) as path1:
with _fake_git(22, 222, 2) as path2:
new_git = Git()
refresh(path1)
new_git.version_info
os.remove(path1) # Arrange that a repeat call for path1 would fail.
os.remove(path2) # Arrange that the new call for path2 will fail.
with self.assertRaises(GitCommandNotFound):
refresh(path2)
self.assertEqual(new_git.version_info, (11, 111, 1))

def test_successful_refresh_with_same_arg_invalidates_cached_version_info(self):
"""Changing git at the same path and refreshing affects version_info."""
with _rollback_refresh():
with _fake_git(11, 111, 1) as path1:
with _fake_git(22, 222, 2) as path2:
new_git = Git()
refresh(path1)
new_git.version_info
shutil.copy(path2, path1)
refresh(path1) # The fake git at path1 has a different version now.
self.assertEqual(new_git.version_info, (22, 222, 2))

def test_successful_refresh_with_env_invalidates_cached_version_info(self):
with contextlib.ExitStack() as stack:
stack.enter_context(_rollback_refresh())
path1 = stack.enter_context(_fake_git(11, 111, 1))
path2 = stack.enter_context(_fake_git(22, 222, 2))
with mock.patch.dict(os.environ, {"GIT_PYTHON_GIT_EXECUTABLE": path1}):
new_git = Git()
refresh()
new_git.version_info
with mock.patch.dict(os.environ, {"GIT_PYTHON_GIT_EXECUTABLE": path2}):
refresh()
self.assertEqual(new_git.version_info, (22, 222, 2))

def test_failed_refresh_with_env_does_not_invalidate_cached_version_info(self):
with contextlib.ExitStack() as stack:
stack.enter_context(_rollback_refresh())
path1 = stack.enter_context(_fake_git(11, 111, 1))
path2 = stack.enter_context(_fake_git(22, 222, 2))
with mock.patch.dict(os.environ, {"GIT_PYTHON_GIT_EXECUTABLE": path1}):
new_git = Git()
refresh()
new_git.version_info
os.remove(path1) # Arrange that a repeat call for path1 would fail.
os.remove(path2) # Arrange that the new call for path2 will fail.
with mock.patch.dict(os.environ, {"GIT_PYTHON_GIT_EXECUTABLE": path2}):
with self.assertRaises(GitCommandNotFound):
refresh(path2)
self.assertEqual(new_git.version_info, (11, 111, 1))

def test_successful_refresh_with_same_env_invalidates_cached_version_info(self):
"""Changing git at the same path/command and refreshing affects version_info."""
with contextlib.ExitStack() as stack:
stack.enter_context(_rollback_refresh())
path1 = stack.enter_context(_fake_git(11, 111, 1))
path2 = stack.enter_context(_fake_git(22, 222, 2))
with mock.patch.dict(os.environ, {"GIT_PYTHON_GIT_EXECUTABLE": path1}):
new_git = Git()
refresh()
new_git.version_info
shutil.copy(path2, path1)
refresh() # The fake git at path1 has a different version now.
self.assertEqual(new_git.version_info, (22, 222, 2))

def test_options_are_passed_to_git(self):
# This works because any command after git --version is ignored.
git_version = self.git(version=True).NoOp()
Expand Down