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