From 041e6eb8f7df33acb78746348adee2af67e6ea4b Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Sat, 24 Feb 2024 02:51:50 +0100 Subject: [PATCH] Merge testcase state. --- pyEDAA/Reports/Unittesting/__init__.py | 51 +++++++++++++++++++++++++- tests/unit/Unittesting/Merge.py | 5 ++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/pyEDAA/Reports/Unittesting/__init__.py b/pyEDAA/Reports/Unittesting/__init__.py index 8e605cb3..9c2d139f 100644 --- a/pyEDAA/Reports/Unittesting/__init__.py +++ b/pyEDAA/Reports/Unittesting/__init__.py @@ -32,8 +32,9 @@ from datetime import timedelta, datetime from enum import Flag +from math import log2 from pathlib import Path -from typing import Optional as Nullable, Dict, Iterable, Any, Tuple, Generator, Union +from typing import Optional as Nullable, Dict, Iterable, Any, Tuple, Generator, Union, List from pyTooling.Decorators import export, readonly from pyTooling.MetaClasses import abstractmethod, ExtendedType, mustoverride @@ -65,6 +66,8 @@ class TestcaseState(Flag): Passed = 8 #: passed testcase, because all assertions succeeded Failed = 16 #: failed testcase due to failing assertions + Mask = Excluded | Skipped | Weak | Passed | Failed + Inverted = 128 #: to mark inverted results UnexpectedPassed = Failed | Inverted ExpectedFailed = Passed | Inverted @@ -78,6 +81,26 @@ class TestcaseState(Flag): # TODO: timed out ? + __MATRIX = ( + # unknown excluded skipped weak passed failed < other / self vv + (Unknown, Unknown, Unknown, Unknown, Unknown, Unknown), # unknown + (Unknown, Excluded, Unknown, Unknown, Unknown, Unknown), # excluded + (Unknown, Unknown, Skipped, Weak, Passed, Failed), # skipped + (Unknown, Unknown, Unknown, Weak, Unknown, Unknown), # weak + (Unknown, Unknown, Passed, Unknown, Passed, Unknown), # passed + (Unknown, Unknown, Failed, Unknown, Unknown, Failed), # failed + ) + + @classmethod + def __conv(cls, value) -> int: + try: + return int(log2((value & cls.Mask).value)) + 1 + except ValueError: + return 0 + + def __matmul__(self, other: "TestcaseState") -> "TestcaseState": + return self.__class__(self.__MATRIX[self.__conv(self)][self.__conv(other)]) + @export class IterationScheme(Flag): @@ -688,6 +711,8 @@ def CombinedCount(self) -> int: @export class MergedTestcase(Testcase, Merged): + _mergedTestcases: List[Testcase] + def __init__( self, name: str, @@ -713,9 +738,13 @@ def __init__( ) Merged.__init__(self) + self._mergedTestcases = [] + def Merge(self, tc: Testcase) -> None: self._mergedCount += 1 + self._mergedTestcases.append(tc) + self._warningCount += tc._warningCount self._errorCount += tc._errorCount self._fatalCount += tc._fatalCount @@ -723,6 +752,26 @@ def Merge(self, tc: Testcase) -> None: def Copy(self, tc: Testcase) -> None: pass + @readonly + def State(self) -> TestcaseState: + result = self._mergedTestcases[0]._state + for state in (tc._state for tc in self._mergedTestcases): + result @= state + + return result + + @readonly + def SummedAssertionCount(self) -> int: + return sum(tc._assertionCount for tc in self._mergedTestcases) + + @readonly + def SummedPassedAssertionCount(self) -> int: + return sum(tc._passedAssertionCount for tc in self._mergedTestcases) + + @readonly + def SummedFailedAssertionCount(self) -> int: + return sum(tc._failedAssertionCount for tc in self._mergedTestcases) + @export class MergedTestsuite(Testsuite, Merged): diff --git a/tests/unit/Unittesting/Merge.py b/tests/unit/Unittesting/Merge.py index 15fed0c9..82b3a39d 100644 --- a/tests/unit/Unittesting/Merge.py +++ b/tests/unit/Unittesting/Merge.py @@ -33,7 +33,7 @@ from typing import List from unittest import TestCase as ut_TestCase -from pyEDAA.Reports.Unittesting import MergedTestsuiteSummary, IterationScheme +from pyEDAA.Reports.Unittesting import MergedTestsuiteSummary, IterationScheme, TestcaseState from pyEDAA.Reports.Unittesting.JUnit import JUnitDocument @@ -71,6 +71,9 @@ def test_PlatformTesting(self) -> None: for item in merged.Iterate(IterationScheme.Default | IterationScheme.IncludeSelf): self.assertEqual(mergedCount, item.MergedCount) + for testcase in (tc for tc in merged.IterateTestcases() if tc.Name not in ("test_NativeMacOS", "test_MSYS", "test_MinGW32", "test_Clang32")): + self.assertEqual(TestcaseState.Passed, testcase.State) + print() print(f"Aggregating datapoints in testsuite ...") startAggregate = perf_counter_ns()