mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-08 17:29:34 +08:00
bug fix: 当使用.csv文件内容来做数据驱动测试时, length_xxx函数都会失败
This commit is contained in:
@@ -37,27 +37,32 @@ def string_equals(check_value, expect_value):
|
|||||||
|
|
||||||
def length_equals(check_value, expect_value):
|
def length_equals(check_value, expect_value):
|
||||||
assert isinstance(expect_value, integer_types)
|
assert isinstance(expect_value, integer_types)
|
||||||
assert len(check_value) == expect_value
|
expect_len = _cast_to_int(expect_value)
|
||||||
|
assert len(check_value) == expect_len
|
||||||
|
|
||||||
|
|
||||||
def length_greater_than(check_value, expect_value):
|
def length_greater_than(check_value, expect_value):
|
||||||
assert isinstance(expect_value, integer_types)
|
assert isinstance(expect_value, integer_types)
|
||||||
assert len(check_value) > expect_value
|
expect_len = _cast_to_int(expect_value)
|
||||||
|
assert len(check_value) > expect_len
|
||||||
|
|
||||||
|
|
||||||
def length_greater_than_or_equals(check_value, expect_value):
|
def length_greater_than_or_equals(check_value, expect_value):
|
||||||
assert isinstance(expect_value, integer_types)
|
assert isinstance(expect_value, integer_types)
|
||||||
assert len(check_value) >= expect_value
|
expect_len = _cast_to_int(expect_value)
|
||||||
|
assert len(check_value) >= expect_len
|
||||||
|
|
||||||
|
|
||||||
def length_less_than(check_value, expect_value):
|
def length_less_than(check_value, expect_value):
|
||||||
assert isinstance(expect_value, integer_types)
|
assert isinstance(expect_value, integer_types)
|
||||||
assert len(check_value) < expect_value
|
expect_len = _cast_to_int(expect_value)
|
||||||
|
assert len(check_value) < expect_len
|
||||||
|
|
||||||
|
|
||||||
def length_less_than_or_equals(check_value, expect_value):
|
def length_less_than_or_equals(check_value, expect_value):
|
||||||
assert isinstance(expect_value, integer_types)
|
assert isinstance(expect_value, integer_types)
|
||||||
assert len(check_value) <= expect_value
|
expect_len = _cast_to_int(expect_value)
|
||||||
|
assert len(check_value) <= expect_len
|
||||||
|
|
||||||
|
|
||||||
def contains(check_value, expect_value):
|
def contains(check_value, expect_value):
|
||||||
@@ -97,3 +102,10 @@ def startswith(check_value, expect_value):
|
|||||||
|
|
||||||
def endswith(check_value, expect_value):
|
def endswith(check_value, expect_value):
|
||||||
assert builtin_str(check_value).endswith(builtin_str(expect_value))
|
assert builtin_str(check_value).endswith(builtin_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))
|
||||||
@@ -80,6 +80,11 @@ class TestUtils(ApiServerUnittest):
|
|||||||
functions_mapping["not_equals"](123, "123")
|
functions_mapping["not_equals"](123, "123")
|
||||||
|
|
||||||
functions_mapping["length_equals"]("123", 3)
|
functions_mapping["length_equals"]("123", 3)
|
||||||
|
# Because the Numbers in a CSV file are by default treated as strings,
|
||||||
|
# you need to convert them to Numbers, and we'll test that out here.
|
||||||
|
functions_mapping["length_equals"]("123", '3')
|
||||||
|
with self.assertRaises(AssertionError):
|
||||||
|
functions_mapping["length_equals"]("123", 'abc')
|
||||||
functions_mapping["length_greater_than"]("123", 2)
|
functions_mapping["length_greater_than"]("123", 2)
|
||||||
functions_mapping["length_greater_than_or_equals"]("123", 3)
|
functions_mapping["length_greater_than_or_equals"]("123", 3)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user