Skip to content

Better document IterableObj.iter_items and improve some subclasses #1780

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 5 commits into from
Dec 23, 2023
Merged
Changes from 1 commit
Commits
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
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.
  • Loading branch information
EliahKagan committed Dec 22, 2023
commit 96fc3547cf62c5ade1477c24566c8b34254a1507
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