feat(tests): add colors and run all tests in base module
This commit is contained in:
43
tests/__main__.py
Normal file
43
tests/__main__.py
Normal file
@@ -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()
|
||||||
@@ -7,6 +7,8 @@ from abc import ABC, abstractmethod
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Iterator, Protocol
|
from typing import Iterator, Protocol
|
||||||
|
|
||||||
|
from midas.cli.ansi import Ansi
|
||||||
|
|
||||||
|
|
||||||
class CaseResult(Protocol):
|
class CaseResult(Protocol):
|
||||||
def dumps(self) -> str: ...
|
def dumps(self) -> str: ...
|
||||||
@@ -44,8 +46,11 @@ class Tester(ABC):
|
|||||||
|
|
||||||
print(rule)
|
print(rule)
|
||||||
for i, test in enumerate(tests):
|
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)
|
success: bool = self._run_test(test)
|
||||||
|
print(Ansi.RESET, end="")
|
||||||
if success:
|
if success:
|
||||||
successes += 1
|
successes += 1
|
||||||
else:
|
else:
|
||||||
@@ -146,8 +151,9 @@ class Tester(ABC):
|
|||||||
if not success:
|
if not success:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
case None:
|
case None:
|
||||||
print("No subcommand provided. Available subcommands: run, update")
|
success: bool = tester.run_all_tests()
|
||||||
sys.exit(1)
|
if not success:
|
||||||
|
sys.exit(1)
|
||||||
case _:
|
case _:
|
||||||
print(f"Unknown subcommand '{args.subcommand}'")
|
print(f"Unknown subcommand '{args.subcommand}'")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|||||||
Reference in New Issue
Block a user