make comparator classified

This commit is contained in:
httprunner
2017-08-03 23:56:05 +08:00
parent 5485b5a532
commit dfba8143ee
2 changed files with 40 additions and 33 deletions

View File

@@ -159,22 +159,6 @@ def match_expected(value, expected, comparator="eq", check_item=""):
if comparator in ["eq", "equals", "=="]:
assert value == expected
elif comparator in ["str_eq", "string_equals"]:
assert str(value) == str(expected)
elif comparator in ["ne", "not_equals"]:
assert value != expected
elif comparator in ["len_eq", "length_equal", "count_eq"]:
assert len(value) == expected
elif comparator in ["len_gt", "count_gt", "length_greater_than", "count_greater_than"]:
assert len(value) > expected
elif comparator in ["len_ge", "count_ge", "length_greater_than_or_equals", \
"count_greater_than_or_equals"]:
assert len(value) >= expected
elif comparator in ["len_lt", "count_lt", "length_less_than", "count_less_than"]:
assert len(value) < expected
elif comparator in ["len_le", "count_le", "length_less_than_or_equals", \
"count_less_than_or_equals"]:
assert len(value) <= expected
elif comparator in ["lt", "less_than"]:
assert value < expected
elif comparator in ["le", "less_than_or_equals"]:
@@ -183,16 +167,43 @@ def match_expected(value, expected, comparator="eq", check_item=""):
assert value > expected
elif comparator in ["ge", "greater_than_or_equals"]:
assert value >= expected
elif comparator in ["ne", "not_equals"]:
assert value != expected
elif comparator in ["str_eq", "string_equals"]:
assert str(value) == str(expected)
elif comparator in ["len_eq", "length_equals", "count_eq"]:
assert isinstance(expected, int)
assert len(value) == expected
elif comparator in ["len_gt", "count_gt", "length_greater_than", "count_greater_than"]:
assert isinstance(expected, int)
assert len(value) > expected
elif comparator in ["len_ge", "count_ge", "length_greater_than_or_equals", \
"count_greater_than_or_equals"]:
assert isinstance(expected, int)
assert len(value) >= expected
elif comparator in ["len_lt", "count_lt", "length_less_than", "count_less_than"]:
assert isinstance(expected, int)
assert len(value) < expected
elif comparator in ["len_le", "count_le", "length_less_than_or_equals", \
"count_less_than_or_equals"]:
assert isinstance(expected, int)
assert len(value) <= expected
elif comparator in ["contains"]:
assert isinstance(value, (list,tuple,dict,string_type))
assert expected in value
elif comparator in ["contained_by"]:
assert isinstance(expected, (list,tuple,dict,string_type))
assert value in expected
elif comparator in ["type"]:
assert isinstance(value, expected)
elif comparator in ["regex"]:
assert isinstance(expected, string_type)
assert isinstance(value, string_type)
assert re.match(expected, value)
elif comparator in ["str_len", "string_length"]:
assert len(value) == int(expected)
elif comparator in ["startswith"]:
assert str(value).startswith(str(expected))
elif comparator in ["endswith"]:
assert str(expected).startswith(str(value))
else:
raise exception.ParamsError("comparator not supported!")