bugfix: TypeError in match_expected

This commit is contained in:
debugtalk
2017-08-02 15:21:37 +08:00
parent 57b1f35e4d
commit 14e744c962
2 changed files with 8 additions and 1 deletions

View File

@@ -192,7 +192,8 @@ def match_expected(value, expected, comparator="eq", check_item=""):
raise exception.ParamsError("comparator not supported!")
return True
except AssertionError:
except (AssertionError, TypeError):
err_msg = "\n".join([
"check item name: %s;" % check_item,
"check item value: %s (%s);" % (value, type(value).__name__),

View File

@@ -196,6 +196,12 @@ class TestUtils(ApiServerUnittest):
self.assertTrue(utils.match_expected("123abc", 12, "startswith"))
self.assertTrue(utils.match_expected(12345, 123, "startswith"))
with self.assertRaises(exception.ValidationError):
utils.match_expected(None, 3, "len_eq")
with self.assertRaises(exception.ValidationError):
utils.match_expected("abc", None, "gt")
def test_deep_update_dict(self):
origin_dict = {'a': 1, 'b': {'c': 3, 'd': 4}, 'f': 6}
override_dict = {'a': 2, 'b': {'c': 33, 'e': 5}, 'g': 7}