mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 23:51:25 +08:00
convert docstring to Google style
This commit is contained in:
+12
-6
@@ -58,21 +58,27 @@ def load_json_file(json_file):
|
|||||||
|
|
||||||
def load_csv_file(csv_file):
|
def load_csv_file(csv_file):
|
||||||
""" load csv file and check file content format
|
""" load csv file and check file content format
|
||||||
@param
|
|
||||||
csv_file: csv file path
|
Args:
|
||||||
e.g. csv file content:
|
csv_file (str): csv file path, csv file content is like below:
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list: list of parameters, each parameter is in dict format
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
>>> cat csv_file
|
||||||
username,password
|
username,password
|
||||||
test1,111111
|
test1,111111
|
||||||
test2,222222
|
test2,222222
|
||||||
test3,333333
|
test3,333333
|
||||||
@return
|
|
||||||
list of parameter, each parameter is in dict format
|
>>> load_csv_file(csv_file)
|
||||||
e.g.
|
|
||||||
[
|
[
|
||||||
{'username': 'test1', 'password': '111111'},
|
{'username': 'test1', 'password': '111111'},
|
||||||
{'username': 'test2', 'password': '222222'},
|
{'username': 'test2', 'password': '222222'},
|
||||||
{'username': 'test3', 'password': '333333'}
|
{'username': 'test3', 'password': '333333'}
|
||||||
]
|
]
|
||||||
|
|
||||||
"""
|
"""
|
||||||
csv_content_list = []
|
csv_content_list = []
|
||||||
|
|
||||||
|
|||||||
+10
-3
@@ -150,20 +150,27 @@ def parse_function(content):
|
|||||||
|
|
||||||
|
|
||||||
def parse_validator(validator):
|
def parse_validator(validator):
|
||||||
""" parse validator, validator maybe in two format
|
""" parse validator
|
||||||
@param (dict) validator
|
|
||||||
|
Args:
|
||||||
|
validator (dict): validator maybe in two formats:
|
||||||
|
|
||||||
format1: this is kept for compatiblity with the previous versions.
|
format1: this is kept for compatiblity with the previous versions.
|
||||||
{"check": "status_code", "comparator": "eq", "expect": 201}
|
{"check": "status_code", "comparator": "eq", "expect": 201}
|
||||||
{"check": "$resp_body_success", "comparator": "eq", "expect": True}
|
{"check": "$resp_body_success", "comparator": "eq", "expect": True}
|
||||||
format2: recommended new version
|
format2: recommended new version
|
||||||
{'eq': ['status_code', 201]}
|
{'eq': ['status_code', 201]}
|
||||||
{'eq': ['$resp_body_success', True]}
|
{'eq': ['$resp_body_success', True]}
|
||||||
@return (dict) validator info
|
|
||||||
|
Returns
|
||||||
|
dict: validator info
|
||||||
|
|
||||||
{
|
{
|
||||||
"check": "status_code",
|
"check": "status_code",
|
||||||
"expect": 201,
|
"expect": 201,
|
||||||
"comparator": "eq"
|
"comparator": "eq"
|
||||||
}
|
}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not isinstance(validator, dict):
|
if not isinstance(validator, dict):
|
||||||
raise exceptions.ParamsError("invalid validator: {}".format(validator))
|
raise exceptions.ParamsError("invalid validator: {}".format(validator))
|
||||||
|
|||||||
+32
-9
@@ -15,7 +15,10 @@ class ResponseObject(object):
|
|||||||
|
|
||||||
def __init__(self, resp_obj):
|
def __init__(self, resp_obj):
|
||||||
""" initialize with a requests.Response object
|
""" initialize with a requests.Response object
|
||||||
@param (requests.Response instance) resp_obj
|
|
||||||
|
Args:
|
||||||
|
resp_obj (instance): requests.Response instance
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self.resp_obj = resp_obj
|
self.resp_obj = resp_obj
|
||||||
|
|
||||||
@@ -36,11 +39,22 @@ class ResponseObject(object):
|
|||||||
def _extract_field_with_regex(self, field):
|
def _extract_field_with_regex(self, field):
|
||||||
""" extract field from response content with regex.
|
""" extract field from response content with regex.
|
||||||
requests.Response body could be json or html text.
|
requests.Response body could be json or html text.
|
||||||
@param (str) field should only be regex string that matched r".*\(.*\).*"
|
|
||||||
e.g.
|
Args:
|
||||||
self.text: "LB123abcRB789"
|
field (str): regex string that matched r".*\(.*\).*"
|
||||||
field: "LB[\d]*(.*)RB[\d]*"
|
|
||||||
return: abc
|
Returns:
|
||||||
|
str: matched content.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
exceptions.ExtractFailure: If no content matched with regex.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
>>> # self.text: "LB123abcRB789"
|
||||||
|
>>> filed = "LB[\d]*(.*)RB[\d]*"
|
||||||
|
>>> _extract_field_with_regex(field)
|
||||||
|
abc
|
||||||
|
|
||||||
"""
|
"""
|
||||||
matched = re.search(field, self.text)
|
matched = re.search(field, self.text)
|
||||||
if not matched:
|
if not matched:
|
||||||
@@ -53,7 +67,9 @@ class ResponseObject(object):
|
|||||||
|
|
||||||
def _extract_field_with_delimiter(self, field):
|
def _extract_field_with_delimiter(self, field):
|
||||||
""" response content could be json or html text.
|
""" response content could be json or html text.
|
||||||
@param (str) field should be string joined by delimiter.
|
|
||||||
|
Args:
|
||||||
|
field (str): string joined by delimiter.
|
||||||
e.g.
|
e.g.
|
||||||
"status_code"
|
"status_code"
|
||||||
"headers"
|
"headers"
|
||||||
@@ -61,6 +77,7 @@ class ResponseObject(object):
|
|||||||
"content"
|
"content"
|
||||||
"headers.content-type"
|
"headers.content-type"
|
||||||
"content.person.name.first_name"
|
"content.person.name.first_name"
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# string.split(sep=None, maxsplit=-1) -> list of strings
|
# string.split(sep=None, maxsplit=-1) -> list of strings
|
||||||
# e.g. "content.person.name" => ["content", "person.name"]
|
# e.g. "content.person.name" => ["content", "person.name"]
|
||||||
@@ -207,14 +224,20 @@ class ResponseObject(object):
|
|||||||
|
|
||||||
def extract_response(self, extractors):
|
def extract_response(self, extractors):
|
||||||
""" extract value from requests.Response and store in OrderedDict.
|
""" extract value from requests.Response and store in OrderedDict.
|
||||||
@param (list) extractors
|
|
||||||
|
Args:
|
||||||
|
extractors (list):
|
||||||
|
|
||||||
[
|
[
|
||||||
{"resp_status_code": "status_code"},
|
{"resp_status_code": "status_code"},
|
||||||
{"resp_headers_content_type": "headers.content-type"},
|
{"resp_headers_content_type": "headers.content-type"},
|
||||||
{"resp_content": "content"},
|
{"resp_content": "content"},
|
||||||
{"resp_content_person_first_name": "content.person.name.first_name"}
|
{"resp_content_person_first_name": "content.person.name.first_name"}
|
||||||
]
|
]
|
||||||
@return (OrderDict) variable binds ordered dict
|
|
||||||
|
Returns:
|
||||||
|
OrderDict: variable binds ordered dict
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not extractors:
|
if not extractors:
|
||||||
return {}
|
return {}
|
||||||
|
|||||||
+37
-16
@@ -64,8 +64,17 @@ def build_url(base_url, path):
|
|||||||
|
|
||||||
def query_json(json_content, query, delimiter='.'):
|
def query_json(json_content, query, delimiter='.'):
|
||||||
""" Do an xpath-like query with json_content.
|
""" Do an xpath-like query with json_content.
|
||||||
@param (dict/list/string) json_content
|
|
||||||
json_content = {
|
Args:
|
||||||
|
json_content (dict/list/string): content to be queried.
|
||||||
|
query (str): query string.
|
||||||
|
delimiter (str): delimiter symbol.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: queried result.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
>>> json_content = {
|
||||||
"ids": [1, 2, 3, 4],
|
"ids": [1, 2, 3, 4],
|
||||||
"person": {
|
"person": {
|
||||||
"name": {
|
"name": {
|
||||||
@@ -76,11 +85,16 @@ def query_json(json_content, query, delimiter='.'):
|
|||||||
"cities": ["Guangzhou", "Shenzhen"]
|
"cities": ["Guangzhou", "Shenzhen"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@param (str) query
|
>>>
|
||||||
"person.name.first_name" => "Leo"
|
>>> query_json(json_content, "person.name.first_name")
|
||||||
"person.name.first_name.0" => "L"
|
>>> Leo
|
||||||
"person.cities.0" => "Guangzhou"
|
>>>
|
||||||
@return queried result
|
>>> query_json(json_content, "person.name.first_name.0")
|
||||||
|
>>> L
|
||||||
|
>>>
|
||||||
|
>>> query_json(json_content, "person.cities.0")
|
||||||
|
>>> Guangzhou
|
||||||
|
|
||||||
"""
|
"""
|
||||||
raise_flag = False
|
raise_flag = False
|
||||||
response_body = u"response body: {}\n".format(json_content)
|
response_body = u"response body: {}\n".format(json_content)
|
||||||
@@ -505,21 +519,28 @@ def create_scaffold(project_name):
|
|||||||
|
|
||||||
def gen_cartesian_product(*args):
|
def gen_cartesian_product(*args):
|
||||||
""" generate cartesian product for lists
|
""" generate cartesian product for lists
|
||||||
@param
|
|
||||||
(list) args
|
Args:
|
||||||
[{"a": 1}, {"a": 2}],
|
args (list of list): lists to be generated with cartesian product
|
||||||
[
|
|
||||||
{"x": 111, "y": 112},
|
Returns:
|
||||||
{"x": 121, "y": 122}
|
list: cartesian product in list
|
||||||
]
|
|
||||||
@return
|
Examples:
|
||||||
cartesian product in list
|
|
||||||
|
>>> arg1 = [{"a": 1}, {"a": 2}]
|
||||||
|
>>> arg2 = [{"x": 111, "y": 112}, {"x": 121, "y": 122}]
|
||||||
|
>>> args = [arg1, arg2]
|
||||||
|
>>> gen_cartesian_product(*args)
|
||||||
|
>>> # same as below
|
||||||
|
>>> gen_cartesian_product(arg1, arg2)
|
||||||
[
|
[
|
||||||
{'a': 1, 'x': 111, 'y': 112},
|
{'a': 1, 'x': 111, 'y': 112},
|
||||||
{'a': 1, 'x': 121, 'y': 122},
|
{'a': 1, 'x': 121, 'y': 122},
|
||||||
{'a': 2, 'x': 111, 'y': 112},
|
{'a': 2, 'x': 111, 'y': 112},
|
||||||
{'a': 2, 'x': 121, 'y': 122}
|
{'a': 2, 'x': 121, 'y': 122}
|
||||||
]
|
]
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not args:
|
if not args:
|
||||||
return []
|
return []
|
||||||
|
|||||||
Reference in New Issue
Block a user