Skip to content

Commit

Permalink
Test version_info parsing
Browse files Browse the repository at this point in the history
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
1 parent dc6b90f commit ac20325
Showing 1 changed file with 19 additions and 1 deletion.
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

0 comments on commit ac20325

Please sign in to comment.