19
19
from urllib .error import URLError
20
20
21
21
use_file = False
22
+ TestingOpenTreeClass = OpenTreeService ()
23
+ TestingOpenTreeClass .is_testing_mode = True
24
+
22
25
23
26
def exec_and_return_locals (statement , locals_dict = None ):
24
27
"""
@@ -146,7 +149,7 @@ def construct_arguments(self,data):
146
149
arguments = arguments + arg + "=" + arg_val + ","
147
150
i += 1
148
151
149
- return 'response = opentreeservice .' + data ['test_function' ]+ '(' + arguments + ')'
152
+ return 'response = TestingOpenTreeClass .' + data ['test_function' ]+ '(' + arguments + ')'
150
153
151
154
# This is the function that does the heavy lifting
152
155
def run_tests (self , data ):
@@ -155,16 +158,16 @@ def run_tests(self, data):
155
158
print ("\t Running test: " + key )
156
159
try :
157
160
if (data [key ]['test_input' ] == {}):
158
- response = exec_and_return_locals ('response = opentreeservice .' + data [key ]['test_function' ]+ '()' , locals ())["response" ]
161
+ response = exec_and_return_locals ('response = TestingOpenTreeClass .' + data [key ]['test_function' ]+ '()' , locals ())["response" ]
159
162
else :
160
163
args = self .construct_arguments (data [key ])
161
164
response = exec_and_return_locals (args , locals ())["response" ]
162
165
except :
163
- if "error " in data [key ]['tests' ]:
164
- for sub_test in data [key ]['tests' ]['error ' ]:
166
+ if "parameters_error " in data [key ]['tests' ]:
167
+ for sub_test in data [key ]['tests' ]['parameters_error ' ]:
165
168
with self .assertRaises (eval (sub_test [0 ])):
166
169
if (data [key ]['test_input' ] == {}):
167
- response = exec_and_return_locals ('response = opentreeservice .' + data [key ]['test_function' ]+ '()' , locals ())['response' ]
170
+ response = exec_and_return_locals ('response = TestingOpenTreeClass .' + data [key ]['test_function' ]+ '()' , locals ())['response' ]
168
171
else :
169
172
args = self .construct_arguments (data [key ])
170
173
response = exec_and_return_locals (args , locals ())["response" ]
@@ -200,9 +203,12 @@ def run_tests(self, data):
200
203
elif test == 'length_less_than' :
201
204
for sub_test in data [key ]['tests' ][test ]:
202
205
self .assertTrue (eval ("len(response['" + sub_test [0 ][0 ]+ "'])" ) < sub_test [0 ][1 ], key + ": " + sub_test [1 ] + " len " + str (eval ("len(response['" + sub_test [0 ][0 ]+ "'])" )))
203
- elif test == "error " :
206
+ elif test == "parameters_error " :
204
207
continue
205
208
# dealt with above!
209
+ elif test == "contains_error" :
210
+ for sub_test in data [key ]['tests' ][test ]:
211
+ self .assert_ ("error" in response , key + ": " + sub_test [0 ])
206
212
else :
207
213
print ("\t \t " + bcolors .FAIL + "Oh oh. I didn't know how to deal with test type: " + test + bcolors .ENDC )
208
214
0 commit comments