Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/embed_tests/InitializeTest.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
12 changes: 9 additions & 3 deletions src/embed_tests/Python.EmbeddingTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,23 @@
<CodeAnalysisFailOnMissingRules>false</CodeAnalysisFailOnMissingRules>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.framework, Version=3.5.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\..\packages\NUnit.3.5.0\lib\net40\nunit.framework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="nunit.framework">
<HintPath>..\..\packages\NUnit.2.6.2\lib\nunit.framework.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<None Include="Embeddingtest.nunit" />
<None Include="..\pythonnet.snk" />
<None Include="packages.config" />
<None Include="pythonnet.snk" Condition="Exists('pythonnet.snk')" />
</ItemGroup>
<ItemGroup>
<Compile Include="InitializeTest.cs" />
<Compile Include="pyimport.cs" />
<Compile Include="pyiter.cs">
<SubType>Code</SubType>
Expand Down Expand Up @@ -172,6 +175,9 @@
<Name>Python.Runtime</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
<ProjectExtensions>
<VisualStudio AllowExistingFolder="true" />
Expand Down
5 changes: 2 additions & 3 deletions src/embed_tests/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>

<packages>
<package id="NUnit" version="2.6.2" targetFramework="net40" />
</packages>
<package id="NUnit" version="3.5.0" targetFramework="net40" />
</packages>
28 changes: 7 additions & 21 deletions src/embed_tests/pyimport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using NUnit.Framework;
using Python.Runtime;
using System.IO;

namespace Python.EmbeddingTest
{
Expand All @@ -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]
Expand Down
22 changes: 2 additions & 20 deletions src/runtime/assemblyinfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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")]