Procházet zdrojové kódy

greater_chk and less_chk added

master
Dirk Alders před 1 rokem
rodič
revize
a73c8f8c35
1 změnil soubory, kde provedl 87 přidání a 1 odebrání
  1. 87
    1
      test.py

+ 87
- 1
test.py Zobrazit soubor

@@ -22,8 +22,20 @@ def __report_result__(result, description, data_filter=repr):
22 22
     logger.debug('Result (%s): %s (%s)', description, __get_repr__(result, data_filter), repr(type(result)))
23 23
 
24 24
 
25
+def __report_expectation__(compare, expectation, description, data_filter=repr):
26
+    logger.debug('Expectation (%s): result %s %s (%s)', description, compare, __get_repr__(expectation, data_filter), repr(type(expectation)))
27
+
28
+
25 29
 def __report_expectation_equivalency__(expectation, description, data_filter=repr):
26
-    logger.debug('Expectation (%s): result = %s (%s)', description, __get_repr__(expectation, data_filter), repr(type(expectation)))
30
+    __report_expectation__("=", expectation, description, data_filter=repr)
31
+
32
+
33
+def __report_expectation_greater__(expectation, description, data_filter=repr):
34
+    __report_expectation__(">", expectation, description, data_filter=repr)
35
+
36
+
37
+def __report_expectation_less__(expectation, description, data_filter=repr):
38
+    __report_expectation__("<", expectation, description, data_filter=repr)
27 39
 
28 40
 
29 41
 def __report_expectation_inlist__(expectation, description, data_filter=repr):
@@ -124,6 +136,34 @@ def __equivalent__(result, expectation, report_comment_fail=None, dict_key='test
124 136
     return log_lvl
125 137
 
126 138
 
139
+def __less__(result, expectation, report_comment_fail=None, dict_key='test_variable'):
140
+    report_comment_fail = (' ' + report_comment_fail) if report_comment_fail is not None else ''
141
+    log_lvl = REPORT_LEVEL_PASS
142
+    if result >= expectation:
143
+        log_lvl = REPORT_LEVEL_FAIL
144
+        logger.error('Content %s is incorrect' + (' for %s' % dict_key if dict_key != '' else '') + '.' + report_comment_fail, __get_repr__(result))
145
+    if type(result) != type(expectation):
146
+        if log_lvl < REPORT_LEVEL_INSPECT:
147
+            log_lvl = REPORT_LEVEL_INSPECT
148
+        logger.warning('Type %s is NOT %s%s (%s). ' + report_comment_fail.strip() or '', __get_repr__(type(result)),
149
+                       __get_repr__(type(expectation)), (' for %s' % dict_key if dict_key != '' else ''), __get_repr__(result))
150
+    return log_lvl
151
+
152
+
153
+def __greater__(result, expectation, report_comment_fail=None, dict_key='test_variable'):
154
+    report_comment_fail = (' ' + report_comment_fail) if report_comment_fail is not None else ''
155
+    log_lvl = REPORT_LEVEL_PASS
156
+    if result <= expectation:
157
+        log_lvl = REPORT_LEVEL_FAIL
158
+        logger.error('Content %s is incorrect' + (' for %s' % dict_key if dict_key != '' else '') + '.' + report_comment_fail, __get_repr__(result))
159
+    if type(result) != type(expectation):
160
+        if log_lvl < REPORT_LEVEL_INSPECT:
161
+            log_lvl = REPORT_LEVEL_INSPECT
162
+        logger.warning('Type %s is NOT %s%s (%s). ' + report_comment_fail.strip() or '', __get_repr__(type(result)),
163
+                       __get_repr__(type(expectation)), (' for %s' % dict_key if dict_key != '' else ''), __get_repr__(result))
164
+    return log_lvl
165
+
166
+
127 167
 def equivalency_chk(result, expectation, tcl, description='Variable', report_comment_fail=None, data_filter=repr):
128 168
     """
129 169
     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
147 187
     return report_level
148 188
 
149 189
 
190
+def less_chk(result, expectation, tcl, description='Variable', report_comment_fail=None, data_filter=repr):
191
+    """
192
+    Routine to check result > expectation inside a test run and report to a testCaseLogger.
193
+
194
+    :param result: The result of a test execution of a module
195
+    :type result: All types are supported
196
+    :param expectation: The expected value (shall be equivalent to result)
197
+    :type expectation: All types are supported
198
+    :param description: A descrition of the result. It will be reported like "xxx is correct." Example: descrition="stringrepresentation created by modulename"
199
+    :type description: str
200
+    :param report_comment_fail: Comment for a failed Testexecution. Will be added in brakets after the Result-Text.
201
+    :type report_comment_fail: str
202
+    """
203
+    __report_result__(result, description, data_filter=data_filter)
204
+    __report_expectation_less__(expectation, description, data_filter=data_filter)
205
+    report_level = __less__(result, expectation, report_comment_fail=report_comment_fail, dict_key='result')
206
+    if report_level == REPORT_LEVEL_PASS:
207
+        tcl.log(report_level, description + ' is greater expectation (Content %s and Type is %s).', data_filter(result), repr(type(result)))
208
+    else:
209
+        tcl.log(report_level, description + ' is NOT correct. See detailed log for more information.')
210
+    return report_level
211
+
212
+
213
+def greater_chk(result, expectation, tcl, description='Variable', report_comment_fail=None, data_filter=repr):
214
+    """
215
+    Routine to check result > expectation inside a test run and report to a testCaseLogger.
216
+
217
+    :param result: The result of a test execution of a module
218
+    :type result: All types are supported
219
+    :param expectation: The expected value (shall be equivalent to result)
220
+    :type expectation: All types are supported
221
+    :param description: A descrition of the result. It will be reported like "xxx is correct." Example: descrition="stringrepresentation created by modulename"
222
+    :type description: str
223
+    :param report_comment_fail: Comment for a failed Testexecution. Will be added in brakets after the Result-Text.
224
+    :type report_comment_fail: str
225
+    """
226
+    __report_result__(result, description, data_filter=data_filter)
227
+    __report_expectation_greater__(expectation, description, data_filter=data_filter)
228
+    report_level = __greater__(result, expectation, report_comment_fail=report_comment_fail, dict_key='result')
229
+    if report_level == REPORT_LEVEL_PASS:
230
+        tcl.log(report_level, description + ' is greater expectation (Content %s and Type is %s).', data_filter(result), repr(type(result)))
231
+    else:
232
+        tcl.log(report_level, description + ' is NOT correct. See detailed log for more information.')
233
+    return report_level
234
+
235
+
150 236
 class equivalency_order_chk(object):
151 237
     def __init__(self, ordered_values, tcl, description='Variable', report_comment_fail=None):
152 238
         self._expected_values = ordered_values

Načítá se…
Zrušit
Uložit