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
This repository was archived by the owner on Jul 22, 2023. It is now read-only.
/pythonnetPublic archive
forked frompythonnet/pythonnet

Commit7db41a9

Browse files
committed
Fix Py_SetPath not available in PY2
Closespythonnet#418
1 parent6d08374 commit7db41a9

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

‎src/embed_tests/TestPythonEngineProperties.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,5 +142,46 @@ public void SetProgramName()
142142
Assert.AreEqual(programName,PythonEngine.ProgramName);
143143
PythonEngine.Shutdown();
144144
}
145+
146+
[Test]
147+
publicvoidSetPythonPath()
148+
{
149+
if(Runtime.Runtime.pyversion=="2.7")
150+
{
151+
// Assert.Skip outputs as a warning (ie. pending to fix)
152+
Assert.Pass();
153+
}
154+
155+
PythonEngine.Initialize();
156+
stringpath=PythonEngine.PythonPath;
157+
PythonEngine.Shutdown();
158+
159+
PythonEngine.ProgramName=path;
160+
PythonEngine.Initialize();
161+
162+
Assert.AreEqual(path,PythonEngine.PythonPath);
163+
PythonEngine.Shutdown();
164+
}
165+
166+
[Test]
167+
publicvoidSetPythonPathExceptionOn27()
168+
{
169+
if(Runtime.Runtime.pyversion!="2.7")
170+
{
171+
Assert.Pass();
172+
}
173+
174+
// Get previous path to avoid crashing Python
175+
PythonEngine.Initialize();
176+
stringpath=PythonEngine.PythonPath;
177+
PythonEngine.Shutdown();
178+
179+
varex=Assert.Throws<NotSupportedException>(()=>PythonEngine.PythonPath="foo");
180+
Assert.AreEqual("Set PythonPath not supported on Python 2",ex.Message);
181+
182+
PythonEngine.Initialize();
183+
Assert.AreEqual(path,PythonEngine.PythonPath);
184+
PythonEngine.Shutdown();
185+
}
145186
}
146187
}

‎src/runtime/pythonengine.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ public static string PythonPath
9595
}
9696
set
9797
{
98+
if(Runtime.IsPython2)
99+
{
100+
thrownewNotSupportedException("Set PythonPath not supported on Python 2");
101+
}
98102
Marshal.FreeHGlobal(_pythonPath);
99103
_pythonPath=UcsMarshaler.Py3UnicodePy2StringtoPtr(value);
100104
Runtime.Py_SetPath(_pythonPath);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp