8000 Fix Py_SetPath not available in PY2 · Unity-Technologies/pythonnet@7db41a9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7db41a9

Browse files
committed
Fix Py_SetPath not available in PY2
Closes pythonnet#418
1 parent 6d08374 commit 7db41a9

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+
public void SetPythonPath()
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+
string path = 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+
public void SetPythonPathExceptionOn27()
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+
string path = PythonEngine.PythonPath;
177+
PythonEngine.Shutdown();
178+
179+
var ex = 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+
throw new NotSupportedException("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)
0