Skip to content

Commit 4fb0a4c

Browse files
committed
Merge branch 'master' of github.com:OpenTreeOfLife/pyopentree
2 parents 2687043 + 9c4006f commit 4fb0a4c

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

test/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
#
77

88
PYTHON="python"
9-
LEGACY_PYTHON = $(shell $(PYTHON) -c 'import sys; print(sys.hexversion < 0x2070000)')
9+
LEGACY_PYTHON = $(shell $(PYTHON) -c 'import sys; print(sys.hexversion < 0x03000000)')
1010
ifeq ($(LEGACY_PYTHON),True)
11-
UNIT_TESTS = _api_level_1.py26_and_below.py
11+
UNIT_TESTS = _api_level_1_py26_and_below.py
1212
else
1313
UNIT_TESTS = _api_level_1.py
1414
endif

test/_api_level_1.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
from urllib.error import URLError
2020

2121
use_file = False
22+
TestingOpenTreeClass = OpenTreeService()
23+
TestingOpenTreeClass.is_testing_mode = True
24+
2225

2326
def exec_and_return_locals(statement, locals_dict=None):
2427
"""
@@ -146,7 +149,7 @@ def construct_arguments(self,data):
146149
arguments = arguments + arg + "=" + arg_val + ","
147150
i += 1
148151

149-
return 'response = opentreeservice.'+data['test_function']+'('+arguments+')'
152+
return 'response = TestingOpenTreeClass.'+data['test_function']+'('+arguments+')'
150153

151154
# This is the function that does the heavy lifting
152155
def run_tests(self, data):
@@ -155,16 +158,16 @@ def run_tests(self, data):
155158
print("\tRunning test: "+key)
156159
try:
157160
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"]
159162
else:
160163
args = self.construct_arguments(data[key])
161164
response = exec_and_return_locals(args, locals())["response"]
162165
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']:
165168
with self.assertRaises(eval(sub_test[0])):
166169
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']
168171
else:
169172
args = self.construct_arguments(data[key])
170173
response = exec_and_return_locals(args, locals())["response"]
@@ -200,9 +203,12 @@ def run_tests(self, data):
200203
elif test == 'length_less_than':
201204
for sub_test in data[key]['tests'][test]:
202205
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":
204207
continue
205208
# 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])
206212
else:
207213
print("\t\t" + bcolors.FAIL + "Oh oh. I didn't know how to deal with test type: " + test + bcolors.ENDC)
208214

test/_api_level_1_py26_and_below.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
from urllib2 import URLError, HTTPError
1212

1313
use_file = False
14+
TestingOpenTreeClass = OpenTreeService()
15+
TestingOpenTreeClass.is_testing_mode = True
1416

1517
class bcolors:
1618
HEADER = '\033[95m'
@@ -127,7 +129,7 @@ def construct_arguments(self,data):
127129
arguments = arguments + arg + "=" + arg_val + ","
128130
i += 1
129131

130-
return 'response = opentreeservice.'+data['test_function']+'('+arguments+')'
132+
return 'response = TestingOpenTreeClass.'+data['test_function']+'('+arguments+')'
131133

132134
# This is the function that does the heavy lifting
133135
def run_tests(self, data):
@@ -136,16 +138,16 @@ def run_tests(self, data):
136138
print "\tRunning test: "+key
137139
try:
138140
if (data[key]['test_input'] == {}):
139-
exec('response = opentreeservice.'+data[key]['test_function']+'()')
141+
exec('response = TestingOpenTreeClass.'+data[key]['test_function']+'()')
140142
else:
141143
args = self.construct_arguments(data[key])
142144
exec(args)
143145
except:
144-
if "error" in data[key]['tests']:
145-
for sub_test in data[key]['tests']['error']:
146+
if "parameters_error" in data[key]['tests']:
147+
for sub_test in data[key]['tests']['parameters_error']:
146148
with self.assertRaises(eval(sub_test[0])):
147149
if (data[key]['test_input'] == {}):
148-
exec('response = opentreeservice.'+data[key]['test_function']+'()')
150+
exec('response = TestingOpenTreeClass.'+data[key]['test_function']+'()')
149151
else:
150152
args = self.construct_arguments(data[key])
151153
exec(args)
@@ -181,9 +183,12 @@ def run_tests(self, data):
181183
elif test == 'length_less_than':
182184
for sub_test in data[key]['tests'][test]:
183185
self.assert_(eval("len(response['"+sub_test[0][0]+"'])") < sub_test[0][1], key+": "+sub_test[1] + " len "+str(eval("len(response['"+sub_test[0][0]+"'])")))
184-
elif test == "error":
186+
elif test == "parameters_error":
185187
continue
186188
# dealt with above!
189+
elif test == "contains_error":
190+
for sub_test in data[key]['tests'][test]:
191+
self.assert_("error" in response, key+": "+sub_test[0])
187192
else:
188193
print "\t\t" + bcolors.FAIL + "Oh oh. I didn't know how to deal with test type: " + test + bcolors.ENDC
189194

0 commit comments

Comments
 (0)