-
Notifications
You must be signed in to change notification settings - Fork 0
/
aoc.py
36 lines (20 loc) · 901 Bytes
/
aoc.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
import unittest
import sys
import importlib
import webbrowser
if __name__ == '__main__':
day = sys.argv[1]
day = day if len(day) == 2 else "0" + day
if len(sys.argv) == 2:
module = importlib.import_module(f"day{day}.solutions")
problem_1 = getattr(module, "problem_1")
problem_2 = getattr(module, "problem_2")
print(f"Problem 1 answer: {problem_1()}")
print(f"Problem 2 answer: {problem_2()}")
if len(sys.argv) == 3 and sys.argv[2] == "test":
module = importlib.import_module(f"day{day}.test")
test_class = getattr(module, f"Day_{day}_Tests")
suite = unittest.defaultTestLoader.loadTestsFromTestCase(test_class)
unittest.TextTestRunner(verbosity=2).run(suite)
if len(sys.argv) == 3 and sys.argv[2] == "open":
webbrowser.open_new_tab(f"https://adventofcode.com/2020/day/{day}")