Skip to content

Commit 81c6030

Browse files
dlatypovshuahkh
authored andcommitted
kunit: tool: fix minor typing issue with None status
The code to handle aggregating statuses didn't check that the status actually got set to some non-None value. Default the value to SUCCESS instead of adding a bunch of `is None` checks. This sorta follows the precedent in commit 3fc4825 ("kunit: Don't fail test suites if one of them is empty"). Also slightly simplify the code and add type annotations. Signed-off-by: Daniel Latypov <dlatypov@google.com> Reviewed-by: David Gow <davidgow@google.com> Reviewed-by: Brendan Higgins <brendanhiggins@google.com> Tested-by: Brendan Higgins <brendanhiggins@google.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent 09641f7 commit 81c6030

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

tools/testing/kunit/kunit_parser.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
from datetime import datetime
1313
from enum import Enum, auto
1414
from functools import reduce
15-
from typing import Iterator, List, Optional, Tuple
15+
from typing import Iterable, Iterator, List, Optional, Tuple
1616

1717
TestResult = namedtuple('TestResult', ['status','suites','log'])
1818

1919
class TestSuite(object):
2020
def __init__(self) -> None:
21-
self.status = None # type: Optional[TestStatus]
21+
self.status = TestStatus.SUCCESS
2222
self.name = ''
2323
self.cases = [] # type: List[TestCase]
2424

@@ -30,7 +30,7 @@ def __repr__(self) -> str:
3030

3131
class TestCase(object):
3232
def __init__(self) -> None:
33-
self.status = None # type: Optional[TestStatus]
33+
self.status = TestStatus.SUCCESS
3434
self.name = ''
3535
self.log = [] # type: List[str]
3636

@@ -224,12 +224,11 @@ def parse_ok_not_ok_test_suite(lines: List[str],
224224
else:
225225
return False
226226

227-
def bubble_up_errors(to_status, status_container_list) -> TestStatus:
228-
status_list = map(to_status, status_container_list)
229-
return reduce(max_status, status_list, TestStatus.SUCCESS)
227+
def bubble_up_errors(statuses: Iterable[TestStatus]) -> TestStatus:
228+
return reduce(max_status, statuses, TestStatus.SUCCESS)
230229

231230
def bubble_up_test_case_errors(test_suite: TestSuite) -> TestStatus:
232-
max_test_case_status = bubble_up_errors(lambda x: x.status, test_suite.cases)
231+
max_test_case_status = bubble_up_errors(x.status for x in test_suite.cases)
233232
return max_status(max_test_case_status, test_suite.status)
234233

235234
def parse_test_suite(lines: List[str], expected_suite_index: int) -> Optional[TestSuite]:
@@ -282,8 +281,8 @@ def parse_test_plan(lines: List[str]) -> Optional[int]:
282281
else:
283282
return None
284283

285-
def bubble_up_suite_errors(test_suite_list: List[TestSuite]) -> TestStatus:
286-
return bubble_up_errors(lambda x: x.status, test_suite_list)
284+
def bubble_up_suite_errors(test_suites: Iterable[TestSuite]) -> TestStatus:
285+
return bubble_up_errors(x.status for x in test_suites)
287286

288287
def parse_test_result(lines: List[str]) -> TestResult:
289288
consume_non_diagnostic(lines)

0 commit comments

Comments
 (0)