Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2f24a35

Browse files
committed
Move tests that require reinit and only run on .NET Framework
1 parenta38eddc commit2f24a35

File tree

7 files changed

+177
-145
lines changed

7 files changed

+177
-145
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
usingPython.Runtime;
2+
usingNUnit.Framework;
3+
4+
namespacePython.EmbeddingTest.NeedsReinit;
5+
6+
publicclassStopAndRestartEngine
7+
{
8+
boolWasInitialized=false;
9+
10+
[OneTimeSetUp]
11+
publicvoidSetup()
12+
{
13+
WasInitialized=PythonEngine.IsInitialized;
14+
if(WasInitialized)
15+
{
16+
PythonEngine.Shutdown();
17+
}
18+
}
19+
20+
[OneTimeTearDown]
21+
publicvoidTeardown()
22+
{
23+
if(WasInitialized&&!PythonEngine.IsInitialized)
24+
{
25+
PythonEngine.Initialize();
26+
}
27+
}
28+
}

src/embed_tests/TestDomainReload.cs renamed to src/embed_tests/NeedsReinit/TestDomainReload.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@
1515
// Unfortunately this means no continuous integration testing for this case.
1616
//
1717
#ifNETFRAMEWORK
18-
namespacePython.EmbeddingTest
18+
namespacePython.EmbeddingTest.NeedsReinit
1919
{
20-
classTestDomainReload
20+
[Category("NeedsReinit")]
21+
classTestDomainReload:StopAndRestartEngine
2122
{
23+
24+
2225
abstractclassCrossCaller:MarshalByRefObject
2326
{
2427
publicabstractValueTypeExecute(ValueTypearg);

src/embed_tests/pyinitialize.cs renamed to src/embed_tests/NeedsReinit/TestPyInitialize.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
usingNUnit.Framework;
33
usingPython.Runtime;
44

5-
namespacePython.EmbeddingTest
5+
namespacePython.EmbeddingTest.NeedsReinit
66
{
7-
[Ignore("Only works if we can re-initialize the Python engine")]
8-
publicclassPyInitializeTest
7+
[Category("NeedsReinit")]
8+
publicclassTestPyInitialize:StopAndRestartEngine
99
{
1010
/// <summary>
1111
/// Tests issue with multiple simple Initialize/Shutdowns.
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
usingSystem;
2+
usingNUnit.Framework;
3+
usingPython.Runtime;
4+
5+
namespacePython.EmbeddingTest.NeedsReinit
6+
{
7+
[Category("NeedsReinit")]
8+
publicclassTestPythonEngineProperties:StopAndRestartEngine
9+
{
10+
[Test]
11+
publicvoidSetPythonHome()
12+
{
13+
PythonEngine.Initialize();
14+
varpythonHomeBackup=PythonEngine.PythonHome;
15+
PythonEngine.Shutdown();
16+
17+
if(pythonHomeBackup=="")
18+
Assert.Inconclusive("Can't reset PythonHome to empty string, skipping");
19+
20+
varpythonHome="/dummypath/";
21+
22+
PythonEngine.PythonHome=pythonHome;
23+
PythonEngine.Initialize();
24+
25+
Assert.AreEqual(pythonHome,PythonEngine.PythonHome);
26+
PythonEngine.Shutdown();
27+
28+
// Restoring valid pythonhome.
29+
PythonEngine.PythonHome=pythonHomeBackup;
30+
}
31+
32+
[Test]
33+
publicvoidSetPythonHomeTwice()
34+
{
35+
PythonEngine.Initialize();
36+
varpythonHomeBackup=PythonEngine.PythonHome;
37+
PythonEngine.Shutdown();
38+
39+
if(pythonHomeBackup=="")
40+
Assert.Inconclusive("Can't reset PythonHome to empty string, skipping");
41+
42+
varpythonHome="/dummypath/";
43+
44+
PythonEngine.PythonHome="/dummypath2/";
45+
PythonEngine.PythonHome=pythonHome;
46+
PythonEngine.Initialize();
47+
48+
Assert.AreEqual(pythonHome,PythonEngine.PythonHome);
49+
PythonEngine.Shutdown();
50+
51+
PythonEngine.PythonHome=pythonHomeBackup;
52+
}
53+
54+
[Test]
55+
[Ignore("Currently buggy in Python")]
56+
publicvoidSetPythonHomeEmptyString()
57+
{
58+
PythonEngine.Initialize();
59+
60+
varbackup=PythonEngine.PythonHome;
61+
if(backup=="")
62+
{
63+
PythonEngine.Shutdown();
64+
Assert.Inconclusive("Can't reset PythonHome to empty string, skipping");
65+
}
66+
PythonEngine.PythonHome="";
67+
68+
Assert.AreEqual("",PythonEngine.PythonHome);
69+
70+
PythonEngine.PythonHome=backup;
71+
PythonEngine.Shutdown();
72+
}
73+
74+
[Test]
75+
publicvoidSetProgramName()
76+
{
77+
if(PythonEngine.IsInitialized)
78+
{
79+
PythonEngine.Shutdown();
80+
}
81+
82+
varprogramNameBackup=PythonEngine.ProgramName;
83+
84+
varprogramName="FooBar";
85+
86+
PythonEngine.ProgramName=programName;
87+
PythonEngine.Initialize();
88+
89+
Assert.AreEqual(programName,PythonEngine.ProgramName);
90+
PythonEngine.Shutdown();
91+
92+
PythonEngine.ProgramName=programNameBackup;
93+
}
94+
95+
[Test]
96+
publicvoidSetPythonPath()
97+
{
98+
PythonEngine.Initialize();
99+
100+
conststringmoduleName="pytest";
101+
boolimportShouldSucceed;
102+
try
103+
{
104+
Py.Import(moduleName);
105+
importShouldSucceed=true;
106+
}
107+
catch
108+
{
109+
importShouldSucceed=false;
110+
}
111+
112+
string[]paths=Py.Import("sys").GetAttr("path").As<string[]>();
113+
stringpath=string.Join(System.IO.Path.PathSeparator.ToString(),paths);
114+
115+
// path should not be set to PythonEngine.PythonPath here.
116+
// PythonEngine.PythonPath gets the default module search path, not the full search path.
117+
// The list sys.path is initialized with this value on interpreter startup;
118+
// it can be (and usually is) modified later to change the search path for loading modules.
119+
// See https://docs.python.org/3/c-api/init.html#c.Py_GetPath
120+
// After PythonPath is set, then PythonEngine.PythonPath will correctly return the full search path.
121+
122+
PythonEngine.Shutdown();
123+
124+
PythonEngine.PythonPath=path;
125+
PythonEngine.Initialize();
126+
127+
Assert.AreEqual(path,PythonEngine.PythonPath);
128+
if(importShouldSucceed)Py.Import(moduleName);
129+
130+
PythonEngine.Shutdown();
131+
}
132+
}
133+
}

src/embed_tests/TestRuntime.cs renamed to src/embed_tests/NeedsReinit/TestRuntime.cs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,11 @@
33
usingNUnit.Framework;
44
usingPython.Runtime;
55

6-
namespacePython.EmbeddingTest
6+
namespacePython.EmbeddingTest.NeedsReinit
77
{
8-
[Ignore("Only works if we can shutdown and re-initialize the Python runtime")]
9-
publicclassTestRuntime
8+
[Ignore("Tests for low-level Runtime functions, crashing currently")]
9+
publicclassTestRuntime:StopAndRestartEngine
1010
{
11-
[OneTimeSetUp]
12-
publicvoidSetUp()
13-
{
14-
// We needs to ensure that no any engines are running.
15-
if(PythonEngine.IsInitialized)
16-
{
17-
PythonEngine.Shutdown();
18-
}
19-
}
20-
2111
[Test]
2212
publicstaticvoidPy_IsInitializedValue()
2313
{

‎src/embed_tests/Python.EmbeddingTest.csproj‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
<NoneInclude="fixtures/**/*.py"CopyToOutputDirectory="PreserveNewest" />
1515
</ItemGroup>
1616

17+
<!-- Drop Reinit test source files for net8.0 and above-->
18+
<ItemGroupCondition="'$(TargetFramework)' != 'net472'">
19+
<CompileRemove="NeedsReinit/*.cs" />
20+
</ItemGroup>
21+
1722
<PropertyGroup>
1823
<DefineConstants>$(DefineConstants);$(ConfiguredConstants)</DefineConstants>
1924
</PropertyGroup>

‎src/embed_tests/TestPythonEngineProperties.cs‎

Lines changed: 0 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -96,132 +96,5 @@ public static void GetPythonHomeDefault()
9696

9797
Assert.AreEqual(envPythonHome,enginePythonHome);
9898
}
99-
100-
[Ignore("Only works if we can shutdown and re-init the interpreter")]
101-
[Test]
102-
publicvoidSetPythonHome()
103-
{
104-
PythonEngine.Initialize();
105-
varpythonHomeBackup=PythonEngine.PythonHome;
106-
PythonEngine.Shutdown();
107-
108-
if(pythonHomeBackup=="")
109-
Assert.Inconclusive("Can't reset PythonHome to empty string, skipping");
110-
111-
varpythonHome="/dummypath/";
112-
113-
PythonEngine.PythonHome=pythonHome;
114-
PythonEngine.Initialize();
115-
116-
Assert.AreEqual(pythonHome,PythonEngine.PythonHome);
117-
PythonEngine.Shutdown();
118-
119-
// Restoring valid pythonhome.
120-
PythonEngine.PythonHome=pythonHomeBackup;
121-
}
122-
123-
[Ignore("Only works if we can shutdown and re-init the interpreter")]
124-
[Test]
125-
publicvoidSetPythonHomeTwice()
126-
{
127-
PythonEngine.Initialize();
128-
varpythonHomeBackup=PythonEngine.PythonHome;
129-
PythonEngine.Shutdown();
130-
131-
if(pythonHomeBackup=="")
132-
Assert.Inconclusive("Can't reset PythonHome to empty string, skipping");
133-
134-
varpythonHome="/dummypath/";
135-
136-
PythonEngine.PythonHome="/dummypath2/";
137-
PythonEngine.PythonHome=pythonHome;
138-
PythonEngine.Initialize();
139-
140-
Assert.AreEqual(pythonHome,PythonEngine.PythonHome);
141-
PythonEngine.Shutdown();
142-
143-
PythonEngine.PythonHome=pythonHomeBackup;
144-
}
145-
146-
[Test]
147-
[Ignore("Currently buggy in Python")]
148-
publicvoidSetPythonHomeEmptyString()
149-
{
150-
PythonEngine.Initialize();
151-
152-
varbackup=PythonEngine.PythonHome;
153-
if(backup=="")
154-
{
155-
PythonEngine.Shutdown();
156-
Assert.Inconclusive("Can't reset PythonHome to empty string, skipping");
157-
}
158-
PythonEngine.PythonHome="";
159-
160-
Assert.AreEqual("",PythonEngine.PythonHome);
161-
162-
PythonEngine.PythonHome=backup;
163-
PythonEngine.Shutdown();
164-
}
165-
166-
[Ignore("Only works if we can shutdown and re-init the interpreter")]
167-
[Test]
168-
publicvoidSetProgramName()
169-
{
170-
if(PythonEngine.IsInitialized)
171-
{
172-
PythonEngine.Shutdown();
173-
}
174-
175-
varprogramNameBackup=PythonEngine.ProgramName;
176-
177-
varprogramName="FooBar";
178-
179-
PythonEngine.ProgramName=programName;
180-
PythonEngine.Initialize();
181-
182-
Assert.AreEqual(programName,PythonEngine.ProgramName);
183-
PythonEngine.Shutdown();
184-
185-
PythonEngine.ProgramName=programNameBackup;
186-
}
187-
188-
[Ignore("Only works if we can shutdown and re-init the interpreter")]
189-
[Test]
190-
publicvoidSetPythonPath()
191-
{
192-
PythonEngine.Initialize();
193-
194-
conststringmoduleName="pytest";
195-
boolimportShouldSucceed;
196-
try
197-
{
198-
Py.Import(moduleName);
199-
importShouldSucceed=true;
200-
}
201-
catch
202-
{
203-
importShouldSucceed=false;
204-
}
205-
206-
string[]paths=Py.Import("sys").GetAttr("path").As<string[]>();
207-
stringpath=string.Join(System.IO.Path.PathSeparator.ToString(),paths);
208-
209-
// path should not be set to PythonEngine.PythonPath here.
210-
// PythonEngine.PythonPath gets the default module search path, not the full search path.
211-
// The list sys.path is initialized with this value on interpreter startup;
212-
// it can be (and usually is) modified later to change the search path for loading modules.
213-
// See https://docs.python.org/3/c-api/init.html#c.Py_GetPath
214-
// After PythonPath is set, then PythonEngine.PythonPath will correctly return the full search path.
215-
216-
PythonEngine.Shutdown();
217-
218-
PythonEngine.PythonPath=path;
219-
PythonEngine.Initialize();
220-
221-
Assert.AreEqual(path,PythonEngine.PythonPath);
222-
if(importShouldSucceed)Py.Import(moduleName);
223-
224-
PythonEngine.Shutdown();
225-
}
22699
}
227100
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp