test.in_list_dict_chk implemented

This commit is contained in:
Dirk Alders 2021-01-06 22:56:09 +01:00
parent a34ffe1201
commit 9bb490eb30

29
test.py
View File

@ -26,6 +26,10 @@ def __report_expectation_equivalency__(expectation, description, data_filter=rep
logger.debug('Expectation (%s): result = %s (%s)', description, __get_repr__(expectation, data_filter), repr(type(expectation))) logger.debug('Expectation (%s): result = %s (%s)', description, __get_repr__(expectation, data_filter), repr(type(expectation)))
def __report_expectation_inlist__(expectation, description, data_filter=repr):
logger.debug('Expectation (%s): %s in result', description, __get_repr__(expectation, data_filter))
def __report_expectation_range__(min_expectation, max_expectation, description): def __report_expectation_range__(min_expectation, max_expectation, description):
logger.debug('Expectation (%s): %s <= result <= %s', description, __get_repr__(min_expectation), __get_repr__(max_expectation)) logger.debug('Expectation (%s): %s <= result <= %s', description, __get_repr__(min_expectation), __get_repr__(max_expectation))
@ -130,8 +134,6 @@ def equivalency_chk(result, expectation, tcl, description='Variable', report_com
:type expectation: All types are supported :type expectation: All types are supported
:param description: A descrition of the result. It will be reported like "xxx is correct." Example: descrition="stringrepresentation created by modulename" :param description: A descrition of the result. It will be reported like "xxx is correct." Example: descrition="stringrepresentation created by modulename"
:type description: str :type description: str
:param report_level_pass: The reporting level as defined in :class:`logging` (e.g.: logging.INFO)
:param report_level_fail: The reporting level as defined in :class:`logging` (e.g.: logging.ERROR)
:param report_comment_fail: Comment for a failed Testexecution. Will be added in brakets after the Result-Text. :param report_comment_fail: Comment for a failed Testexecution. Will be added in brakets after the Result-Text.
:type report_comment_fail: str :type report_comment_fail: str
""" """
@ -221,21 +223,24 @@ def range_chk(result, min_expectation, max_expectation, tcl, description='Value'
return report_level return report_level
def in_list_chk(result, expectation_list, tcl, description='Value', report_level_pass=logging.INFO, report_level_fail=logging.ERROR, report_comment_fail=None): def in_list_dict_chk(result_list, expectation_key, tcl, description='Value', report_comment_fail=None, data_filter=repr):
""" """
Routine to check values to be in a range inside a test run and report to a testCaseLogger. Routine to check values to be in a range inside a test run and report to a testCaseLogger.
:param result: The result of a test execution of a module :param result_key: The result of a test execution of a module
:type result: All types are supported :type result_key: All types are supported
:param expectation_list: The list of allowed values :param expectation_list: The list or dict of allowed values
:type expectation_list: A list of all types is supported :type expectation_list: A list of all types or a dict is supported
:param description: A descrition of the result. It will be reported like "xxx is correct." Example: descrition="stringrepresentation created by modulename" :param description: A descrition of the result. It will be reported like "xxx is correct." Example: descrition="stringrepresentation created by modulename"
:type description: str :type description: str
:param report_level_pass: The reporting level as defined in :class:`logging` (e.g.: logging.INFO)
:param report_level_fail: The reporting level as defined in :class:`logging` (e.g.: logging.ERROR)
:param report_comment_fail: Comment for a failed Testexecution. Will be added in brakets after the Result-Text. :param report_comment_fail: Comment for a failed Testexecution. Will be added in brakets after the Result-Text.
:type report_comment_fail: str :type report_comment_fail: str
""" """
__report_values__(result, expectation) __report_result__(result_list, description)
tcl.log(REPORT_LEVEL_FAIL, 'in_list check not yet implemented') __report_expectation_inlist__(expectation_key, description, data_filter=data_filter)
return REPORT_LEVEL_FAIL if expectation_key in result_list:
tcl.log(REPORT_LEVEL_PASS, description + ' is correct (%s is in the list or dict).', data_filter(expectation_key))
return REPORT_LEVEL_PASS
else:
tcl.log(REPORT_LEVEL_FAIL, description + ' is NOT correct (%s is NOT in the list or dict).', data_filter(expectation_key))
return REPORT_LEVEL_FAIL