Skip to content

Commit c28bafd

Browse files
authored
Merge branch 'master' into implicit_assembly_load_opt
2 parents 4af13a3 + c18285f commit c28bafd

File tree

5 files changed

+28
-4
lines changed

5 files changed

+28
-4
lines changed

src/embed_tests/TestExample.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void TestReadme()
4747
dynamic b = np.array(new List<float> { 6, 5, 4 }, Py.kw("dtype", np.int32));
4848
Assert.AreEqual("int32", b.dtype.ToString());
4949

50-
Assert.AreEqual("[ 6. 10. 12.]", (a * b).ToString());
50+
Assert.AreEqual("[ 6. 10. 12.]", (a * b).ToString().Replace(" ", " "));
5151
}
5252
}
5353
}

src/embed_tests/TestPythonException.cs

+14
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,19 @@ public void TestNoError()
4040
var e = new PythonException(); // There is no PyErr to fetch
4141
Assert.AreEqual("", e.Message);
4242
}
43+
44+
[Test]
45+
public void TestPythonErrorTypeName()
46+
{
47+
try
48+
{
49+
var module = PythonEngine.ImportModule("really____unknown___module");
50+
Assert.Fail("Unknown module should not be loaded");
51+
}
52+
catch (PythonException ex)
53+
{
54+
Assert.That(ex.PythonTypeName, Is.EqualTo("ModuleNotFoundError").Or.EqualTo("ImportError"));
55+
}
56+
}
4357
}
4458
}

src/embed_tests/dynamic.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public void PassObjectInPython()
103103
Assert.AreEqual(sys.testattr3.ToString(), "True");
104104

105105
// Compare in .NET
106-
Assert.AreEqual(sys.testattr1, sys.testattr2);
106+
Assert.IsTrue(sys.testattr1.Equals(sys.testattr2));
107107
}
108108

109109
/// <summary>
@@ -125,7 +125,7 @@ public void PassPyObjectInNet()
125125
Assert.AreEqual(sys.testattr3.ToString(), "True");
126126

127127
// Compare in .NET
128-
Assert.AreEqual(sys.testattr1, sys.testattr2);
128+
Assert.IsTrue(sys.testattr1.Equals(sys.testattr2));
129129
}
130130
}
131131
}

src/runtime/pyobject.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Python.Runtime
1212
/// PY3: https://docs.python.org/3/c-api/object.html
1313
/// for details.
1414
/// </summary>
15-
public class PyObject : DynamicObject, IDisposable
15+
public class PyObject : DynamicObject, IEnumerable, IDisposable
1616
{
1717
protected internal IntPtr obj = IntPtr.Zero;
1818
private bool disposed = false;

src/runtime/pythonexception.cs

+10
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class PythonException : System.Exception
1313
private IntPtr _pyTB = IntPtr.Zero;
1414
private string _tb = "";
1515
private string _message = "";
16+
private string _pythonTypeName = "";
1617
private bool disposed = false;
1718

1819
public PythonException()
@@ -33,6 +34,8 @@ public PythonException()
3334
type = pyTypeName.ToString();
3435
}
3536

37+
_pythonTypeName = type;
38+
3639
Runtime.XIncref(_pyValue);
3740
using (var pyValue = new PyObject(_pyValue))
3841
{
@@ -132,6 +135,13 @@ public override string StackTrace
132135
get { return _tb; }
133136
}
134137

138+
/// <summary>
139+
/// Python error type name.
140+
/// </summary>
141+
public string PythonTypeName
142+
{
143+
get { return _pythonTypeName; }
144+
}
135145

136146
/// <summary>
137147
/// Dispose Method

0 commit comments

Comments
 (0)