mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 07:26:55 +08:00
bugfix: comparison with None should raise exception in Python 2.7
This commit is contained in:
@@ -152,6 +152,11 @@ def match_expected(value, expected, comparator="eq", check_item=""):
|
|||||||
@param check_item: check item name
|
@param check_item: check item name
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
|
if value is None or expected is None:
|
||||||
|
assert comparator in ["is", "eq", "equals", "=="]
|
||||||
|
assert value is None
|
||||||
|
assert expected is None
|
||||||
|
|
||||||
if comparator in ["eq", "equals", "=="]:
|
if comparator in ["eq", "equals", "=="]:
|
||||||
assert value == expected
|
assert value == expected
|
||||||
elif comparator in ["str_eq", "string_equals"]:
|
elif comparator in ["str_eq", "string_equals"]:
|
||||||
|
|||||||
+1
-1
@@ -196,9 +196,9 @@ class TestUtils(ApiServerUnittest):
|
|||||||
self.assertTrue(utils.match_expected("123abc", 12, "startswith"))
|
self.assertTrue(utils.match_expected("123abc", 12, "startswith"))
|
||||||
self.assertTrue(utils.match_expected(12345, 123, "startswith"))
|
self.assertTrue(utils.match_expected(12345, 123, "startswith"))
|
||||||
|
|
||||||
|
self.assertTrue(utils.match_expected(None, None, "eq"))
|
||||||
with self.assertRaises(exception.ValidationError):
|
with self.assertRaises(exception.ValidationError):
|
||||||
utils.match_expected(None, 3, "len_eq")
|
utils.match_expected(None, 3, "len_eq")
|
||||||
|
|
||||||
with self.assertRaises(exception.ValidationError):
|
with self.assertRaises(exception.ValidationError):
|
||||||
utils.match_expected("abc", None, "gt")
|
utils.match_expected("abc", None, "gt")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user