| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,20 +6,30 @@ namespace Python.EmbeddingTest | |||
| 6 | 6 | { | |
| 7 | 7 | public class TestCustomMarshal | |
| 8 | 8 | { | |
| 9 | + [OneTimeSetUp] | ||
| 10 | + public void SetUp() | ||
| 11 | + { | ||
| 12 | + PythonEngine.Initialize(); | ||
| 13 | + } | ||
| 14 | + | ||
| 15 | + [OneTimeTearDown] | ||
| 16 | + public void Dispose() | ||
| 17 | + { | ||
| 18 | + PythonEngine.Shutdown(); | ||
| 19 | + } | ||
| 20 | + | ||
| 9 | 21 | [Test] | |
| 10 | 22 | public static void GetManagedStringTwice() | |
| 11 | 23 | { | |
| 12 | 24 | const string expected = "FooBar"; | |
| 13 | - using (Py.GIL()) | ||
| 14 | - { | ||
| 15 | - IntPtr op = Runtime.Runtime.PyUnicode_FromString(expected); | ||
| 16 | - string s1 = Runtime.Runtime.GetManagedString(op); | ||
| 17 | - string s2 = Runtime.Runtime.GetManagedString(op); | ||
| 18 | 25 | ||
| 19 | - Assert.AreEqual(1, Runtime.Runtime.Refcount(op)); | ||
| 20 | - Assert.AreEqual(expected, s1); | ||
| 21 | - Assert.AreEqual(expected, s2); | ||
| 22 | - } | ||
| 26 | + IntPtr op = Runtime.Runtime.PyUnicode_FromString(expected); | ||
| 27 | + string s1 = Runtime.Runtime.GetManagedString(op); | ||
| 28 | + string s2 = Runtime.Runtime.GetManagedString(op); | ||
| 29 | + | ||
| 30 | + Assert.AreEqual(1, Runtime.Runtime.Refcount(op)); | ||
| 31 | + Assert.AreEqual(expected, s1); | ||
| 32 | + Assert.AreEqual(expected, s2); | ||
| 23 | 33 | } | |
| 24 | 34 | } | |
| 25 | 35 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -134,14 +134,14 @@ public void TestCtorBadString() | |||
| 134 | 134 | public void TestIsIntTypeTrue() | |
| 135 | 135 | { | |
| 136 | 136 | var i = new PyInt(5); | |
| 137 | - Assert.IsTrue(PyInt.IsIntType(i)); | ||
| 137 | + Assert.True(PyInt.IsIntType(i)); | ||
| 138 | 138 | } | |
| 139 | 139 | ||
| 140 | 140 | [Test] | |
| 141 | 141 | public void TestIsIntTypeFalse() | |
| 142 | 142 | { | |
| 143 | 143 | var s = new PyString("Foo"); | |
| 144 | - Assert.IsFalse(PyInt.IsIntType(s)); | ||
| 144 | + Assert.False(PyInt.IsIntType(s)); | ||
| 145 | 145 | } | |
| 146 | 146 | ||
| 147 | 147 | [Test] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,25 +7,36 @@ namespace Python.EmbeddingTest | |||
| 7 | 7 | { | |
| 8 | 8 | public class TestPyList | |
| 9 | 9 | { | |
| 10 | + [OneTimeSetUp] | ||
| 11 | + public void SetUp() | ||
| 12 | + { | ||
| 13 | + PythonEngine.Initialize(); | ||
| 14 | + } | ||
| 15 | + | ||
| 16 | + [OneTimeTearDown] | ||
| 17 | + public void Dispose() | ||
| 18 | + { | ||
| 19 | + PythonEngine.Shutdown(); | ||
| 20 | + } | ||
| 21 | + | ||
| 10 | 22 | [Test] | |
| 11 | 23 | public void TestOnPyList() | |
| 12 | 24 | { | |
| 13 | - using (Py.GIL()) | ||
| 25 | + var list = new PyList(); | ||
| 26 | + | ||
| 27 | + list.Append(new PyString("foo")); | ||
| 28 | + list.Append(new PyString("bar")); | ||
| 29 | + list.Append(new PyString("baz")); | ||
| 30 | + var result = new List<string>(); | ||
| 31 | + foreach (PyObject item in list) | ||
| 14 | 32 | { | |
| 15 | - var list = new PyList(); | ||
| 16 | - list.Append(new PyString("foo")); | ||
| 17 | - list.Append(new PyString("bar")); | ||
| 18 | - list.Append(new PyString("baz")); | ||
| 19 | - var result = new List<string>(); | ||
| 20 | - foreach (PyObject item in list) | ||
| 21 | - { | ||
| 22 | - result.Add(item.ToString()); | ||
| 23 | - } | ||
| 24 | - Assert.AreEqual(3, result.Count); | ||
| 25 | - Assert.AreEqual("foo", result[0]); | ||
| 26 | - Assert.AreEqual("bar", result[1]); | ||
| 27 | - Assert.AreEqual("baz", result[2]); | ||
| 33 | + result.Add(item.ToString()); | ||
| 28 | 34 | } | |
| 35 | + | ||
| 36 | + Assert.AreEqual(3, result.Count); | ||
| 37 | + Assert.AreEqual("foo", result[0]); | ||
| 38 | + Assert.AreEqual("bar", result[1]); | ||
| 39 | + Assert.AreEqual("baz", result[2]); | ||
| 29 | 40 | } | |
| 30 | 41 | } | |
| 31 | 42 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -150,14 +150,14 @@ public void TestCtorBadString() | |||
| 150 | 150 | public void TestIsIntTypeTrue() | |
| 151 | 151 | { | |
| 152 | 152 | var i = new PyLong(5); | |
| 153 | - Assert.IsTrue(PyLong.IsLongType(i)); | ||
| 153 | + Assert.True(PyLong.IsLongType(i)); | ||
| 154 | 154 | } | |
| 155 | 155 | ||
| 156 | 156 | [Test] | |
| 157 | 157 | public void TestIsLongTypeFalse() | |
| 158 | 158 | { | |
| 159 | 159 | var s = new PyString("Foo"); | |
| 160 | - Assert.IsFalse(PyLong.IsLongType(s)); | ||
| 160 | + Assert.False(PyLong.IsLongType(s)); | ||
| 161 | 161 | } | |
| 162 | 162 | ||
| 163 | 163 | [Test] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,14 +22,14 @@ public void Dispose() | |||
| 22 | 22 | public void IsNumberTypeTrue() | |
| 23 | 23 | { | |
| 24 | 24 | var i = new PyInt(1); | |
| 25 | - Assert.IsTrue(PyNumber.IsNumberType(i)); | ||
| 25 | + Assert.True(PyNumber.IsNumberType(i)); | ||
| 26 | 26 | } | |
| 27 | 27 | ||
| 28 | 28 | [Test] | |
| 29 | 29 | public void IsNumberTypeFalse() | |
| 30 | 30 | { | |
| 31 | 31 | var s = new PyString("Foo"); | |
| 32 | - Assert.IsFalse(PyNumber.IsNumberType(s)); | ||
| 32 | + Assert.False(PyNumber.IsNumberType(s)); | ||
| 33 | 33 | } | |
| 34 | 34 | } | |
| 35 | 35 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,18 +6,27 @@ namespace Python.EmbeddingTest | |||
| 6 | 6 | { | |
| 7 | 7 | public class TestPyTuple | |
| 8 | 8 | { | |
| 9 | + [OneTimeSetUp] | ||
| 10 | + public void SetUp() | ||
| 11 | + { | ||
| 12 | + PythonEngine.Initialize(); | ||
| 13 | + } | ||
| 14 | + | ||
| 15 | + [OneTimeTearDown] | ||
| 16 | + public void Dispose() | ||
| 17 | + { | ||
| 18 | + PythonEngine.Shutdown(); | ||
| 19 | + } | ||
| 20 | + | ||
| 9 | 21 | /// <summary> | |
| 10 | 22 | /// Test IsTupleType without having to Initialize a tuple. | |
| 11 | 23 | /// PyTuple constructor use IsTupleType. This decouples the tests. | |
| 12 | 24 | /// </summary> | |
| 13 | 25 | [Test] | |
| 14 | 26 | public void TestStringIsTupleType() | |
| 15 | 27 | { | |
| 16 | - using (Py.GIL()) | ||
| 17 | - { | ||
| 18 | - var s = new PyString("foo"); | ||
| 19 | - Assert.IsFalse(PyTuple.IsTupleType(s)); | ||
| 20 | - } | ||
| 28 | + var s = new PyString("foo"); | ||
| 29 | + Assert.False(PyTuple.IsTupleType(s)); | ||
| 21 | 30 | } | |
| 22 | 31 | ||
| 23 | 32 | /// <summary> | |
@@ -26,72 +35,54 @@ public void TestStringIsTupleType() | |||
| 26 | 35 | [Test] | |
| 27 | 36 | public void TestPyTupleIsTupleType() | |
| 28 | 37 | { | |
| 29 | - using (Py.GIL()) | ||
| 30 | - { | ||
| 31 | - var t = new PyTuple(); | ||
| 32 | - Assert.IsTrue(PyTuple.IsTupleType(t)); | ||
| 33 | - } | ||
| 38 | + var t = new PyTuple(); | ||
| 39 | + Assert.True(PyTuple.IsTupleType(t)); | ||
| 34 | 40 | } | |
| 35 | 41 | ||
| 36 | 42 | [Test] | |
| 37 | 43 | public void TestPyTupleEmpty() | |
| 38 | 44 | { | |
| 39 | - using (Py.GIL()) | ||
| 40 | - { | ||
| 41 | - var t = new PyTuple(); | ||
| 42 | - Assert.AreEqual(0, t.Length()); | ||
| 43 | - } | ||
| 45 | + var t = new PyTuple(); | ||
| 46 | + Assert.AreEqual(0, t.Length()); | ||
| 44 | 47 | } | |
| 45 | 48 | ||
| 46 | 49 | [Test] | |
| 47 | 50 | public void TestPyTupleBadCtor() | |
| 48 | 51 | { | |
| 49 | - using (Py.GIL()) | ||
| 50 | - { | ||
| 51 | - var i = new PyInt(5); | ||
| 52 | - PyTuple t = null; | ||
| 52 | + var i = new PyInt(5); | ||
| 53 | + PyTuple t = null; | ||
| 53 | 54 | ||
| 54 | - var ex = Assert.Throws<ArgumentException>(() => t = new PyTuple(i)); | ||
| 55 | + var ex = Assert.Throws<ArgumentException>(() => t = new PyTuple(i)); | ||
| 55 | 56 | ||
| 56 | - Assert.AreEqual("object is not a tuple", ex.Message); | ||
| 57 | - Assert.IsNull(t); | ||
| 58 | - } | ||
| 57 | + Assert.AreEqual("object is not a tuple", ex.Message); | ||
| 58 | + Assert.IsNull(t); | ||
| 59 | 59 | } | |
| 60 | 60 | ||
| 61 | 61 | [Test] | |
| 62 | 62 | public void TestPyTupleCtorEmptyArray() | |
| 63 | 63 | { | |
| 64 | - using (Py.GIL()) | ||
| 65 | - { | ||
| 66 | - var a = new PyObject[] { }; | ||
| 67 | - var t = new PyTuple(a); | ||
| 64 | + var a = new PyObject[] { }; | ||
| 65 | + var t = new PyTuple(a); | ||
| 68 | 66 | ||
| 69 | - Assert.AreEqual(0, t.Length()); | ||
| 70 | - } | ||
| 67 | + Assert.AreEqual(0, t.Length()); | ||
| 71 | 68 | } | |
| 72 | 69 | ||
| 73 | 70 | [Test] | |
| 74 | 71 | public void TestPyTupleCtorArrayPyIntEmpty() | |
| 75 | 72 | { | |
| 76 | - using (Py.GIL()) | ||
| 77 | - { | ||
| 78 | - var a = new PyInt[] { }; | ||
| 79 | - var t = new PyTuple(a); | ||
| 73 | + var a = new PyInt[] { }; | ||
| 74 | + var t = new PyTuple(a); | ||
| 80 | 75 | ||
| 81 | - Assert.AreEqual(0, t.Length()); | ||
| 82 | - } | ||
| 76 | + Assert.AreEqual(0, t.Length()); | ||
| 83 | 77 | } | |
| 84 | 78 | ||
| 85 | 79 | [Test] | |
| 86 | 80 | public void TestPyTupleCtorArray() | |
| 87 | 81 | { | |
| 88 | - using (Py.GIL()) | ||
| 89 | - { | ||
| 90 | - var a = new PyObject[] {new PyInt(1), new PyString("Foo") }; | ||
| 91 | - var t = new PyTuple(a); | ||
| 82 | + var a = new PyObject[] { new PyInt(1), new PyString("Foo") }; | ||
| 83 | + var t = new PyTuple(a); | ||
| 92 | 84 | ||
| 93 | - Assert.AreEqual(2, t.Length()); | ||
| 94 | - } | ||
| 85 | + Assert.AreEqual(2, t.Length()); | ||
| 95 | 86 | } | |
| 96 | 87 | ||
| 97 | 88 | /// <summary> | |
@@ -108,69 +99,58 @@ public void TestPyTupleCtorArray() | |||
| 108 | 99 | [Test] | |
| 109 | 100 | public void TestPyTupleInvalidAppend() | |
| 110 | 101 | { | |
| 111 | - using (Py.GIL()) | ||
| 112 | - { | ||
| 113 | - PyObject s = new PyString("foo"); | ||
| 114 | - var t = new PyTuple(); | ||
| 102 | + PyObject s = new PyString("foo"); | ||
| 103 | + var t = new PyTuple(); | ||
| 115 | 104 | ||
| 116 | - var ex = Assert.Throws<PythonException>(() => t.Concat(s)); | ||
| 105 | + var ex = Assert.Throws<PythonException>(() => t.Concat(s)); | ||
| 117 | 106 | ||
| 118 | - StringAssert.StartsWith("TypeError : can only concatenate tuple", ex.Message); | ||
| 119 | - Assert.AreEqual(0, t.Length()); | ||
| 120 | - Assert.IsEmpty(t); | ||
| 121 | - } | ||
| 107 | + StringAssert.StartsWith("TypeError : can only concatenate tuple", ex.Message); | ||
| 108 | + Assert.AreEqual(0, t.Length()); | ||
| 109 | + Assert.IsEmpty(t); | ||
| 122 | 110 | } | |
| 123 | 111 | ||
| 124 | 112 | [Test] | |
| 125 | 113 | public void TestPyTupleValidAppend() | |
| 126 | 114 | { | |
| 127 | - using (Py.GIL()) | ||
| 128 | - { | ||
| 129 | - var t0 = new PyTuple(); | ||
| 130 | - var t = new PyTuple(); | ||
| 131 | - t.Concat(t0); | ||
| 132 | - Assert.IsNotNull(t); | ||
| 133 | - Assert.IsInstanceOf(typeof(PyTuple), t); | ||
| 134 | - } | ||
| 115 | + var t0 = new PyTuple(); | ||
| 116 | + var t = new PyTuple(); | ||
| 117 | + t.Concat(t0); | ||
| 118 | + | ||
| 119 | + Assert.IsNotNull(t); | ||
| 120 | + Assert.IsInstanceOf(typeof(PyTuple), t); | ||
| 135 | 121 | } | |
| 136 | 122 | ||
| 137 | 123 | [Test] | |
| 138 | 124 | public void TestPyTupleStringConvert() | |
| 139 | 125 | { | |
| 140 | - using (Py.GIL()) | ||
| 141 | - { | ||
| 142 | - PyObject s = new PyString("foo"); | ||
| 143 | - PyTuple t = PyTuple.AsTuple(s); | ||
| 144 | - Assert.IsNotNull(t); | ||
| 145 | - Assert.IsInstanceOf(typeof(PyTuple), t); | ||
| 146 | - Assert.AreEqual("f", t[0].ToString()); | ||
| 147 | - Assert.AreEqual("o", t[1].ToString()); | ||
| 148 | - Assert.AreEqual("o", t[2].ToString()); | ||
| 149 | - } | ||
| 126 | + PyObject s = new PyString("foo"); | ||
| 127 | + PyTuple t = PyTuple.AsTuple(s); | ||
| 128 | + | ||
| 129 | + Assert.IsNotNull(t); | ||
| 130 | + Assert.IsInstanceOf(typeof(PyTuple), t); | ||
| 131 | + Assert.AreEqual("f", t[0].ToString()); | ||
| 132 | + Assert.AreEqual("o", t[1].ToString()); | ||
| 133 | + Assert.AreEqual("o", t[2].ToString()); | ||
| 150 | 134 | } | |
| 151 | 135 | ||
| 152 | 136 | [Test] | |
| 153 | 137 | public void TestPyTupleValidConvert() | |
| 154 | 138 | { | |
| 155 | - using (Py.GIL()) | ||
| 156 | - { | ||
| 157 | - var l = new PyList(); | ||
| 158 | - PyTuple t = PyTuple.AsTuple(l); | ||
| 159 | - Assert.IsNotNull(t); | ||
| 160 | - Assert.IsInstanceOf(typeof(PyTuple), t); | ||
| 161 | - } | ||
| 139 | + var l = new PyList(); | ||
| 140 | + PyTuple t = PyTuple.AsTuple(l); | ||
| 141 | + | ||
| 142 | + Assert.IsNotNull(t); | ||
| 143 | + Assert.IsInstanceOf(typeof(PyTuple), t); | ||
| 162 | 144 | } | |
| 163 | 145 | ||
| 164 | 146 | [Test] | |
| 165 | 147 | public void TestNewPyTupleFromPyTuple() | |
| 166 | 148 | { | |
| 167 | - using (Py.GIL()) | ||
| 168 | - { | ||
| 169 | - var t0 = new PyTuple(); | ||
| 170 | - var t = new PyTuple(t0); | ||
| 171 | - Assert.IsNotNull(t); | ||
| 172 | - Assert.IsInstanceOf(typeof(PyTuple), t); | ||
| 173 | - } | ||
| 149 | + var t0 = new PyTuple(); | ||
| 150 | + var t = new PyTuple(t0); | ||
| 151 | + | ||
| 152 | + Assert.IsNotNull(t); | ||
| 153 | + Assert.IsInstanceOf(typeof(PyTuple), t); | ||
| 174 | 154 | } | |
| 175 | 155 | ||
| 176 | 156 | /// <remarks> | |
@@ -179,16 +159,13 @@ public void TestNewPyTupleFromPyTuple() | |||
| 179 | 159 | [Test] | |
| 180 | 160 | public void TestInvalidAsTuple() | |
| 181 | 161 | { | |
| 182 | - using (Py.GIL()) | ||
| 183 | - { | ||
| 184 | - var i = new PyInt(5); | ||
| 185 | - PyTuple t = null; | ||
| 162 | + var i = new PyInt(5); | ||
| 163 | + PyTuple t = null; | ||
| 186 | 164 | ||
| 187 | - var ex = Assert.Throws<PythonException>(() => t = PyTuple.AsTuple(i)); | ||
| 165 | + var ex = Assert.Throws<PythonException>(() => t = PyTuple.AsTuple(i)); | ||
| 188 | 166 | ||
| 189 | - Assert.AreEqual("TypeError : 'int' object is not iterable", ex.Message); | ||
| 190 | - Assert.IsNull(t); | ||
| 191 | - } | ||
| 167 | + Assert.AreEqual("TypeError : 'int' object is not iterable", ex.Message); | ||
| 168 | + Assert.IsNull(t); | ||
| 192 | 169 | } | |
| 193 | 170 | } | |
| 194 | 171 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments