]> granicus.if.org Git - esp-idf/commitdiff
Tiny-test-fw: Fix string comparison which cases ignore of test cases
authorRoland Dobai <dobai.roland@gmail.com>
Wed, 10 Oct 2018 06:24:42 +0000 (08:24 +0200)
committerRoland Dobai <dobai.roland@gmail.com>
Wed, 17 Oct 2018 09:07:04 +0000 (11:07 +0200)
Example tests from examples/protocols/http_server/ were silently ignored
because of incompatible string comparisons.

tools/tiny-test-fw/Utility/CaseConfig.py

index 3260c9b6ee855e74583c13eac5fc57a23462cf4b..910131dd9f9dbb24e3576deaad01e2204e02d3e0 100644 (file)
@@ -51,15 +51,18 @@ import yaml
 import TestCase
 
 
-def _convert_to_lower_case(item):
+def _convert_to_lower_case_bytes(item):
     """
     bot filter is always lower case string.
     this function will convert to all string to lower case.
+    Note: Unicode strings are converted to bytes.
     """
     if isinstance(item, (tuple, list)):
-        output = [_convert_to_lower_case(v) for v in item]
-    elif isinstance(item, str):
+        output = [_convert_to_lower_case_bytes(v) for v in item]
+    elif type(item) == type(b''):
         output = item.lower()
+    elif type(item) == type(u''):
+        output = item.encode().lower()
     else:
         output = item
     return output
@@ -76,8 +79,8 @@ def _filter_one_case(test_method, case_filter):
         if key in test_method.case_info:
             # the filter key is both in case and filter
             # we need to check if they match
-            filter_item = _convert_to_lower_case(case_filter[orig_key])
-            accepted_item = _convert_to_lower_case(test_method.case_info[key])
+            filter_item = _convert_to_lower_case_bytes(case_filter[orig_key])
+            accepted_item = _convert_to_lower_case_bytes(test_method.case_info[key])
 
             if isinstance(filter_item, (tuple, list)) \
                     and isinstance(accepted_item, (tuple, list)):
@@ -90,6 +93,9 @@ def _filter_one_case(test_method, case_filter):
                 # accepted item list/tuple, check if case filter value is in accept item list/tuple
                 filter_result = True if filter_item in accepted_item else False
             else:
+                if type(filter_item) != type(accepted_item):
+                    # This will catch silent ignores of test cases when Unicode and bytes are compared
+                    raise AssertionError(filter_item, '!=', accepted_item)
                 # both string/int, just do string compare
                 filter_result = (filter_item == accepted_item)
         else: