1
1
using System ;
2
+ using System . Diagnostics ;
2
3
using NUnit . Framework ;
3
4
using Python . Runtime ;
4
5
@@ -109,18 +110,41 @@ public static void GetPythonHomeDefault()
109
110
[ Test ]
110
111
public void SetPythonHome ( )
111
112
{
113
+ // We needs to ensure that engine was started and shutdown at least once before setting dummy home.
114
+ // Otherwise engine will not run with dummy path with random problem.
115
+ if ( ! PythonEngine . IsInitialized )
116
+ {
117
+ PythonEngine . Initialize ( ) ;
118
+ }
119
+
120
+ PythonEngine . Shutdown ( ) ;
121
+
122
+ var pythonHomeBackup = PythonEngine . PythonHome ;
123
+
112
124
var pythonHome = "/dummypath/" ;
113
125
114
126
PythonEngine . PythonHome = pythonHome ;
115
127
PythonEngine . Initialize ( ) ;
116
128
117
- Assert . AreEqual ( pythonHome , PythonEngine . PythonHome ) ;
118
129
PythonEngine . Shutdown ( ) ;
130
+
131
+ // Restoring valid pythonhome.
132
+ PythonEngine . PythonHome = pythonHomeBackup ;
119
133
}
120
134
121
135
[ Test ]
122
136
public void SetPythonHomeTwice ( )
123
137
{
138
+ // We needs to ensure that engine was started and shutdown at least once before setting dummy home.
139
+ // Otherwise engine will not run with dummy path with random problem.
140
+ if ( ! PythonEngine . IsInitialized )
141
+ {
142
+ PythonEngine . Initialize ( ) ;
143
+ }
144
+ PythonEngine . Shutdown ( ) ;
145
+
146
+ var pythonHomeBackup = PythonEngine . PythonHome ;
147
+
124
148
var pythonHome = "/dummypath/" ;
125
149
126
150
PythonEngine . PythonHome = "/dummypath2/" ;
@@ -129,18 +153,29 @@ public void SetPythonHomeTwice()
129
153
130
154
Assert . AreEqual ( pythonHome , PythonEngine . PythonHome ) ;
131
155
PythonEngine . Shutdown ( ) ;
156
+
157
+ PythonEngine . PythonHome = pythonHomeBackup ;
132
158
}
133
159
134
160
[ Test ]
135
161
public void SetProgramName ( )
136
162
{
163
+ if ( PythonEngine . IsInitialized )
164
+ {
165
+ PythonEngine . Shutdown ( ) ;
166
+ }
167
+
168
+ var programNameBackup = PythonEngine . ProgramName ;
169
+
137
170
var programName = "FooBar" ;
138
171
139
172
PythonEngine . ProgramName = programName ;
140
173
PythonEngine . Initialize ( ) ;
141
174
142
175
Assert . AreEqual ( programName , PythonEngine . ProgramName ) ;
143
176
PythonEngine . Shutdown ( ) ;
177
+
178
+ PythonEngine . ProgramName = programNameBackup ;
144
179
}
145
180
146
181
[ Test ]
@@ -156,7 +191,7 @@ public void SetPythonPath()
156
191
string path = PythonEngine . PythonPath ;
157
192
PythonEngine . Shutdown ( ) ;
158
193
159
- PythonEngine . ProgramName = path ;
194
+ PythonEngine . PythonPath = path ;
160
195
PythonEngine . Initialize ( ) ;
161
196
162
197
Assert . AreEqual ( path , PythonEngine . PythonPath ) ;
@@ -171,7 +206,6 @@ public void SetPythonPathExceptionOn27()
171
206
Assert . Pass ( ) ;
172
207
}
173
208
174
- // Get previous path to avoid crashing Python
175
209
PythonEngine . Initialize ( ) ;
176
210
string path = PythonEngine . PythonPath ;
177
211
PythonEngine . Shutdown ( ) ;
0 commit comments