| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -142,5 +142,46 @@ public void SetProgramName() | |||
| 142 | 142 | Assert.AreEqual(programName, PythonEngine.ProgramName); | |
| 143 | 143 | PythonEngine.Shutdown(); | |
| 144 | 144 | } | |
| 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 | + } | ||
| 145 | 186 | } | |
| 146 | 187 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -95,6 +95,10 @@ public static string PythonPath | |||
| 95 | 95 | } | |
| 96 | 96 | set | |
| 97 | 97 | { | |
| 98 | + if (Runtime.IsPython2) | ||
| 99 | + { | ||
| 100 | + throw new NotSupportedException("Set PythonPath not supported on Python 2"); | ||
| 101 | + } | ||
| 98 | 102 | Marshal.FreeHGlobal(_pythonPath); | |
| 99 | 103 | _pythonPath = UcsMarshaler.Py3UnicodePy2StringtoPtr(value); | |
| 100 | 104 | Runtime.Py_SetPath(_pythonPath); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments