| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,7 +5,7 @@ | |||
| 5 | 5 | ||
| 6 | 6 | namespace Python.EmbeddingTest | |
| 7 | 7 | { | |
| 8 | - public class dynamicTest | ||
| 8 | + public class DynamicTest | ||
| 9 | 9 | { | |
| 10 | 10 | private Py.GILState gil; | |
| 11 | 11 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,14 +33,12 @@ public void Dispose() | |||
| 33 | 33 | public void TestMessage() | |
| 34 | 34 | { | |
| 35 | 35 | var list = new PyList(); | |
| 36 | - try | ||
| 37 | - { | ||
| 38 | - PyObject junk = list[0]; | ||
| 39 | - } | ||
| 40 | - catch (PythonException e) | ||
| 41 | - { | ||
| 42 | - Assert.AreEqual("IndexError : list index out of range", e.Message); | ||
| 43 | - } | ||
| 36 | + PyObject foo = null; | ||
| 37 | + | ||
| 38 | + var ex = Assert.Throws<PythonException>(() => foo = list[0]); | ||
| 39 | + | ||
| 40 | + Assert.AreEqual("IndexError : list index out of range", ex.Message); | ||
| 41 | + Assert.IsNull(foo); | ||
| 44 | 42 | } | |
| 45 | 43 | ||
| 46 | 44 | [Test] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -43,6 +43,21 @@ public void TestPyTupleEmpty() | |||
| 43 | 43 | } | |
| 44 | 44 | } | |
| 45 | 45 | ||
| 46 | + [Test] | ||
| 47 | + public void TestPyTupleBadCtor() | ||
| 48 | + { | ||
| 49 | + using (Py.GIL()) | ||
| 50 | + { | ||
| 51 | + var i = new PyInt(5); | ||
| 52 | + PyTuple t = null; | ||
| 53 | + | ||
| 54 | + var ex = Assert.Throws<ArgumentException>(() => t = new PyTuple(i)); | ||
| 55 | + | ||
| 56 | + Assert.AreEqual("object is not a tuple", ex.Message); | ||
| 57 | + Assert.IsNull(t); | ||
| 58 | + } | ||
| 59 | + } | ||
| 60 | + | ||
| 46 | 61 | /// <summary> | |
| 47 | 62 | /// Test PyTuple.Concat(...) doesn't let invalid appends happen | |
| 48 | 63 | /// and throws and exception. | |
@@ -51,6 +66,8 @@ public void TestPyTupleEmpty() | |||
| 51 | 66 | /// Test has second purpose. Currently it generated an Exception | |
| 52 | 67 | /// that the GC failed to remove often and caused AppDomain unload | |
| 53 | 68 | /// errors at the end of tests. See GH#397 for more info. | |
| 69 | + /// <para /> | ||
| 70 | + /// Curious, on PY27 it gets a Unicode on the ex.Message. On PY3+ its string. | ||
| 54 | 71 | /// </remarks> | |
| 55 | 72 | [Test] | |
| 56 | 73 | public void TestPyTupleInvalidAppend() | |
@@ -59,7 +76,12 @@ public void TestPyTupleInvalidAppend() | |||
| 59 | 76 | { | |
| 60 | 77 | PyObject s = new PyString("foo"); | |
| 61 | 78 | var t = new PyTuple(); | |
| 62 | - Assert.Throws<PythonException>(() => t.Concat(s)); | ||
| 79 | + | ||
| 80 | + var ex = Assert.Throws<PythonException>(() => t.Concat(s)); | ||
| 81 | + | ||
| 82 | + StringAssert.StartsWith("TypeError : can only concatenate tuple", ex.Message); | ||
| 83 | + Assert.AreEqual(0, t.Length()); | ||
| 84 | + Assert.IsEmpty(t); | ||
| 63 | 85 | } | |
| 64 | 86 | } | |
| 65 | 87 | ||
@@ -114,5 +136,23 @@ public void TestNewPyTupleFromPyTuple() | |||
| 114 | 136 | Assert.IsInstanceOf(typeof(PyTuple), t); | |
| 115 | 137 | } | |
| 116 | 138 | } | |
| 139 | + | ||
| 140 | + /// <remarks> | ||
| 141 | + /// TODO: Should this throw ArgumentError instead? | ||
| 142 | + /// </remarks> | ||
| 143 | + [Test] | ||
| 144 | + public void TestInvalidAsTuple() | ||
| 145 | + { | ||
| 146 | + using (Py.GIL()) | ||
| 147 | + { | ||
| 148 | + var i = new PyInt(5); | ||
| 149 | + PyTuple t = null; | ||
| 150 | + | ||
| 151 | + var ex = Assert.Throws<PythonException>(() => t = PyTuple.AsTuple(i)); | ||
| 152 | + | ||
| 153 | + Assert.AreEqual("TypeError : 'int' object is not iterable", ex.Message); | ||
| 154 | + Assert.IsNull(t); | ||
| 155 | + } | ||
| 156 | + } | ||
| 117 | 157 | } | |
| 118 | 158 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments