mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-26 10:50:12 +08:00
#29: refactor validator, now support custom defined validators
This commit is contained in:
@@ -4,10 +4,12 @@ Built-in dependent functions used in YAML/JSON testcases.
|
||||
|
||||
import datetime
|
||||
import random
|
||||
import re
|
||||
import string
|
||||
import time
|
||||
|
||||
from httprunner.exception import ParamsError
|
||||
from httprunner.utils import string_type
|
||||
|
||||
|
||||
def gen_random_string(str_len):
|
||||
@@ -33,3 +35,69 @@ def sleep(sec):
|
||||
""" sleep specified seconds
|
||||
"""
|
||||
time.sleep(sec)
|
||||
|
||||
|
||||
""" built-in comparators
|
||||
"""
|
||||
def equals(check_value, expect_value):
|
||||
assert check_value == expect_value
|
||||
|
||||
def less_than(check_value, expect_value):
|
||||
assert check_value < expect_value
|
||||
|
||||
def less_than_or_equals(check_value, expect_value):
|
||||
assert check_value <= expect_value
|
||||
|
||||
def greater_than(check_value, expect_value):
|
||||
assert check_value > expect_value
|
||||
|
||||
def greater_than_or_equals(check_value, expect_value):
|
||||
assert check_value >= expect_value
|
||||
|
||||
def not_equals(check_value, expect_value):
|
||||
assert check_value != expect_value
|
||||
|
||||
def string_equals(check_value, expect_value):
|
||||
assert str(check_value) == str(expect_value)
|
||||
|
||||
def length_equals(check_value, expect_value):
|
||||
assert isinstance(expect_value, int)
|
||||
assert len(check_value) == expect_value
|
||||
|
||||
def length_greater_than(check_value, expect_value):
|
||||
assert isinstance(expect_value, int)
|
||||
assert len(check_value) > expect_value
|
||||
|
||||
def length_greater_than_or_equals(check_value, expect_value):
|
||||
assert isinstance(expect_value, int)
|
||||
assert len(check_value) >= expect_value
|
||||
|
||||
def length_less_than(check_value, expect_value):
|
||||
assert isinstance(expect_value, int)
|
||||
assert len(check_value) < expect_value
|
||||
|
||||
def length_less_than_or_equals(check_value, expect_value):
|
||||
assert isinstance(expect_value, int)
|
||||
assert len(check_value) <= expect_value
|
||||
|
||||
def contains(check_value, expect_value):
|
||||
assert isinstance(check_value, (list, tuple, dict, string_type))
|
||||
assert expect_value in check_value
|
||||
|
||||
def contained_by(check_value, expect_value):
|
||||
assert isinstance(expect_value, (list, tuple, dict, string_type))
|
||||
assert check_value in expect_value
|
||||
|
||||
def type_match(check_value, expect_value):
|
||||
assert isinstance(check_value, expect_value)
|
||||
|
||||
def regex_match(check_value, expect_value):
|
||||
assert isinstance(expect_value, string_type)
|
||||
assert isinstance(check_value, string_type)
|
||||
assert re.match(expect_value, check_value)
|
||||
|
||||
def startswith(check_value, expect_value):
|
||||
assert str(check_value).startswith(str(expect_value))
|
||||
|
||||
def endswith(check_value, expect_value):
|
||||
assert str(check_value).endswith(str(expect_value))
|
||||
|
||||
Reference in New Issue
Block a user