Merge branch 'master' into dev

This commit is contained in:
debugtalk
2019-12-11 17:23:53 +08:00
2 changed files with 22 additions and 5 deletions

View File

@@ -37,27 +37,32 @@ def string_equals(check_value, expect_value):
def length_equals(check_value, expect_value):
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):
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):
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):
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):
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):
@@ -97,3 +102,10 @@ def startswith(check_value, expect_value):
def endswith(check_value, 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))

View File

@@ -80,6 +80,11 @@ class TestUtils(ApiServerUnittest):
functions_mapping["not_equals"](123, "123")
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_or_equals"]("123", 3)