greater_chk and less_chk added
This commit is contained in:
parent
5b077eab90
commit
a73c8f8c35
88
test.py
88
test.py
@ -22,8 +22,20 @@ def __report_result__(result, description, data_filter=repr):
|
||||
logger.debug('Result (%s): %s (%s)', description, __get_repr__(result, data_filter), repr(type(result)))
|
||||
|
||||
|
||||
def __report_expectation__(compare, expectation, description, data_filter=repr):
|
||||
logger.debug('Expectation (%s): result %s %s (%s)', description, compare, __get_repr__(expectation, data_filter), repr(type(expectation)))
|
||||
|
||||
|
||||
def __report_expectation_equivalency__(expectation, description, data_filter=repr):
|
||||
logger.debug('Expectation (%s): result = %s (%s)', description, __get_repr__(expectation, data_filter), repr(type(expectation)))
|
||||
__report_expectation__("=", expectation, description, data_filter=repr)
|
||||
|
||||
|
||||
def __report_expectation_greater__(expectation, description, data_filter=repr):
|
||||
__report_expectation__(">", expectation, description, data_filter=repr)
|
||||
|
||||
|
||||
def __report_expectation_less__(expectation, description, data_filter=repr):
|
||||
__report_expectation__("<", expectation, description, data_filter=repr)
|
||||
|
||||
|
||||
def __report_expectation_inlist__(expectation, description, data_filter=repr):
|
||||
@ -124,6 +136,34 @@ def __equivalent__(result, expectation, report_comment_fail=None, dict_key='test
|
||||
return log_lvl
|
||||
|
||||
|
||||
def __less__(result, expectation, report_comment_fail=None, dict_key='test_variable'):
|
||||
report_comment_fail = (' ' + report_comment_fail) if report_comment_fail is not None else ''
|
||||
log_lvl = REPORT_LEVEL_PASS
|
||||
if result >= expectation:
|
||||
log_lvl = REPORT_LEVEL_FAIL
|
||||
logger.error('Content %s is incorrect' + (' for %s' % dict_key if dict_key != '' else '') + '.' + report_comment_fail, __get_repr__(result))
|
||||
if type(result) != type(expectation):
|
||||
if log_lvl < REPORT_LEVEL_INSPECT:
|
||||
log_lvl = REPORT_LEVEL_INSPECT
|
||||
logger.warning('Type %s is NOT %s%s (%s). ' + report_comment_fail.strip() or '', __get_repr__(type(result)),
|
||||
__get_repr__(type(expectation)), (' for %s' % dict_key if dict_key != '' else ''), __get_repr__(result))
|
||||
return log_lvl
|
||||
|
||||
|
||||
def __greater__(result, expectation, report_comment_fail=None, dict_key='test_variable'):
|
||||
report_comment_fail = (' ' + report_comment_fail) if report_comment_fail is not None else ''
|
||||
log_lvl = REPORT_LEVEL_PASS
|
||||
if result <= expectation:
|
||||
log_lvl = REPORT_LEVEL_FAIL
|
||||
logger.error('Content %s is incorrect' + (' for %s' % dict_key if dict_key != '' else '') + '.' + report_comment_fail, __get_repr__(result))
|
||||
if type(result) != type(expectation):
|
||||
if log_lvl < REPORT_LEVEL_INSPECT:
|
||||
log_lvl = REPORT_LEVEL_INSPECT
|
||||
logger.warning('Type %s is NOT %s%s (%s). ' + report_comment_fail.strip() or '', __get_repr__(type(result)),
|
||||
__get_repr__(type(expectation)), (' for %s' % dict_key if dict_key != '' else ''), __get_repr__(result))
|
||||
return log_lvl
|
||||
|
||||
|
||||
def equivalency_chk(result, expectation, tcl, description='Variable', report_comment_fail=None, data_filter=repr):
|
||||
"""
|
||||
Routine to check values for equivalency inside a test run and report to a testCaseLogger.
|
||||
@ -147,6 +187,52 @@ def equivalency_chk(result, expectation, tcl, description='Variable', report_com
|
||||
return report_level
|
||||
|
||||
|
||||
def less_chk(result, expectation, tcl, description='Variable', report_comment_fail=None, data_filter=repr):
|
||||
"""
|
||||
Routine to check result > expectation inside a test run and report to a testCaseLogger.
|
||||
|
||||
:param result: The result of a test execution of a module
|
||||
:type result: All types are supported
|
||||
:param expectation: The expected value (shall be equivalent to result)
|
||||
: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"
|
||||
:type description: str
|
||||
:param report_comment_fail: Comment for a failed Testexecution. Will be added in brakets after the Result-Text.
|
||||
:type report_comment_fail: str
|
||||
"""
|
||||
__report_result__(result, description, data_filter=data_filter)
|
||||
__report_expectation_less__(expectation, description, data_filter=data_filter)
|
||||
report_level = __less__(result, expectation, report_comment_fail=report_comment_fail, dict_key='result')
|
||||
if report_level == REPORT_LEVEL_PASS:
|
||||
tcl.log(report_level, description + ' is greater expectation (Content %s and Type is %s).', data_filter(result), repr(type(result)))
|
||||
else:
|
||||
tcl.log(report_level, description + ' is NOT correct. See detailed log for more information.')
|
||||
return report_level
|
||||
|
||||
|
||||
def greater_chk(result, expectation, tcl, description='Variable', report_comment_fail=None, data_filter=repr):
|
||||
"""
|
||||
Routine to check result > expectation inside a test run and report to a testCaseLogger.
|
||||
|
||||
:param result: The result of a test execution of a module
|
||||
:type result: All types are supported
|
||||
:param expectation: The expected value (shall be equivalent to result)
|
||||
: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"
|
||||
:type description: str
|
||||
:param report_comment_fail: Comment for a failed Testexecution. Will be added in brakets after the Result-Text.
|
||||
:type report_comment_fail: str
|
||||
"""
|
||||
__report_result__(result, description, data_filter=data_filter)
|
||||
__report_expectation_greater__(expectation, description, data_filter=data_filter)
|
||||
report_level = __greater__(result, expectation, report_comment_fail=report_comment_fail, dict_key='result')
|
||||
if report_level == REPORT_LEVEL_PASS:
|
||||
tcl.log(report_level, description + ' is greater expectation (Content %s and Type is %s).', data_filter(result), repr(type(result)))
|
||||
else:
|
||||
tcl.log(report_level, description + ' is NOT correct. See detailed log for more information.')
|
||||
return report_level
|
||||
|
||||
|
||||
class equivalency_order_chk(object):
|
||||
def __init__(self, ordered_values, tcl, description='Variable', report_comment_fail=None):
|
||||
self._expected_values = ordered_values
|
||||
|
Loading…
x
Reference in New Issue
Block a user