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 version_info parsing
This modifies two existing test cases to include an assertion about
the length. These test cases are retained as there is value in
testing on output from a real git command rather than only with
test doubles.

More importantly, this also adds a parameterized test method to
check parsing of:

- All numeric, shorter than the limit - all fields used.
- All numeric, at the limit - all fields used.
- All numeric, longer than the limit - extra fields dropped.
- Has unambiguous non-numeric - dropped from there on.
- Has ambiguous non-numeric, negative int - dropped from there on.
- Has ambiguous non-numeric, number+letter - dropped from there on.

The cases for parsing when a field is not numeric (or not fully or
unambiguously numeric) currently all fail, because the existing
logic drops intermediate non-numeric fields (#1833).

Parsing should instead stop at (or, *perhaps* in cases like "2a",
after) such fields. When the code is changed to stop at them
rather than dropping them and presenting the subsequent field as
though it were a previous field, these test cases should also pass.
  • Loading branch information
EliahKagan committed Feb 22, 2024
commit ac20325133649876749a12c2f611dbf66f5bc17c
20 changes: 19 additions & 1 deletion test/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,10 @@ def test_persistent_cat_file_command(self):
self.assertEqual(size, size_two)

def test_version_info(self):
"""The version_info attribute is a tuple of ints."""
"""The version_info attribute is a tuple of up to four ints."""
v = self.git.version_info
self.assertIsInstance(v, tuple)
self.assertLessEqual(len(v), 4)
for n in v:
self.assertIsInstance(n, int)

Expand All @@ -349,9 +350,26 @@ def test_version_info_pickleable(self):
deserialized = pickle.loads(pickle.dumps(self.git))
v = deserialized.version_info
self.assertIsInstance(v, tuple)
self.assertLessEqual(len(v), 4)
for n in v:
self.assertIsInstance(n, int)

@ddt.data(
(("123", "456", "789"), (123, 456, 789)),
(("12", "34", "56", "78"), (12, 34, 56, 78)),
(("12", "34", "56", "78", "90"), (12, 34, 56, 78)),
(("1", "2", "a", "3"), (1, 2)),
(("1", "-2", "3"), (1,)),
(("1", "2a", "3"), (1,)), # Subject to change.
)
def test_version_info_is_leading_numbers(self, case):
fake_fields, expected_version_info = case
with _rollback_refresh():
with _fake_git(*fake_fields) as path:
refresh(path)
new_git = Git()
self.assertEqual(new_git.version_info, expected_version_info)

def test_git_exc_name_is_git(self):
self.assertEqual(self.git.git_exec_name, "git")

Expand Down