Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d119c6c

Browse files
rickardraysearchabessen
authored and
abessen
committed
Add test throwing exception with inner exception in iterator
(cherry picked from commit 4956b3e)
1 parent 9aac609 commit d119c6c

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/tests/test_exceptions.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,12 +350,30 @@ def test_iteration_exception():
350350
from Python.Test import ExceptionTest
351351
from System import OverflowException
352352

353-
val = ExceptionTest.ThrowExceptionInIterator().__iter__()
353+
exception = OverflowException("error")
354+
355+
val = ExceptionTest.ThrowExceptionInIterator(exception).__iter__()
356+
assert next(val) == 1
357+
assert next(val) == 2
358+
with pytest.raises(OverflowException) as cm:
359+
next(val)
360+
361+
exc = cm.value
362+
363+
assert exc == exception
364+
365+
def test_iteration_innerexception():
366+
from Python.Test import ExceptionTest
367+
from System import OverflowException
368+
369+
exception = System.Exception("message", OverflowException("error"))
370+
371+
val = ExceptionTest.ThrowExceptionInIterator(exception).__iter__()
354372
assert next(val) == 1
355373
assert next(val) == 2
356374
with pytest.raises(OverflowException) as cm:
357375
next(val)
358376

359-
exc = cm.value
377+
exc = cm.value
360378

361-
assert isinstance(exc, OverflowException)
379+
assert exc == exception.InnerException

0 commit comments

Comments
 (0)