mirror of
https://github.com/pybind/pybind11.git
synced 2026-04-20 14:59:27 +00:00
Propagate exceptions in sequence::size() (#2076)
This commit is contained in:
committed by
Wenzel Jakob
parent
805c5862b6
commit
02c83dba0f
@@ -100,6 +100,25 @@ def test_sequence():
|
||||
assert cstats.move_assignments == 0
|
||||
|
||||
|
||||
def test_sequence_length():
|
||||
"""#2076: Exception raised by len(arg) should be propagated """
|
||||
class BadLen(RuntimeError):
|
||||
pass
|
||||
|
||||
class SequenceLike():
|
||||
def __getitem__(self, i):
|
||||
return None
|
||||
|
||||
def __len__(self):
|
||||
raise BadLen()
|
||||
|
||||
with pytest.raises(BadLen):
|
||||
m.sequence_length(SequenceLike())
|
||||
|
||||
assert m.sequence_length([1, 2, 3]) == 3
|
||||
assert m.sequence_length("hello") == 5
|
||||
|
||||
|
||||
def test_map_iterator():
|
||||
sm = m.StringMap({'hi': 'bye', 'black': 'white'})
|
||||
assert sm['hi'] == 'bye'
|
||||
|
||||
Reference in New Issue
Block a user