From 8278b91e1965badc215c5aa9887d844bd71d6741 Mon Sep 17 00:00:00 2001 From: Stefan Harmuth Date: Sun, 21 Nov 2021 13:13:16 +0100 Subject: [PATCH] don't spam the output on live input runs --- aoclib/day.py | 16 ++++++++++++---- main.py | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/aoclib/day.py b/aoclib/day.py index f44e0c7..2d0f0ce 100644 --- a/aoclib/day.py +++ b/aoclib/day.py @@ -24,29 +24,37 @@ class AOCDay: def part2(self) -> Any: pass - def test_part1(self) -> bool: + def test_part1(self, silent: bool = False) -> bool: live_input = self.input.copy() for case, solution in enumerate(self.test_solutions_p1): with open(os.path.join(INPUTS_PATH, "test_input%02d_1_%d" % (self.day, case))) as f: self.input = f.read().splitlines() check = self.part1() - printSolution(self.day, 1, check, solution, case) + if not silent: + printSolution(self.day, 1, check, solution, case) + if check != solution: + if silent: + printSolution(self.day, 1, check, solution, case) return False self.input = live_input return True - def test_part2(self) -> bool: + def test_part2(self, silent: bool = False) -> bool: live_input = self.input.copy() for case, solution in enumerate(self.test_solutions_p2): with open(os.path.join(INPUTS_PATH, "test_input%02d_2_%d" % (self.day, case))) as f: self.input = f.read().splitlines() check = self.part2() - printSolution(self.day, 2, check, solution, case) + if not silent: + printSolution(self.day, 2, check, solution, case) + if check != solution: + if silent: + printSolution(self.day, 2, check, solution, case) return False self.input = live_input diff --git a/main.py b/main.py index e551860..a2b9289 100644 --- a/main.py +++ b/main.py @@ -41,12 +41,12 @@ for lib in sorted(imported): day_class = getattr(globals()[lib], "Day")(day) if not flags.test: if not flags.part or flags.part == 1: - if not day_class.test_part1(): + if not day_class.test_part1(silent=True): print("TEST FAILED! Aborting.") sys.exit(1) if not flags.part or flags.part == 2: - if not day_class.test_part2(): + if not day_class.test_part2(silent=True): print("TEST FAILED! Aborting.") sys.exit(1)