kopia lustrzana https://github.com/espressif/esp-idf
Tiny-test-fw: Fix string comparison which cases ignore of test cases
Example tests from examples/protocols/http_server/ were silently ignored because of incompatible string comparisons.pull/2683/head
rodzic
222a7118a9
commit
374f92c0a0
|
@ -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:
|
||||
|
|
Ładowanie…
Reference in New Issue