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

Skip to content

Commit 31a4482

Browse files
author
Rickard Holmberg
committed
crashing exception test
1 parent 25e66f0 commit 31a4482

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/testing/exceptiontest.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
24

35
namespace Python.Test
46
{
@@ -54,6 +56,13 @@ public static bool ThrowException()
5456
throw new OverflowException("error");
5557
}
5658

59+
public static IEnumerable<int> ThrowExceptionInIterator()
60+
{
61+
yield return 1;
62+
yield return 2;
63+
throw new OverflowException("error");
64+
}
65+
5766
public static void ThrowChainedExceptions()
5867
{
5968
try

src/tests/test_exceptions.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,3 +345,17 @@ def test_chained_exceptions():
345345
assert exc.Message == msg
346346
assert exc.__cause__ == exc.InnerException
347347
exc = exc.__cause__
348+
349+
def test_iteration_exception():
350+
from Python.Test import ExceptionTest
351+
from System import OverflowException
352+
353+
val = ExceptionTest.ThrowExceptionInIterator().__iter__()
354+
assert next(val) == 1
355+
assert next(val) == 2
356+
with pytest.raises(OverflowException) as cm:
357+
next(val)
358+
359+
exc = cm.value
360+
361+
assert isinstance(exc, OverflowException)

0 commit comments

Comments
 (0)