Skip to content

Commit

Permalink
Add tests for current Submodule.iter_items behavior
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
EliahKagan committed Dec 22, 2023
1 parent 53e7383 commit 96fc354
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions test/test_submodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,17 @@ def test_root_module(self, rwrepo):
# gitdb: has either 1 or 2 submodules depending on the version.
assert len(nsm.children()) >= 1 and nsmc.module_exists()

def test_iter_items_from_nonexistent_hash(self):
it = Submodule.iter_items(self.rorepo, "b4ecbfaa90c8be6ed6d9fb4e57cc824663ae15b4")
with self.assertRaisesRegex(ValueError, r"\bcould not be resolved\b"):
next(it)

def test_iter_items_from_invalid_hash(self):
"""Check legacy behavaior on BadName (also applies to IOError, i.e. OSError)."""
it = Submodule.iter_items(self.rorepo, "xyz")
with self.assertRaises(StopIteration):
next(it)

@with_rw_repo(k_no_subm_tag, bare=False)
def test_first_submodule(self, rwrepo):
assert len(list(rwrepo.iter_submodules())) == 0
Expand Down

0 comments on commit 96fc354

Please sign in to comment.