@@ -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- public void SetPythonHome ( )
103- {
104- PythonEngine . Initialize ( ) ;
105- var pythonHomeBackup = PythonEngine . PythonHome ;
106- PythonEngine . Shutdown ( ) ;
107-
108- if ( pythonHomeBackup == "" )
109- Assert . Inconclusive ( "Can't reset PythonHome to empty string, skipping" ) ;
110-
111- var pythonHome = "/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- public void SetPythonHomeTwice ( )
126- {
127- PythonEngine . Initialize ( ) ;
128- var pythonHomeBackup = PythonEngine . PythonHome ;
129- PythonEngine . Shutdown ( ) ;
130-
131- if ( pythonHomeBackup == "" )
132- Assert . Inconclusive ( "Can't reset PythonHome to empty string, skipping" ) ;
133-
134- var pythonHome = "/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- public void SetPythonHomeEmptyString ( )
149- {
150- PythonEngine . Initialize ( ) ;
151-
152- var backup = 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- public void SetProgramName ( )
169- {
170- if ( PythonEngine . IsInitialized )
171- {
172- PythonEngine . Shutdown ( ) ;
173- }
174-
175- var programNameBackup = PythonEngine . ProgramName ;
176-
177- var programName = "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- public void SetPythonPath ( )
191- {
192- PythonEngine . Initialize ( ) ;
193-
194- const string moduleName = "pytest" ;
195- bool importShouldSucceed ;
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- string path = 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