8000 added tests for __cause__/InnerException #893 #1098 · pythonnet/pythonnet@0961c94 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0961c94

Browse files
committed
added tests for __cause__/InnerException #893 #1098
1 parent bec8b7d commit 0961c94

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/embed_tests/TestPythonException.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,36 @@ public void TestPythonErrorTypeName()
5555
}
5656
}
5757

58+
[Test]
59+
public void TestNestedExceptions()
60+
{
61+
try
62+
{
63+
PythonEngine.Exec(@"
64+
try:
65+
raise Exception('inner')
66+
except Exception as ex:
67+
raise Exception('outer') from ex
68+
");
69+
}
70+
catch (PythonException ex)
71+
{
72+
Assert.That(ex.InnerException, Is.InstanceOf<PythonException>());
73+
Assert.That(ex.InnerException.Message, Is.EqualTo("Exception : inner"));
74+
}
75+
}
76+
77+
[Test]
78+
public void InnerIsEmptyWithNoCause()
79+
{
80+
var list = new PyList();
81+
PyObject foo = null;
82+
83+
var ex = Assert.Throws<PythonException>(() => foo = list[0]);
84+
85+
Assert.IsNull(ex.InnerException);
86+
}
87+
5888
[Test]
5989
public void TestPythonExceptionFormat()
6090
{

0 commit comments

Comments
 (0)
0