mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 23:51:25 +08:00
optimize exception type
This commit is contained in:
+5
-8
@@ -7,7 +7,7 @@ import re
|
|||||||
import string
|
import string
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
from ate.exception import ParamsError
|
from ate import exception
|
||||||
|
|
||||||
try:
|
try:
|
||||||
string_type = basestring
|
string_type = basestring
|
||||||
@@ -47,7 +47,7 @@ def load_testcases(testcase_file_path):
|
|||||||
return load_yaml_file(testcase_file_path)
|
return load_yaml_file(testcase_file_path)
|
||||||
else:
|
else:
|
||||||
# '' or other suffix
|
# '' or other suffix
|
||||||
raise ParamsError("Bad testcase file name!")
|
return []
|
||||||
|
|
||||||
def load_foler_files(folder_path):
|
def load_foler_files(folder_path):
|
||||||
""" load folder path, return all files in list format.
|
""" load folder path, return all files in list format.
|
||||||
@@ -96,10 +96,7 @@ def load_testcases_by_path(path):
|
|||||||
"config": {},
|
"config": {},
|
||||||
"testcases": []
|
"testcases": []
|
||||||
}
|
}
|
||||||
try:
|
testcases_list = load_testcases(path)
|
||||||
testcases_list = load_testcases(path)
|
|
||||||
except ParamsError:
|
|
||||||
return []
|
|
||||||
|
|
||||||
for item in testcases_list:
|
for item in testcases_list:
|
||||||
for key in item:
|
for key in item:
|
||||||
@@ -143,7 +140,7 @@ def query_json(json_content, query, delimiter='.'):
|
|||||||
key = int(key)
|
key = int(key)
|
||||||
json_content = json_content[key]
|
json_content = json_content[key]
|
||||||
except (KeyError, ValueError, IndexError):
|
except (KeyError, ValueError, IndexError):
|
||||||
raise ParamsError("invalid query string in extract_binds!")
|
raise exception.ParseResponseError("failed to query json when extracting response!")
|
||||||
|
|
||||||
return json_content
|
return json_content
|
||||||
|
|
||||||
@@ -191,7 +188,7 @@ def match_expected(value, expected, comparator="eq"):
|
|||||||
elif comparator in ["startswith"]:
|
elif comparator in ["startswith"]:
|
||||||
assert str(value).startswith(str(expected))
|
assert str(value).startswith(str(expected))
|
||||||
else:
|
else:
|
||||||
raise ParamsError("comparator not supported!")
|
raise exception.ParamsError("comparator not supported!")
|
||||||
|
|
||||||
return True
|
return True
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ class TestResponse(ApiServerUnittest):
|
|||||||
]
|
]
|
||||||
resp_obj = response.ResponseObject(resp)
|
resp_obj = response.ResponseObject(resp)
|
||||||
|
|
||||||
with self.assertRaises(exception.ParamsError):
|
with self.assertRaises(exception.ParseResponseError):
|
||||||
resp_obj.extract_response(extract_binds_list)
|
resp_obj.extract_response(extract_binds_list)
|
||||||
|
|
||||||
extract_binds_list = [
|
extract_binds_list = [
|
||||||
@@ -124,7 +124,7 @@ class TestResponse(ApiServerUnittest):
|
|||||||
]
|
]
|
||||||
resp_obj = response.ResponseObject(resp)
|
resp_obj = response.ResponseObject(resp)
|
||||||
|
|
||||||
with self.assertRaises(exception.ParamsError):
|
with self.assertRaises(exception.ParseResponseError):
|
||||||
resp_obj.extract_response(extract_binds_list)
|
resp_obj.extract_response(extract_binds_list)
|
||||||
|
|
||||||
def test_extract_response_json_string(self):
|
def test_extract_response_json_string(self):
|
||||||
|
|||||||
+4
-5
@@ -7,8 +7,7 @@ class TestUtils(ApiServerUnittest):
|
|||||||
|
|
||||||
def test_load_testcases_bad_filepath(self):
|
def test_load_testcases_bad_filepath(self):
|
||||||
testcase_file_path = os.path.join(os.getcwd(), 'tests/data/demo')
|
testcase_file_path = os.path.join(os.getcwd(), 'tests/data/demo')
|
||||||
with self.assertRaises(exception.ParamsError):
|
self.assertEqual(utils.load_testcases(testcase_file_path), [])
|
||||||
utils.load_testcases(testcase_file_path)
|
|
||||||
|
|
||||||
def test_load_json_testcases(self):
|
def test_load_json_testcases(self):
|
||||||
testcase_file_path = os.path.join(
|
testcase_file_path = os.path.join(
|
||||||
@@ -132,11 +131,11 @@ class TestUtils(ApiServerUnittest):
|
|||||||
self.assertEqual(result, 3)
|
self.assertEqual(result, 3)
|
||||||
|
|
||||||
query = "ids.str_key"
|
query = "ids.str_key"
|
||||||
with self.assertRaises(exception.ParamsError):
|
with self.assertRaises(exception.ParseResponseError):
|
||||||
utils.query_json(json_content, query)
|
utils.query_json(json_content, query)
|
||||||
|
|
||||||
query = "ids.5"
|
query = "ids.5"
|
||||||
with self.assertRaises(exception.ParamsError):
|
with self.assertRaises(exception.ParseResponseError):
|
||||||
utils.query_json(json_content, query)
|
utils.query_json(json_content, query)
|
||||||
|
|
||||||
query = "person.age"
|
query = "person.age"
|
||||||
@@ -144,7 +143,7 @@ class TestUtils(ApiServerUnittest):
|
|||||||
self.assertEqual(result, 29)
|
self.assertEqual(result, 29)
|
||||||
|
|
||||||
query = "person.not_exist_key"
|
query = "person.not_exist_key"
|
||||||
with self.assertRaises(exception.ParamsError):
|
with self.assertRaises(exception.ParseResponseError):
|
||||||
utils.query_json(json_content, query)
|
utils.query_json(json_content, query)
|
||||||
|
|
||||||
query = "person.cities.0"
|
query = "person.cities.0"
|
||||||
|
|||||||
Reference in New Issue
Block a user