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