-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_solutions.py
51 lines (38 loc) · 1.36 KB
/
test_solutions.py
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import importlib
import json
import pytest
@pytest.fixture(scope="session", params=list(range(2017, 2024)))
def year(request):
return request.param
@pytest.fixture(scope="session", params=list(range(1, 26)))
def day(request):
return request.param
@pytest.fixture(scope="session", params=(1, 2))
def part(request):
return request.param
@pytest.fixture(scope="session")
def solution(year, day, part):
with open("tests/known_incomplete_solutions.json") as f:
known_incomplete_solutions = json.load(f)
if part in known_incomplete_solutions.get(str(year), {}).get(str(day), []):
pytest.skip(
f"Known incomplete solution for year: {year}, day: {day}, part: {part}"
)
try:
module = importlib.import_module(f"{year}.day{day:02}")
return module.main(part=part)
except ModuleNotFoundError:
pytest.skip(f"No solution found for year: {year}, day: {day}, part: {part}")
@pytest.fixture(scope="session")
def expected(year, day, part):
with open("tests/expected.json") as f:
results = json.load(f)
try:
return results[str(year)][str(day)][str(part)]
except KeyError:
pytest.skip(
f"No expected output found for year: {year}, day: {day}, part: {part}"
)
@pytest.mark.timeout(60)
def test_solution(solution, expected):
assert solution == expected