-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.py
More file actions
26 lines (20 loc) · 739 Bytes
/
common.py
File metadata and controls
26 lines (20 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import os
from pathlib import Path
from typing import NamedTuple, Callable, Any, Sequence
root = Path(os.path.dirname(os.path.realpath(__file__)))
class Test(NamedTuple):
function: Callable
input: tuple
expected: Any
def run_test_cases(cases: Sequence[Test], verbose: bool = False) -> None:
for case in cases:
try:
output = case.function(*case.input)
assert output == case.expected
except AssertionError:
print(
f"[X] {case.function.__name__}: expected {case.expected} for input {case.input}, found {output}"
)
else:
if verbose:
print(f"[√] {case.function.__name__}{case.input} == {case.expected}")