From e40056cb4f0d18a81f9830c3a08bf7692db736f4 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Wed, 2 Aug 2017 16:44:51 +0800 Subject: [PATCH] bugfix: comparison with None should raise exception in Python 2.7 --- ate/utils.py | 5 +++++ tests/test_utils.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ate/utils.py b/ate/utils.py index 07f522ca..320412f6 100644 --- a/ate/utils.py +++ b/ate/utils.py @@ -152,6 +152,11 @@ def match_expected(value, expected, comparator="eq", check_item=""): @param check_item: check item name """ 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", "=="]: assert value == expected elif comparator in ["str_eq", "string_equals"]: diff --git a/tests/test_utils.py b/tests/test_utils.py index 3c6584f9..9af1a1cb 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -196,9 +196,9 @@ class TestUtils(ApiServerUnittest): self.assertTrue(utils.match_expected("123abc", 12, "startswith")) self.assertTrue(utils.match_expected(12345, 123, "startswith")) + self.assertTrue(utils.match_expected(None, None, "eq")) with self.assertRaises(exception.ValidationError): utils.match_expected(None, 3, "len_eq") - with self.assertRaises(exception.ValidationError): utils.match_expected("abc", None, "gt")