Commit f473dd94 authored by Daniel Latypov's avatar Daniel Latypov Committed by Shuah Khan

kunit: tool: make TestCounts a dataclass

Since we're using Python 3.7+, we can use dataclasses to tersen the
code.

It also lets us create pre-populated TestCounts() objects and compare
them in our unit test. (Before, you could only create empty ones).
Signed-off-by: default avatarDaniel Latypov <dlatypov@google.com>
Reviewed-by: default avatarDavid Gow <davidgow@google.com>
Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
parent f19dd011
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
# Author: Rae Moar <rmoar@google.com> # Author: Rae Moar <rmoar@google.com>
from __future__ import annotations from __future__ import annotations
from dataclasses import dataclass
import re import re
import sys import sys
...@@ -71,27 +72,17 @@ class TestStatus(Enum): ...@@ -71,27 +72,17 @@ class TestStatus(Enum):
NO_TESTS = auto() NO_TESTS = auto()
FAILURE_TO_PARSE_TESTS = auto() FAILURE_TO_PARSE_TESTS = auto()
@dataclass
class TestCounts: class TestCounts:
""" """
Tracks the counts of statuses of all test cases and any errors within Tracks the counts of statuses of all test cases and any errors within
a Test. a Test.
"""
Attributes: passed: int = 0
passed : int - the number of tests that have passed failed: int = 0
failed : int - the number of tests that have failed crashed: int = 0
crashed : int - the number of tests that have crashed skipped: int = 0
skipped : int - the number of tests that have skipped errors: int = 0
errors : int - the number of errors in the test and subtests
"""
def __init__(self):
"""Creates TestCounts object with counts of all test
statuses and test errors set to 0.
"""
self.passed = 0
self.failed = 0
self.crashed = 0
self.skipped = 0
self.errors = 0
def __str__(self) -> str: def __str__(self) -> str:
"""Returns the string representation of a TestCounts object.""" """Returns the string representation of a TestCounts object."""
......
...@@ -182,9 +182,7 @@ class KUnitParserTest(unittest.TestCase): ...@@ -182,9 +182,7 @@ class KUnitParserTest(unittest.TestCase):
kunit_parser.extract_tap_lines( kunit_parser.extract_tap_lines(
file.readlines())) file.readlines()))
# A missing test plan is not an error. # A missing test plan is not an error.
self.assertEqual(0, result.counts.errors) self.assertEqual(result.counts, kunit_parser.TestCounts(passed=10, errors=0))
# All tests should be accounted for.
self.assertEqual(10, result.counts.total())
self.assertEqual( self.assertEqual(
kunit_parser.TestStatus.SUCCESS, kunit_parser.TestStatus.SUCCESS,
result.status) result.status)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment