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 diff --git a/src/embed_tests/pyimport.cs b/src/embed_tests/pyimport.cs index 58da0ac13..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,34 +18,19 @@ 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. */ const string s = @"../../../../tests"; - Type RTClass = typeof(Runtime.Runtime); - - /* 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); + var testPath = Path.Combine( + TestContext.CurrentContext.TestDirectory, s + ); - /* 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] diff --git a/src/runtime/assemblyinfo.cs b/src/runtime/assemblyinfo.cs index 1defa851f..1cbd1e749 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")] @@ -11,23 +12,4 @@ [assembly: AssemblyCopyright("MIT License")] [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")] -#elif PYTHON33 -[assembly: AssemblyTitle("Python.Runtime for Python 3.3")] -[assembly: AssemblyDescription("Python Runtime for Python 3.3")] -#elif PYTHON34 -[assembly: AssemblyTitle("Python.Runtime for Python 3.4")] -[assembly: AssemblyDescription("Python Runtime for Python 3.4")] -#elif PYTHON35 -[assembly: AssemblyTitle("Python.Runtime for Python 3.5")] -[assembly: AssemblyDescription("Python Runtime for Python 3.5")] -#elif PYTHON36 -[assembly: AssemblyTitle("Python.Runtime for Python 3.6")] -[assembly: AssemblyDescription("Python Runtime for Python 3.6")] -#elif PYTHON37 -[assembly: AssemblyTitle("Python.Runtime for Python 3.7")] -[assembly: AssemblyDescription("Python Runtime for Python 3.7")] -#endif +[assembly: InternalsVisibleTo("Python.EmbeddingTest")]