🌐 AI搜索 & 代理 主页
Skip to content

Commit b3bbdfb

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

File tree

5 files changed

+41
-46
lines changed

5 files changed

+41
-46
lines changed

src/embed_tests/InitializeTest.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using NUnit.Framework;
2+
using Python.Runtime;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
8+
namespace Python.EmbeddingTest
9+
{
10+
public class InitializeTest
11+
{
12+
[Test]
13+
public static void Test()
14+
{
15+
PythonEngine.Initialize();
16+
PythonEngine.Shutdown();
17+
18+
PythonEngine.Initialize();
19+
PythonEngine.Shutdown();
20+
}
21+
}
22+
}

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
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Reflection;
33
using System.Resources;
44
using System.Runtime.InteropServices;
5+
using System.Runtime.CompilerServices;
56

67
[assembly: AssemblyProduct("Python for .NET")]
78
[assembly: AssemblyVersion("4.0.0.1")]
@@ -11,23 +12,4 @@
1112
[assembly: AssemblyCopyright("MIT License")]
1213
[assembly: AssemblyFileVersion("2.0.0.2")]
1314
[assembly: NeutralResourcesLanguage("en")]
14-
15-
#if PYTHON27
16-
[assembly: AssemblyTitle("Python.Runtime for Python 2.7")]
17-
[assembly: AssemblyDescription("Python Runtime for Python 2.7")]
18-
#elif PYTHON33
19-
[assembly: AssemblyTitle("Python.Runtime for Python 3.3")]
20-
[assembly: AssemblyDescription("Python Runtime for Python 3.3")]
21-
#elif PYTHON34
22-
[assembly: AssemblyTitle("Python.Runtime for Python 3.4")]
23-
[assembly: AssemblyDescription("Python Runtime for Python 3.4")]
24-
#elif PYTHON35
25-
[assembly: AssemblyTitle("Python.Runtime for Python 3.5")]
26-
[assembly: AssemblyDescription("Python Runtime for Python 3.5")]
27-
#elif PYTHON36
28-
[assembly: AssemblyTitle("Python.Runtime for Python 3.6")]
29-
[assembly: AssemblyDescription("Python Runtime for Python 3.6")]
30-
#elif PYTHON37
31-
[assembly: AssemblyTitle("Python.Runtime for Python 3.7")]
32-
[assembly: AssemblyDescription("Python Runtime for Python 3.7")]
33-
#endif
15+
[assembly: InternalsVisibleTo("Python.EmbeddingTest")]

0 commit comments

Comments
 (0)