Skip to content

Commit

Permalink
Merge testcase state.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paebbels committed Feb 24, 2024
1 parent f1b2122 commit 041e6eb
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
51 changes: 50 additions & 1 deletion pyEDAA/Reports/Unittesting/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -688,6 +711,8 @@ def CombinedCount(self) -> int:

@export
class MergedTestcase(Testcase, Merged):
_mergedTestcases: List[Testcase]

def __init__(
self,
name: str,
Expand All @@ -713,16 +738,40 @@ 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

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):
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/Unittesting/Merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 041e6eb

Please sign in to comment.