"""
Helper functions for a basic test suite
"""

from typing import Callable, List
from enum import StrEnum
from dataclasses import dataclass
from traceback import print_exc


class TestResult(StrEnum):
    PASS = "PASS"
    FAIL = "FAIL"
    SKIP = "SKIP"


@dataclass
class TestInfo:
    suite_name: str
    test_name: str
    result: TestResult

    def __str__(self):
        # TODO colour?
        return f"[{self.suite_name}.{self.test_name}] {self.result}"


skipped_suites: List[str] = []


def skip_suite(suite_name: str):
    """Skips running tests from a specific suite"""
    skipped_suites.append(suite_name)


def run_test(suite_name: str, test_fn: Callable, do_skip = False) -> TestResult:
    test_name = test_fn.__name__

    if do_skip or suite_name in skipped_suites:
        res = TestInfo(suite_name, test_name, TestResult.SKIP)
    else:
        print(f"[{suite_name}.{test_name}] Running...")
        try:
            test_fn()
            res = TestInfo(suite_name, test_name, TestResult.PASS)
        except AssertionError:
            res =  TestInfo(suite_name, test_name, TestResult.FAIL)
            print_exc()

    print(res)
    return res
