Skip to content
Closed
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 test throwing exception with inner exception in iterator
  • Loading branch information
rickardraysearch committed Aug 9, 2017
commit 4956b3e1b5ddc47e95c7e889f781f24e537523c9
24 changes: 21 additions & 3 deletions src/tests/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,30 @@ def test_iteration_exception():
from Python.Test import ExceptionTest
from System import OverflowException

val = ExceptionTest.ThrowExceptionInIterator().__iter__()
exception = OverflowException("error")

val = ExceptionTest.ThrowExceptionInIterator(exception).__iter__()
assert next(val) == 1
assert next(val) == 2
with pytest.raises(OverflowException) as cm:
next(val)

exc = cm.value

assert exc == exception

def test_iteration_innerexception():
from Python.Test import ExceptionTest
from System import OverflowException

exception = System.Exception("message", OverflowException("error"))

val = ExceptionTest.ThrowExceptionInIterator(exception).__iter__()
assert next(val) == 1
assert next(val) == 2
with pytest.raises(OverflowException) as cm:
next(val)

exc = cm.value
exc = cm.value

assert isinstance(exc, OverflowException)
assert exc == exception.InnerException