Skip to content

Commit 186b0ad

Browse files
committed
Added separate enums for exit and result codes
1 parent 6756cda commit 186b0ad

File tree

3 files changed

+34
-21
lines changed

3 files changed

+34
-21
lines changed

tools/scripts/test_runner/lib/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55

66
from .test_config import TestConfigProcessor
77
from .test_parser import ArgumentParserInterface, parse_test_output
8-
from .test_executor import TestExecutor
8+
from .test_executor import TestExecutor, ExitCode, TestResult
99

1010
__all__ = [
1111
'TestConfigProcessor',
1212
'ArgumentParserInterface',
1313
'parse_test_output',
14-
'TestExecutor'
14+
'TestExecutor',
15+
'ExitCode',
16+
'TestResult'
1517
]
1618

1719
__version__ = '1.0.0'

tools/scripts/test_runner/lib/test_executor.py

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,33 @@
1212
import sys
1313
import time
1414
import datetime
15+
from enum import IntEnum, Enum
1516
from pathlib import Path
1617

1718
# Make stdout unbuffered to prevent output ordering issues with subprocesses
1819
sys.stdout.reconfigure(line_buffering=True)
1920

2021

21-
class TestExecutor:
22-
"""
23-
Executes tests and manages build/test workflows
24-
"""
22+
class ExitCode(IntEnum):
23+
"""Exit codes for processes"""
24+
EXIT_SUCCESS = 0
25+
EXIT_FAILURE = 1
26+
EXIT_TIMEOUT = 124
27+
2528

26-
# Test results
29+
class TestResult(str, Enum):
30+
"""Test result statuses"""
2731
RESULT_PASSED = "PASSED"
2832
RESULT_FAILED = "FAILED"
2933
RESULT_TIMEOUT = "TIMEOUT"
3034
RESULT_SKIPPED = "SKIPPED"
3135

36+
37+
class TestExecutor:
38+
"""
39+
Executes tests and manages build/test workflows
40+
"""
41+
3242
def __init__(self, config_processor, args):
3343
"""
3444
Initialize TestExecutor
@@ -419,7 +429,7 @@ def run_test(self, test_config, suite_config):
419429
print(f"ERROR: Test binary not found: {test_binary_path}")
420430
return {
421431
"name": test_name,
422-
"result": self.RESULT_FAILED,
432+
"result": TestResult.RESULT_FAILED.value,
423433
"duration": 0,
424434
"error": f"Binary not found: {test_binary_path}"
425435
}
@@ -556,12 +566,12 @@ def run_test(self, test_config, suite_config):
556566
duration = time.time() - start_time
557567

558568
# Determine result
559-
if result.returncode == 0:
560-
test_result = self.RESULT_PASSED
561-
elif result.returncode == self.EXIT_TIMEOUT:
562-
test_result = self.RESULT_TIMEOUT
569+
if result.returncode == ExitCode.EXIT_SUCCESS:
570+
test_result = TestResult.RESULT_PASSED.value
571+
elif result.returncode == ExitCode.EXIT_TIMEOUT:
572+
test_result = TestResult.RESULT_TIMEOUT.value
563573
else:
564-
test_result = self.RESULT_FAILED
574+
test_result = TestResult.RESULT_FAILED.value
565575

566576
if self.args.verbose:
567577
print(f"\n Result: {test_result} ({duration:.3f} seconds)")
@@ -576,10 +586,10 @@ def run_test(self, test_config, suite_config):
576586
except subprocess.TimeoutExpired:
577587
duration = time.time() - start_time
578588
if self.args.verbose:
579-
print(f"\n Result: {self.RESULT_TIMEOUT} after {timeout} seconds")
589+
print(f"\n Result: {TestResult.RESULT_TIMEOUT.value} after {timeout} seconds")
580590
return {
581591
"name": test_name,
582-
"result": self.RESULT_TIMEOUT,
592+
"result": TestResult.RESULT_TIMEOUT.value,
583593
"duration": duration,
584594
"error": f"Test timed out after {timeout} seconds"
585595
}
@@ -588,7 +598,7 @@ def run_test(self, test_config, suite_config):
588598
print(f"\n ERROR: {e}")
589599
return {
590600
"name": test_name,
591-
"result": self.RESULT_FAILED,
601+
"result": TestResult.RESULT_FAILED.value,
592602
"duration": duration,
593603
"error": str(e)
594604
}
@@ -636,9 +646,9 @@ def run_test_suite(self, suite_config):
636646
def print_summary(self):
637647
"""Print test execution summary"""
638648
total_tests = len(self.test_results)
639-
passed = self.test_results.count(self.RESULT_PASSED)
640-
failed = self.test_results.count(self.RESULT_FAILED)
641-
timeout = self.test_results.count(self.RESULT_TIMEOUT)
649+
passed = self.test_results.count(TestResult.RESULT_PASSED.value)
650+
failed = self.test_results.count(TestResult.RESULT_FAILED.value)
651+
timeout = self.test_results.count(TestResult.RESULT_TIMEOUT.value)
642652

643653
# Get unique test suites that were run
644654
unique_suites = sorted(set(self.test_suites)) if self.test_suites else []

tools/scripts/test_runner/test_runner.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ def main():
9393

9494
# Return based on results
9595
if executor.test_results:
96-
failed = executor.test_results.count(executor.RESULT_FAILED)
97-
timeout = executor.test_results.count(executor.RESULT_TIMEOUT)
96+
from lib.test_executor import TestResult
97+
failed = executor.test_results.count(TestResult.RESULT_FAILED.value)
98+
timeout = executor.test_results.count(TestResult.RESULT_TIMEOUT.value)
9899
if failed > 0 or timeout > 0:
99100
if args.verbose:
100101
print(f"Exiting: Tests failed (failed={failed}, timeout={timeout})")

0 commit comments

Comments
 (0)