From 14e744c96242b70bf265b16b8a3c3962774719f9 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Wed, 2 Aug 2017 15:21:37 +0800 Subject: [PATCH] bugfix: TypeError in match_expected --- ate/utils.py | 3 ++- tests/test_utils.py | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ate/utils.py b/ate/utils.py index 432b8a6e..07f522ca 100644 --- a/ate/utils.py +++ b/ate/utils.py @@ -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__), diff --git a/tests/test_utils.py b/tests/test_utils.py index ba01636d..3c6584f9 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -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}