Merge pull request #341 from filmor/improve-tests · pythonnet/pythonnet@b3bbdfb · GitHub
Skip to content

Commit b3bbdfb

Browse files
committed
Merge pull request #341 from filmor/improve-tests
2 parents f4d83cf + 689c1fc commit b3bbdfb

5 files changed

Lines changed: 41 additions & 46 deletions

File tree

src/embed_tests/InitializeTest.cs

Lines changed: 22 additions & 0 deletions

src/embed_tests/Python.EmbeddingTest.csproj

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,20 +128,23 @@
128128
<CodeAnalysisFailOnMissingRules>false</CodeAnalysisFailOnMissingRules>
129129
</PropertyGroup>
130130
<ItemGroup>
131+
<Reference Include="nunit.framework, Version=3.5.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
132+
<HintPath>..\..\packages\NUnit.3.5.0\lib\net40\nunit.framework.dll</HintPath>
133+
<Private>True</Private>
134+
</Reference>
131135
<Reference Include="System" />
132136
<Reference Include="System.Core">
133137
<RequiredTargetFramework>3.5</RequiredTargetFramework>
134138
</Reference>
135-
<Reference Include="nunit.framework">
136-
<HintPath>..\..\packages\NUnit.2.6.2\lib\nunit.framework.dll</HintPath>
137-
</Reference>
138139
</ItemGroup>
139140
<ItemGroup>
140141
<None Include="Embeddingtest.nunit" />
141142
<None Include="..\pythonnet.snk" />
142143
<None Include="packages.config" />
144+
<None Include="pythonnet.snk" Condition="Exists('pythonnet.snk')" />
143145
</ItemGroup>
144146
<ItemGroup>
147+
<Compile Include="InitializeTest.cs" />
145148
<Compile Include="pyimport.cs" />
146149
<Compile Include="pyiter.cs">
147150
<SubType>Code</SubType>
@@ -172,6 +175,9 @@
172175
<Name>Python.Runtime</Name>
173176
</ProjectReference>
174177
</ItemGroup>
178+
<ItemGroup>
179+
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
180+
</ItemGroup>
175181
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
176182
<ProjectExtensions>
177183
<VisualStudio AllowExistingFolder="true" />

src/embed_tests/packages.config

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
32
<packages>
4-
<package id="NUnit" version="2.6.2" targetFramework="net40" />
3+
<package id="NUnit" version="3.5.0" targetFramework="net40" />
54
</packages>

src/embed_tests/pyimport.cs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections.Generic;
44
using NUnit.Framework;
55
using Python.Runtime;
6+
using System.IO;
67

78
namespace Python.EmbeddingTest
89
{
@@ -17,34 +18,19 @@ public void SetUp()
1718
PythonEngine.Initialize();
1819
gs = PythonEngine.AcquireLock();
1920

20-
//string here = Environment.CurrentDirectory;
21-
//trunk\pythonnet\src\embed_tests\bin\x86\DebugWin
22-
2321
/*
2422
* Append the tests directory to sys.path
2523
* using reflection to circumvent the private modifires placed on most Runtime methods.
2624
*/
2725
const string s = @"../../../../tests";
2826

29-
Type RTClass = typeof(Runtime.Runtime);
30-
31-
/* pyStrPtr = PyString_FromString(s); */
32-
MethodInfo PyString_FromString = RTClass.GetMethod("PyString_FromString",
33-
BindingFlags.NonPublic | BindingFlags.Static);
34-
object[] funcArgs = new object[1];
35-
funcArgs[0] = s;
36-
IntPtr pyStrPtr = (IntPtr)PyString_FromString.Invoke(null, funcArgs);
37-
38-
/* SysDotPath = sys.path */
39-
MethodInfo PySys_GetObject = RTClass.GetMethod("PySys_GetObject",
40-
BindingFlags.NonPublic | BindingFlags.Static);
41-
funcArgs[0] = "path";
42-
IntPtr SysDotPath = (IntPtr)PySys_GetObject.Invoke(null, funcArgs);
27+
var testPath = Path.Combine(
28+
TestContext.CurrentContext.TestDirectory, s
29+
);
4330

44-
/* SysDotPath.append(*pyStrPtr) */
45-
MethodInfo PyList_Append = RTClass.GetMethod("PyList_Append", BindingFlags.NonPublic | BindingFlags.Static);
46-
funcArgs = new object[] { SysDotPath, pyStrPtr };
47-
int r = (int)PyList_Append.Invoke(null, funcArgs);
31+
IntPtr str = Runtime.Runtime.PyString_FromString(testPath);
32+
IntPtr path = Runtime.Runtime.PySys_GetObject("path");
33+
Runtime.Runtime.PyList_Append(path, str);
4834
}
4935

5036
[TearDown]

src/runtime/assemblyinfo.cs

Lines changed: 2 additions & 20 deletions

0 commit comments

Comments
 (0)