Skip to content

Commit f9213a7

Browse files
committed
Add tests for current Submodule.iter_items behavior
Where the behavior is intended. In the case of an invalid hash (or IOError, which in Python 2 was a subclass of OSError but now is just another name for it), the behavior of just yielding no items may be unintuitive, since on most other errors an exception is raised. However, examining the code reveals this behavior is clearly intentional. Furthrmore, it may be reasonable for applications to rely on it, and it may be convenient in some situations. For backward compatibility, it probably can't be changed significantly. This adds tests that show both an error that does raise an error-representing exception -- a well-formed hash not present in the repository raising ValueError with a suitable message -- and an error that silently causes the iterator to yield zero items.
1 parent fc7a521 commit f9213a7

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Diff for: test/test_submodule.py

+11
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,17 @@ def test_root_module(self, rwrepo):
688688
# gitdb: has either 1 or 2 submodules depending on the version.
689689
assert len(nsm.children()) >= 1 and nsmc.module_exists()
690690

691+
def test_iter_items_from_nonexistent_hash(self):
692+
it = Submodule.iter_items(self.rorepo, "b4ecbfaa90c8be6ed6d9fb4e57cc824663ae15b4")
693+
with self.assertRaisesRegex(ValueError, r"\bcould not be resolved\b"):
694+
next(it)
695+
696+
def test_iter_items_from_invalid_hash(self):
697+
"""Check legacy behavaior on BadName (also applies to IOError, i.e. OSError)."""
698+
it = Submodule.iter_items(self.rorepo, "xyz")
699+
with self.assertRaises(StopIteration) as ctx:
700+
next(it)
701+
691702
@with_rw_repo(k_no_subm_tag, bare=False)
692703
def test_first_submodule(self, rwrepo):
693704
assert len(list(rwrepo.iter_submodules())) == 0

0 commit comments

Comments
 (0)