Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 96fc354

Browse filesBrowse 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 53e7383 commit 96fc354
Copy full SHA for 96fc354

File tree

1 file changed

+11
-0
lines changed
Filter options

1 file changed

+11
-0
lines changed

‎test/test_submodule.py

Copy file name to clipboardExpand all lines: test/test_submodule.py
+11Lines changed: 11 additions & 0 deletions
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):
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.