mirror of
https://github.com/httprunner/httprunner.git
synced 2026-08-28 19:47:14 +08:00
change: remove support for Python 2.7
This commit is contained in:
@@ -4,8 +4,6 @@ Built-in validate comparators.
|
||||
|
||||
import re
|
||||
|
||||
from httprunner.compat import basestring, builtin_str, integer_types
|
||||
|
||||
|
||||
def equals(check_value, expect_value):
|
||||
assert check_value == expect_value
|
||||
@@ -32,46 +30,46 @@ def not_equals(check_value, expect_value):
|
||||
|
||||
|
||||
def string_equals(check_value, expect_value):
|
||||
assert builtin_str(check_value) == builtin_str(expect_value)
|
||||
assert str(check_value) == str(expect_value)
|
||||
|
||||
|
||||
def length_equals(check_value, expect_value):
|
||||
assert isinstance(expect_value, integer_types)
|
||||
assert isinstance(expect_value, int)
|
||||
expect_len = _cast_to_int(expect_value)
|
||||
assert len(check_value) == expect_len
|
||||
|
||||
|
||||
def length_greater_than(check_value, expect_value):
|
||||
assert isinstance(expect_value, integer_types)
|
||||
assert isinstance(expect_value, int)
|
||||
expect_len = _cast_to_int(expect_value)
|
||||
assert len(check_value) > expect_len
|
||||
|
||||
|
||||
def length_greater_than_or_equals(check_value, expect_value):
|
||||
assert isinstance(expect_value, integer_types)
|
||||
assert isinstance(expect_value, int)
|
||||
expect_len = _cast_to_int(expect_value)
|
||||
assert len(check_value) >= expect_len
|
||||
|
||||
|
||||
def length_less_than(check_value, expect_value):
|
||||
assert isinstance(expect_value, integer_types)
|
||||
assert isinstance(expect_value, int)
|
||||
expect_len = _cast_to_int(expect_value)
|
||||
assert len(check_value) < expect_len
|
||||
|
||||
|
||||
def length_less_than_or_equals(check_value, expect_value):
|
||||
assert isinstance(expect_value, integer_types)
|
||||
assert isinstance(expect_value, int)
|
||||
expect_len = _cast_to_int(expect_value)
|
||||
assert len(check_value) <= expect_len
|
||||
|
||||
|
||||
def contains(check_value, expect_value):
|
||||
assert isinstance(check_value, (list, tuple, dict, basestring))
|
||||
assert isinstance(check_value, (list, tuple, dict, str, bytes))
|
||||
assert expect_value in check_value
|
||||
|
||||
|
||||
def contained_by(check_value, expect_value):
|
||||
assert isinstance(expect_value, (list, tuple, dict, basestring))
|
||||
assert isinstance(expect_value, (list, tuple, dict, str, bytes))
|
||||
assert check_value in expect_value
|
||||
|
||||
|
||||
@@ -79,7 +77,7 @@ def type_match(check_value, expect_value):
|
||||
def get_type(name):
|
||||
if isinstance(name, type):
|
||||
return name
|
||||
elif isinstance(name, basestring):
|
||||
elif isinstance(name, str, bytes):
|
||||
try:
|
||||
return __builtins__[name]
|
||||
except KeyError:
|
||||
@@ -91,21 +89,21 @@ def type_match(check_value, expect_value):
|
||||
|
||||
|
||||
def regex_match(check_value, expect_value):
|
||||
assert isinstance(expect_value, basestring)
|
||||
assert isinstance(check_value, basestring)
|
||||
assert isinstance(expect_value, str)
|
||||
assert isinstance(check_value, str)
|
||||
assert re.match(expect_value, check_value)
|
||||
|
||||
|
||||
def startswith(check_value, expect_value):
|
||||
assert builtin_str(check_value).startswith(builtin_str(expect_value))
|
||||
assert str(check_value).startswith(str(expect_value))
|
||||
|
||||
|
||||
def endswith(check_value, expect_value):
|
||||
assert builtin_str(check_value).endswith(builtin_str(expect_value))
|
||||
assert str(check_value).endswith(str(expect_value))
|
||||
|
||||
|
||||
def _cast_to_int(expect_value):
|
||||
try:
|
||||
return int(expect_value)
|
||||
except Exception:
|
||||
raise AssertionError("%r can't cast to int" % str(expect_value))
|
||||
raise AssertionError("%r can't cast to int" % str(expect_value))
|
||||
|
||||
@@ -7,7 +7,6 @@ import random
|
||||
import string
|
||||
import time
|
||||
|
||||
from httprunner.compat import builtin_str, integer_types
|
||||
from httprunner.exceptions import ParamsError
|
||||
|
||||
|
||||
@@ -21,8 +20,8 @@ def gen_random_string(str_len):
|
||||
def get_timestamp(str_len=13):
|
||||
""" get timestamp string, length can only between 0 and 16
|
||||
"""
|
||||
if isinstance(str_len, integer_types) and 0 < str_len < 17:
|
||||
return builtin_str(time.time()).replace(".", "")[:str_len]
|
||||
if isinstance(str_len, int) and 0 < str_len < 17:
|
||||
return str(time.time()).replace(".", "")[:str_len]
|
||||
|
||||
raise ParamsError("timestamp length can only between 0 and 16.")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user