From 58d2459eab237bbf99569d5ceaefa47e01190843 Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Tue, 24 Jan 2017 15:54:28 +0100 Subject: [PATCH 1/4] Make internals (in particular Runtime.*) visible to the tests. --- src/runtime/assemblyinfo.cs | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/src/runtime/assemblyinfo.cs b/src/runtime/assemblyinfo.cs index 49433f0dc..c4056a1ad 100644 --- a/src/runtime/assemblyinfo.cs +++ b/src/runtime/assemblyinfo.cs @@ -2,6 +2,7 @@ using System.Reflection; using System.Resources; using System.Runtime.InteropServices; +using System.Runtime.CompilerServices; [assembly: AssemblyProduct("Python for .NET")] [assembly: AssemblyVersion("4.0.0.1")] @@ -12,23 +13,4 @@ [assembly: AssemblyFileVersion("2.0.0.2")] [assembly: NeutralResourcesLanguage("en")] -#if PYTHON27 -[assembly: AssemblyTitle("Python.Runtime for Python 2.7")] -[assembly: AssemblyDescription("Python Runtime for Python 2.7")] -#endif -#if PYTHON33 -[assembly: AssemblyTitle("Python.Runtime for Python 3.3")] -[assembly: AssemblyDescription("Python Runtime for Python 3.3")] -#endif -#if PYTHON34 -[assembly: AssemblyTitle("Python.Runtime for Python 3.4")] -[assembly: AssemblyDescription("Python Runtime for Python 3.4")] -#endif -#if PYTHON35 -[assembly: AssemblyTitle("Python.Runtime for Python 3.5")] -[assembly: AssemblyDescription("Python Runtime for Python 3.5")] -#endif -#if PYTHON36 -[assembly: AssemblyTitle("Python.Runtime for Python 3.6")] -[assembly: AssemblyDescription("Python Runtime for Python 3.6")] -#endif +[assembly: InternalsVisibleTo("Python.EmbeddingTest")] \ No newline at end of file From 8baf9d336e36a3bba99ddee6604b6f0659a6c7a8 Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Tue, 24 Jan 2017 15:56:42 +0100 Subject: [PATCH 2/4] Simplify the `sys.path` setting in the PyImportTests. --- src/embed_tests/pyimport.cs | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/src/embed_tests/pyimport.cs b/src/embed_tests/pyimport.cs index 58da0ac13..e928ab633 100644 --- a/src/embed_tests/pyimport.cs +++ b/src/embed_tests/pyimport.cs @@ -26,25 +26,13 @@ public void SetUp() */ const string s = @"../../../../tests"; - Type RTClass = typeof(Runtime.Runtime); + var testPath = Path.Combine( + TestContext.CurrentContext.TestDirectory, s + ); - /* pyStrPtr = PyString_FromString(s); */ - MethodInfo PyString_FromString = RTClass.GetMethod("PyString_FromString", - BindingFlags.NonPublic | BindingFlags.Static); - object[] funcArgs = new object[1]; - funcArgs[0] = s; - IntPtr pyStrPtr = (IntPtr)PyString_FromString.Invoke(null, funcArgs); - - /* SysDotPath = sys.path */ - MethodInfo PySys_GetObject = RTClass.GetMethod("PySys_GetObject", - BindingFlags.NonPublic | BindingFlags.Static); - funcArgs[0] = "path"; - IntPtr SysDotPath = (IntPtr)PySys_GetObject.Invoke(null, funcArgs); - - /* SysDotPath.append(*pyStrPtr) */ - MethodInfo PyList_Append = RTClass.GetMethod("PyList_Append", BindingFlags.NonPublic | BindingFlags.Static); - funcArgs = new object[] { SysDotPath, pyStrPtr }; - int r = (int)PyList_Append.Invoke(null, funcArgs); + IntPtr str = Runtime.Runtime.PyString_FromString(testPath); + IntPtr path = Runtime.Runtime.PySys_GetObject("path"); + Runtime.Runtime.PyList_Append(path, str); } [TearDown] From a748b3aa57a7b199ffca4905913df9cd70e14a8a Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Tue, 24 Jan 2017 16:05:43 +0100 Subject: [PATCH 3/4] Add initialize test and update NUnit. --- src/embed_tests/InitializeTest.cs | 22 +++++++++++++++++++++ src/embed_tests/Python.EmbeddingTest.csproj | 12 ++++++++--- src/embed_tests/packages.config | 5 ++--- 3 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 src/embed_tests/InitializeTest.cs diff --git a/src/embed_tests/InitializeTest.cs b/src/embed_tests/InitializeTest.cs new file mode 100644 index 000000000..a9667343c --- /dev/null +++ b/src/embed_tests/InitializeTest.cs @@ -0,0 +1,22 @@ +using NUnit.Framework; +using Python.Runtime; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Python.EmbeddingTest +{ + public class InitializeTest + { + [Test] + public static void Test() + { + PythonEngine.Initialize(); + PythonEngine.Shutdown(); + + PythonEngine.Initialize(); + PythonEngine.Shutdown(); + } + } +} diff --git a/src/embed_tests/Python.EmbeddingTest.csproj b/src/embed_tests/Python.EmbeddingTest.csproj index 24645f1bd..f2b4dce61 100644 --- a/src/embed_tests/Python.EmbeddingTest.csproj +++ b/src/embed_tests/Python.EmbeddingTest.csproj @@ -128,20 +128,23 @@ false + + ..\..\packages\NUnit.3.5.0\lib\net40\nunit.framework.dll + True + 3.5 - - ..\..\packages\NUnit.2.6.2\lib\nunit.framework.dll - + + Code @@ -172,6 +175,9 @@ Python.Runtime + + + diff --git a/src/embed_tests/packages.config b/src/embed_tests/packages.config index fdc687a35..7b9ec0c4c 100644 --- a/src/embed_tests/packages.config +++ b/src/embed_tests/packages.config @@ -1,5 +1,4 @@ - - - + + \ No newline at end of file From f6ebcb94e66cbc2826c9620afdef9fd2da39d690 Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Thu, 26 Jan 2017 17:36:18 +0100 Subject: [PATCH 4/4] Add missing using to the pyimport tests. --- src/embed_tests/pyimport.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/embed_tests/pyimport.cs b/src/embed_tests/pyimport.cs index e928ab633..c7a567bdf 100644 --- a/src/embed_tests/pyimport.cs +++ b/src/embed_tests/pyimport.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using NUnit.Framework; using Python.Runtime; +using System.IO; namespace Python.EmbeddingTest { @@ -17,9 +18,6 @@ public void SetUp() PythonEngine.Initialize(); gs = PythonEngine.AcquireLock(); - //string here = Environment.CurrentDirectory; - //trunk\pythonnet\src\embed_tests\bin\x86\DebugWin - /* * Append the tests directory to sys.path * using reflection to circumvent the private modifires placed on most Runtime methods.