| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3995130 commit 4919bff
9 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,20 +12,22 @@ $RUNTIME_DIR = ".\src\runtime\bin\" | |||
| 12 | 12 | ||
| 13 | 13 | # Run python tests with C# coverage | |
| 14 | 14 | # why `2>&1 | %{ "$_" }`? see: http://stackoverflow.com/a/20950421/5208670 | |
| 15 | + Write-Host ("Starting Python tests") -ForegroundColor "Green" | ||
| 15 | 16 | .$OPENCOVER -register:user -searchdirs:"$RUNTIME_DIR" -output:py.coverage -target:"$PY" -targetargs:src\tests\runtests.py -returntargetcode 2>&1 | %{ "$_" } | |
| 16 | 17 | $PYTHON_STATUS = $LastExitCode | |
| 17 | 18 | if ($PYTHON_STATUS -ne 0) { | |
| 18 | 19 | Write-Host "Python tests failed, continuing to embedded tests" -ForegroundColor "Red" | |
| 19 | 20 | } | |
| 20 | 21 | ||
| 21 | 22 | # Run Embedded tests with C# coverage | |
| 23 | + Write-Host ("Starting embedded tests") -ForegroundColor "Green" | ||
| 22 | 24 | .$OPENCOVER -register:user -searchdirs:"$RUNTIME_DIR" -output:cs.coverage -target:"$NUNIT" -targetargs:"$CS_TESTS" -returntargetcode | |
| 23 | 25 | $NUNIT_STATUS = $LastExitCode | |
| 24 | 26 | if ($NUNIT_STATUS -ne 0) { | |
| 25 | 27 | Write-Host "Embedded tests failed" -ForegroundColor "Red" | |
| 26 | 28 | } | |
| 27 | 29 | ||
| 28 | - # Embedded tests failing due to open issues, pass/fail only on Python exit code | ||
| 30 | + # Set exit code to fail if either Python or Embedded tests failed | ||
| 29 | 31 | if ($PYTHON_STATUS -ne 0 -or $NUNIT_STATUS -ne 0) { | |
| 30 | 32 | Write-Host "Tests failed" -ForegroundColor "Red" | |
| 31 | 33 | $host.SetShouldExit(1) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -75,12 +75,13 @@ | |||
| 75 | 75 | <None Include="packages.config" /> | |
| 76 | 76 | </ItemGroup> | |
| 77 | 77 | <ItemGroup> | |
| 78 | - <Compile Include="InitializeTest.cs" /> | ||
| 78 | + <Compile Include="pyinitialize.cs" /> | ||
| 79 | 79 | <Compile Include="pyimport.cs" /> | |
| 80 | 80 | <Compile Include="pyiter.cs" /> | |
| 81 | 81 | <Compile Include="pylong.cs" /> | |
| 82 | 82 | <Compile Include="pyobject.cs" /> | |
| 83 | 83 | <Compile Include="pythonexception.cs" /> | |
| 84 | + <Compile Include="pytuple.cs" /> | ||
| 84 | 85 | </ItemGroup> | |
| 85 | 86 | <ItemGroup> | |
| 86 | 87 | <ProjectReference Include="..\runtime\Python.Runtime.csproj"> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,6 +5,18 @@ | |||
| 5 | 5 | ||
| 6 | 6 | namespace Python.EmbeddingTest | |
| 7 | 7 | { | |
| 8 | + /// <summary> | ||
| 9 | + /// Test Import unittests and regressions | ||
| 10 | + /// </summary> | ||
| 11 | + /// <remarks> | ||
| 12 | + /// Keeping in old-style SetUp/TearDown due to required SetUp. | ||
| 13 | + /// The required directory structure was added to .\pythonnet\src\tests\ directory: | ||
| 14 | + /// + PyImportTest/ | ||
| 15 | + /// | - __init__.py | ||
| 16 | + /// | + test/ | ||
| 17 | + /// | | - __init__.py | ||
| 18 | + /// | | - one.py | ||
| 19 | + /// </remarks> | ||
| 8 | 20 | [TestFixture] | |
| 9 | 21 | public class PyImportTest | |
| 10 | 22 | { | |
@@ -18,10 +30,8 @@ public void SetUp() | |||
| 18 | 30 | ||
| 19 | 31 | /* Append the tests directory to sys.path | |
| 20 | 32 | * using reflection to circumvent the private | |
| 21 | - * modifiers placed on most Runtime methods. | ||
| 22 | - */ | ||
| 23 | - const string s = @"../../tests"; | ||
| 24 | - | ||
| 33 | + * modifiers placed on most Runtime methods. */ | ||
| 34 | + const string s = "../../tests"; | ||
| 25 | 35 | string testPath = Path.Combine(TestContext.CurrentContext.TestDirectory, s); | |
| 26 | 36 | ||
| 27 | 37 | IntPtr str = Runtime.Runtime.PyString_FromString(testPath); | |
@@ -39,19 +49,11 @@ public void TearDown() | |||
| 39 | 49 | /// <summary> | |
| 40 | 50 | /// Test subdirectory import | |
| 41 | 51 | /// </summary> | |
| 42 | - /// <remarks> | ||
| 43 | - /// The required directory structure was added to .\pythonnet\src\tests\ directory: | ||
| 44 | - /// + PyImportTest/ | ||
| 45 | - /// | - __init__.py | ||
| 46 | - /// | + test/ | ||
| 47 | - /// | | - __init__.py | ||
| 48 | - /// | | - one.py | ||
| 49 | - /// </remarks> | ||
| 50 | 52 | [Test] | |
| 51 | 53 | public void TestDottedName() | |
| 52 | 54 | { | |
| 53 | 55 | PyObject module = PythonEngine.ImportModule("PyImportTest.test.one"); | |
| 54 | - Assert.IsNotNull(module, ">>> import PyImportTest.test.one # FAILED"); | ||
| 56 | + Assert.IsNotNull(module); | ||
| 55 | 57 | } | |
| 56 | 58 | ||
| 57 | 59 | /// <summary> | |
@@ -61,7 +63,7 @@ public void TestDottedName() | |||
| 61 | 63 | public void TestSysArgsImportException() | |
| 62 | 64 | { | |
| 63 | 65 | PyObject module = PythonEngine.ImportModule("PyImportTest.sysargv"); | |
| 64 | - Assert.IsNotNull(module, ">>> import PyImportTest.sysargv # FAILED"); | ||
| 66 | + Assert.IsNotNull(module); | ||
| 65 | 67 | } | |
| 66 | 68 | } | |
| 67 | 69 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,13 +1,9 @@ | |||
| 1 | 1 | using NUnit.Framework; | |
| 2 | 2 | using Python.Runtime; | |
| 3 | - using System; | ||
| 4 | - using System.Collections.Generic; | ||
| 5 | - using System.Linq; | ||
| 6 | - using System.Text; | ||
| 7 | 3 | ||
| 8 | 4 | namespace Python.EmbeddingTest | |
| 9 | 5 | { | |
| 10 | - public class InitializeTest | ||
| 6 | + public class PyInitializeTest | ||
| 11 | 7 | { | |
| 12 | 8 | [Test] | |
| 13 | 9 | public static void LoadSpecificArgs() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,45 +1,30 @@ | |||
| 1 | - using System; | ||
| 2 | 1 | using System.Collections.Generic; | |
| 3 | 2 | using NUnit.Framework; | |
| 4 | 3 | using Python.Runtime; | |
| 5 | 4 | ||
| 6 | 5 | namespace Python.EmbeddingTest | |
| 7 | 6 | { | |
| 8 | - [TestFixture] | ||
| 9 | 7 | public class PyIterTest | |
| 10 | 8 | { | |
| 11 | - private IntPtr gs; | ||
| 12 | - | ||
| 13 | - [SetUp] | ||
| 14 | - public void SetUp() | ||
| 15 | - { | ||
| 16 | - PythonEngine.Initialize(); | ||
| 17 | - gs = PythonEngine.AcquireLock(); | ||
| 18 | - } | ||
| 19 | - | ||
| 20 | - [TearDown] | ||
| 21 | - public void TearDown() | ||
| 22 | - { | ||
| 23 | - PythonEngine.ReleaseLock(gs); | ||
| 24 | - PythonEngine.Shutdown(); | ||
| 25 | - } | ||
| 26 | - | ||
| 27 | 9 | [Test] | |
| 28 | 10 | public void TestOnPyList() | |
| 29 | 11 | { | |
| 30 | - var list = new PyList(); | ||
| 31 | - list.Append(new PyString("foo")); | ||
| 32 | - list.Append(new PyString("bar")); | ||
| 33 | - list.Append(new PyString("baz")); | ||
| 34 | - var result = new List<string>(); | ||
| 35 | - foreach (PyObject item in list) | ||
| 12 | + using (Py.GIL()) | ||
| 36 | 13 | { | |
| 37 | - result.Add(item.ToString()); | ||
| 14 | + var list = new PyList(); | ||
| 15 | + list.Append(new PyString("foo")); | ||
| 16 | + list.Append(new PyString("bar")); | ||
| 17 | + list.Append(new PyString("baz")); | ||
| 18 | + var result = new List<string>(); | ||
| 19 | + foreach (PyObject item in list) | ||
| 20 | + { | ||
| 21 | + result.Add(item.ToString()); | ||
| 22 | + } | ||
| 23 | + Assert.AreEqual(3, result.Count); | ||
| 24 | + Assert.AreEqual("foo", result[0]); | ||
| 25 | + Assert.AreEqual("bar", result[1]); | ||
| 26 | + Assert.AreEqual("baz", result[2]); | ||
| 38 | 27 | } | |
| 39 | - Assert.AreEqual(3, result.Count); | ||
| 40 | - Assert.AreEqual("foo", result[0]); | ||
| 41 | - Assert.AreEqual("bar", result[1]); | ||
| 42 | - Assert.AreEqual("baz", result[2]); | ||
| 43 | 28 | } | |
| 44 | 29 | } | |
| 45 | 30 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,34 +1,19 @@ | |||
| 1 | - using System; | ||
| 2 | 1 | using NUnit.Framework; | |
| 3 | 2 | using Python.Runtime; | |
| 4 | 3 | ||
| 5 | 4 | namespace Python.EmbeddingTest | |
| 6 | 5 | { | |
| 7 | - [TestFixture] | ||
| 8 | 6 | public class PyLongTest | |
| 9 | 7 | { | |
| 10 | - private IntPtr gs; | ||
| 11 | - | ||
| 12 | - [SetUp] | ||
| 13 | - public void SetUp() | ||
| 14 | - { | ||
| 15 | - PythonEngine.Initialize(); | ||
| 16 | - gs = PythonEngine.AcquireLock(); | ||
| 17 | - } | ||
| 18 | - | ||
| 19 | - [TearDown] | ||
| 20 | - public void TearDown() | ||
| 21 | - { | ||
| 22 | - PythonEngine.ReleaseLock(gs); | ||
| 23 | - PythonEngine.Shutdown(); | ||
| 24 | - } | ||
| 25 | - | ||
| 26 | 8 | [Test] | |
| 27 | 9 | public void TestToInt64() | |
| 28 | 10 | { | |
| 29 | - long largeNumber = 8L * 1024L * 1024L * 1024L; // 8 GB | ||
| 30 | - var pyLargeNumber = new PyLong(largeNumber); | ||
| 31 | - Assert.AreEqual(largeNumber, pyLargeNumber.ToInt64()); | ||
| 11 | + using (Py.GIL()) | ||
| 12 | + { | ||
| 13 | + long largeNumber = 8L * 1024L * 1024L * 1024L; // 8 GB | ||
| 14 | + var pyLargeNumber = new PyLong(largeNumber); | ||
| 15 | + Assert.AreEqual(largeNumber, pyLargeNumber.ToInt64()); | ||
| 16 | + } | ||
| 32 | 17 | } | |
| 33 | 18 | } | |
| 34 | 19 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,33 +1,18 @@ | |||
| 1 | - using System; | ||
| 2 | 1 | using NUnit.Framework; | |
| 3 | 2 | using Python.Runtime; | |
| 4 | 3 | ||
| 5 | 4 | namespace Python.EmbeddingTest | |
| 6 | 5 | { | |
| 7 | - [TestFixture] | ||
| 8 | 6 | public class PyObjectTest | |
| 9 | 7 | { | |
| 10 | - private IntPtr gs; | ||
| 11 | - | ||
| 12 | - [SetUp] | ||
| 13 | - public void SetUp() | ||
| 14 | - { | ||
| 15 | - PythonEngine.Initialize(); | ||
| 16 | - gs = PythonEngine.AcquireLock(); | ||
| 17 | - } | ||
| 18 | - | ||
| 19 | - [TearDown] | ||
| 20 | - public void TearDown() | ||
| 21 | - { | ||
| 22 | - PythonEngine.ReleaseLock(gs); | ||
| 23 | - PythonEngine.Shutdown(); | ||
| 24 | - } | ||
| 25 | - | ||
| 26 | 8 | [Test] | |
| 27 | 9 | public void TestUnicode() | |
| 28 | 10 | { | |
| 29 | - PyObject s = new PyString("foo\u00e9"); | ||
| 30 | - Assert.AreEqual("foo\u00e9", s.ToString()); | ||
| 11 | + using (Py.GIL()) | ||
| 12 | + { | ||
| 13 | + PyObject s = new PyString("foo\u00e9"); | ||
| 14 | + Assert.AreEqual("foo\u00e9", s.ToString()); | ||
| 15 | + } | ||
| 31 | 16 | } | |
| 32 | 17 | } | |
| 33 | 18 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,6 +4,13 @@ | |||
| 4 | 4 | ||
| 5 | 5 | namespace Python.EmbeddingTest | |
| 6 | 6 | { | |
| 7 | + /// <summary> | ||
| 8 | + /// Test Python Exceptions | ||
| 9 | + /// </summary> | ||
| 10 | + /// <remarks> | ||
| 11 | + /// Keeping this in the old-style SetUp/TearDown | ||
| 12 | + /// to ensure that setup still works. | ||
| 13 | + /// </remarks> | ||
| 7 | 14 | [TestFixture] | |
| 8 | 15 | public class PythonExceptionTest | |
| 9 | 16 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,94 @@ | |||
| 1 | + using NUnit.Framework; | ||
| 2 | + using Python.Runtime; | ||
| 3 | + | ||
| 4 | + namespace Python.EmbeddingTest | ||
| 5 | + { | ||
| 6 | + public class PyTupleTest | ||
| 7 | + { | ||
| 8 | + [Test] | ||
| 9 | + public void TestPyTupleEmpty() | ||
| 10 | + { | ||
| 11 | + using (Py.GIL()) | ||
| 12 | + { | ||
| 13 | + var t = new PyTuple(); | ||
| 14 | + Assert.AreEqual(0, t.Length()); | ||
| 15 | + } | ||
| 16 | + } | ||
| 17 | + | ||
| 18 | + [Test] | ||
| 19 | + [ExpectedException("Python.Runtime.PythonException")] | ||
| 20 | + public void TestPyTupleInvalidAppend() | ||
| 21 | + { | ||
| 22 | + using (Py.GIL()) | ||
| 23 | + { | ||
| 24 | + PyObject s = new PyString("foo"); | ||
| 25 | + var t = new PyTuple(); | ||
| 26 | + t.Concat(s); | ||
| 27 | + } | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + [Test] | ||
| 31 | + public void TestPyTupleValidAppend() | ||
| 32 | + { | ||
| 33 | + using (Py.GIL()) | ||
| 34 | + { | ||
| 35 | + var t0 = new PyTuple(); | ||
| 36 | + var t = new PyTuple(); | ||
| 37 | + t.Concat(t0); | ||
| 38 | + Assert.IsNotNull(t); | ||
| 39 | + Assert.IsInstanceOf(typeof(PyTuple), t); | ||
| 40 | + } | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + [Test] | ||
| 44 | + public void TestPyTupleIsTupleType() | ||
| 45 | + { | ||
| 46 | + using (Py.GIL()) | ||
| 47 | + { | ||
| 48 | + var s = new PyString("foo"); | ||
| 49 | + var t = new PyTuple(); | ||
| 50 | + Assert.IsTrue(PyTuple.IsTupleType(t)); | ||
| 51 | + Assert.IsFalse(PyTuple.IsTupleType(s)); | ||
| 52 | + } | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + [Test] | ||
| 56 | + public void TestPyTupleStringConvert() | ||
| 57 | + { | ||
| 58 | + using (Py.GIL()) | ||
| 59 | + { | ||
| 60 | + PyObject s = new PyString("foo"); | ||
| 61 | + PyTuple t = PyTuple.AsTuple(s); | ||
| 62 | + Assert.IsNotNull(t); | ||
| 63 | + Assert.IsInstanceOf(typeof(PyTuple), t); | ||
| 64 | + Assert.AreEqual("f", t[0].ToString()); | ||
| 65 | + Assert.AreEqual("o", t[1].ToString()); | ||
| 66 | + Assert.AreEqual("o", t[2].ToString()); | ||
| 67 | + } | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + [Test] | ||
| 71 | + public void TestPyTupleValidConvert() | ||
| 72 | + { | ||
| 73 | + using (Py.GIL()) | ||
| 74 | + { | ||
| 75 | + var l = new PyList(); | ||
| 76 | + PyTuple t = PyTuple.AsTuple(l); | ||
| 77 | + Assert.IsNotNull(t); | ||
| 78 | + Assert.IsInstanceOf(typeof(PyTuple), t); | ||
| 79 | + } | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + [Test] | ||
| 83 | + public void TestNewPyTupleFromPyTuple() | ||
| 84 | + { | ||
| 85 | + using (Py.GIL()) | ||
| 86 | + { | ||
| 87 | + var t0 = new PyTuple(); | ||
| 88 | + var t = new PyTuple(t0); | ||
| 89 | + Assert.IsNotNull(t); | ||
| 90 | + Assert.IsInstanceOf(typeof(PyTuple), t); | ||
| 91 | + } | ||
| 92 | + } | ||
| 93 | + } | ||
| 94 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments