Selaa lähdekoodia

test.in_list_dict_chk implemented

master
Dirk Alders 4 vuotta sitten
vanhempi
commit
9bb490eb30
1 muutettua tiedostoa jossa 17 lisäystä ja 12 poistoa
  1. 17
    12
      test.py

+ 17
- 12
test.py Näytä tiedosto

@@ -26,6 +26,10 @@ def __report_expectation_equivalency__(expectation, description, data_filter=rep
26 26
     logger.debug('Expectation (%s): result = %s (%s)', description, __get_repr__(expectation, data_filter), repr(type(expectation)))
27 27
 
28 28
 
29
+def __report_expectation_inlist__(expectation, description, data_filter=repr):
30
+    logger.debug('Expectation (%s): %s in result', description, __get_repr__(expectation, data_filter))
31
+
32
+
29 33
 def __report_expectation_range__(min_expectation, max_expectation, description):
30 34
     logger.debug('Expectation (%s): %s <= result <= %s', description, __get_repr__(min_expectation), __get_repr__(max_expectation))
31 35
 
@@ -130,8 +134,6 @@ def equivalency_chk(result, expectation, tcl, description='Variable', report_com
130 134
     :type expectation: All types are supported
131 135
     :param description: A descrition of the result. It will be reported like "xxx is correct." Example: descrition="stringrepresentation created by modulename"
132 136
     :type description: str
133
-    :param report_level_pass: The reporting level as defined in :class:`logging` (e.g.: logging.INFO)
134
-    :param report_level_fail: The reporting level as defined in :class:`logging` (e.g.: logging.ERROR)
135 137
     :param report_comment_fail: Comment for a failed Testexecution. Will be added in brakets after the Result-Text.
136 138
     :type report_comment_fail: str
137 139
     """
@@ -221,21 +223,24 @@ def range_chk(result, min_expectation, max_expectation, tcl, description='Value'
221 223
     return report_level
222 224
 
223 225
 
224
-def in_list_chk(result, expectation_list, tcl, description='Value', report_level_pass=logging.INFO, report_level_fail=logging.ERROR, report_comment_fail=None):
226
+def in_list_dict_chk(result_list, expectation_key, tcl, description='Value', report_comment_fail=None, data_filter=repr):
225 227
     """
226 228
     Routine to check values to be in a range inside a test run and report to a testCaseLogger.
227 229
 
228
-    :param result: The result of a test execution of a module
229
-    :type result: All types are supported
230
-    :param expectation_list: The list of allowed values
231
-    :type expectation_list: A list of all types is supported
230
+    :param result_key: The result of a test execution of a module
231
+    :type result_key: All types are supported
232
+    :param expectation_list: The list or dict of allowed values
233
+    :type expectation_list: A list of all types or a dict is supported
232 234
     :param description: A descrition of the result. It will be reported like "xxx is correct." Example: descrition="stringrepresentation created by modulename"
233 235
     :type description: str
234
-    :param report_level_pass: The reporting level as defined in :class:`logging` (e.g.: logging.INFO)
235
-    :param report_level_fail: The reporting level as defined in :class:`logging` (e.g.: logging.ERROR)
236 236
     :param report_comment_fail: Comment for a failed Testexecution. Will be added in brakets after the Result-Text.
237 237
     :type report_comment_fail: str
238 238
     """
239
-    __report_values__(result, expectation)
240
-    tcl.log(REPORT_LEVEL_FAIL, 'in_list check not yet implemented')
241
-    return REPORT_LEVEL_FAIL
239
+    __report_result__(result_list, description)
240
+    __report_expectation_inlist__(expectation_key, description, data_filter=data_filter)
241
+    if expectation_key in result_list:
242
+        tcl.log(REPORT_LEVEL_PASS, description + ' is correct (%s is in the list or dict).', data_filter(expectation_key))
243
+        return REPORT_LEVEL_PASS
244
+    else:
245
+        tcl.log(REPORT_LEVEL_FAIL, description + ' is NOT correct (%s is NOT in the list or dict).', data_filter(expectation_key))
246
+        return REPORT_LEVEL_FAIL

Loading…
Peruuta
Tallenna