From 20173a0b07f10c62d107e4ea9eeb0c7debd0aaf9 Mon Sep 17 00:00:00 2001 From: LordBaryhobal Date: Fri, 3 Jul 2026 10:58:28 +0200 Subject: [PATCH] feat(tests): add colors and run all tests in base module --- tests/__main__.py | 43 +++++++++++++++++++++++++++++++++++++++++++ tests/base.py | 12 +++++++++--- 2 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 tests/__main__.py diff --git a/tests/__main__.py b/tests/__main__.py new file mode 100644 index 0000000..0280e3b --- /dev/null +++ b/tests/__main__.py @@ -0,0 +1,43 @@ +from typing import Type + +from midas.cli.ansi import Ansi +from tests.base import Tester +from tests.checker import CheckerTester +from tests.generator import GeneratorTester +from tests.midas import MidasTester +from tests.python import PythonTester + + +def print_banner(name: str): + horizontal: str = "+" + "-" * (len(name) + 2) + "+" + print(horizontal) + print(f"| {name} |") + print(horizontal) + + +def run_tests(tester_cls: Type[Tester]) -> bool: + print_banner(tester_cls.__name__) + tester: Tester = tester_cls() + success: bool = tester.run_all_tests() + print() + return success + + +def main(): + testers: list[Type[Tester]] = [ + PythonTester, + MidasTester, + CheckerTester, + GeneratorTester, + ] + + success: bool = all(map(run_tests, testers)) + + if success: + print(Ansi.FG(Ansi.BRIGHT_GREEN) + "All tests passed!" + Ansi.RESET) + else: + print(Ansi.FG(Ansi.BRIGHT_RED) + "Some tests failed!" + Ansi.RESET) + + +if __name__ == "__main__": + main() diff --git a/tests/base.py b/tests/base.py index c8bad17..353c3e8 100644 --- a/tests/base.py +++ b/tests/base.py @@ -7,6 +7,8 @@ from abc import ABC, abstractmethod from pathlib import Path from typing import Iterator, Protocol +from midas.cli.ansi import Ansi + class CaseResult(Protocol): def dumps(self) -> str: ... @@ -44,8 +46,11 @@ class Tester(ABC): print(rule) for i, test in enumerate(tests): - print(f"Case {i+1}/{n}: {test.resolve().relative_to(self.CASES_DIR)}") + path: Path = test.resolve().relative_to(self.CASES_DIR) + print(f"{Ansi.FG(Ansi.BRIGHT_CYAN)}Case {i+1}/{n}: {path}{Ansi.RESET}") + print(Ansi.DIM, end="") success: bool = self._run_test(test) + print(Ansi.RESET, end="") if success: successes += 1 else: @@ -146,8 +151,9 @@ class Tester(ABC): if not success: sys.exit(1) case None: - print("No subcommand provided. Available subcommands: run, update") - sys.exit(1) + success: bool = tester.run_all_tests() + if not success: + sys.exit(1) case _: print(f"Unknown subcommand '{args.subcommand}'") sys.exit(1)