Coverage for src/zapy/test/assertion.py: 100%
25 statements
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-10 19:35 +0000
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-10 19:35 +0000
1import warnings
2from typing import Callable, List
4from .models import TestResult
7def filter_failed_tests(test_result: List[TestResult]) -> List[TestResult]:
8 failed_tests = [result for result in test_result if result["status"] in ("error", "failure")]
9 return failed_tests
12class AssertTestResultMixin:
14 assertEqual: Callable # noqa: N815
16 def assert_zapy_test_results(self, test_result: List[TestResult]) -> None:
17 """Fails if `test_result` contains an item with `error` or `failure` status.
19 Parameters
20 ----------
21 test_result : List[TestResult]
22 The test results of the request.
24 Raises
25 ------
26 AssertionError
27 If `test_result` contains an item with `error` or `failure` status.
28 """
29 failed_tests = filter_failed_tests(test_result)
30 self.assertEqual([], failed_tests)
32 def assertZapyTestResults(self, test_result: List[TestResult]) -> None: # noqa: N802
33 """This alias will be deprecated in preference of `assert_zapy_test_results`."""
34 warnings.warn(
35 "Call to deprecated function assertZapyTestResults. Replace it with assert_zapy_test_results.", stacklevel=2
36 )
37 self.assert_zapy_test_results(test_result)
40def assert_test_result_dict(test_result: List[TestResult]) -> None:
41 failed_tests = filter_failed_tests(test_result)
42 if [] != failed_tests:
43 err_msg = stringify_error(failed_tests)
44 raise AssertionError(err_msg)
47def stringify_error(error: List[TestResult]) -> str:
48 output = ""
49 for err in error:
50 output += f"Method: {err['method']}"
51 output += f"\n{err['traceback']}\n"
52 return output