Skip to content

Commit ac20325

Browse files
committed
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 (gitpython-developers#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.
1 parent dc6b90f commit ac20325

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

Diff for: test/test_git.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,10 @@ def test_persistent_cat_file_command(self):
338338
self.assertEqual(size, size_two)
339339

340340
def test_version_info(self):
341-
"""The version_info attribute is a tuple of ints."""
341+
"""The version_info attribute is a tuple of up to four ints."""
342342
v = self.git.version_info
343343
self.assertIsInstance(v, tuple)
344+
self.assertLessEqual(len(v), 4)
344345
for n in v:
345346
self.assertIsInstance(n, int)
346347

@@ -349,9 +350,26 @@ def test_version_info_pickleable(self):
349350
deserialized = pickle.loads(pickle.dumps(self.git))
350351
v = deserialized.version_info
351352
self.assertIsInstance(v, tuple)
353+
self.assertLessEqual(len(v), 4)
352354
for n in v:
353355
self.assertIsInstance(n, int)
354356

357+
@ddt.data(
358+
(("123", "456", "789"), (123, 456, 789)),
359+
(("12", "34", "56", "78"), (12, 34, 56, 78)),
360+
(("12", "34", "56", "78", "90"), (12, 34, 56, 78)),
361+
(("1", "2", "a", "3"), (1, 2)),
362+
(("1", "-2", "3"), (1,)),
363+
(("1", "2a", "3"), (1,)), # Subject to change.
364+
)
365+
def test_version_info_is_leading_numbers(self, case):
366+
fake_fields, expected_version_info = case
367+
with _rollback_refresh():
368+
with _fake_git(*fake_fields) as path:
369+
refresh(path)
370+
new_git = Git()
371+
self.assertEqual(new_git.version_info, expected_version_info)
372+
355373
def test_git_exc_name_is_git(self):
356374
self.assertEqual(self.git.git_exec_name, "git")
357375

0 commit comments

Comments
 (0)