diff options
Diffstat (limited to 'src/test/test.py')
| -rw-r--r-- | src/test/test.py | 48 |
1 files changed, 23 insertions, 25 deletions
diff --git a/src/test/test.py b/src/test/test.py index 91fbbca..506bfff 100644 --- a/src/test/test.py +++ b/src/test/test.py @@ -6,7 +6,7 @@ # By: charles <me@cacharle.xyz> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/09/27 11:36:32 by charles #+# #+# # -# Updated: 2020/09/28 16:08:51 by cacharle ### ########.fr # +# Updated: 2020/09/29 10:53:14 by cacharle ### ########.fr # # # # ############################################################################ # @@ -15,15 +15,13 @@ import subprocess import config import test.philo as philo - - -class ShouldFailError(Exception): - pass +import test.error as error class Test: _tests = [] _exec_path = None + _fail_summaries = [] @classmethod def run_all(cls, exec_path: str): @@ -57,16 +55,17 @@ class Test: def run(self): try: self._run_tested() - except ShouldFailError as e: - self._print_fail("not failed: " + str(e)) - except philo.FormatError as e: - self._print_fail("format: " + str(e)) - except philo.LogError as e: - self._print_fail("log: " + str(e)) - # except Time + except error.Philo as e: + self._print_fail(e.summary) + Test._fail_summaries.append(self._argv_str + '\n' + e.full_summary) else: self._print_pass() + @classmethod + def write_failed(cls): + with open(config.RESULT_FILE, "w") as f: + f.write('\n\n'.join(cls._fail_summaries)) + def _run_tested(self): process = subprocess.Popen( self._argv(), @@ -90,22 +89,17 @@ class Test: table.add_log(philo.Log(line, self._philo_num)) table.check() if died and not table.dead: - raise philo.LogError("one philosopher should have died") + raise philo.error.Log("one philosopher should have died") def _check_error(self, process): try: out, _ = process.communicate(timeout=config.TIMEOUT_ERROR) except subprocess.TimeoutExpired: - raise ShouldFailError("no error message") + raise error.ShouldFail("no error message") if process.returncode == 0: - raise ShouldFailError("non zero status code: {}".format(process.returncode)) + raise error.ShouldFail("non zero status code: {}".format(process.returncode)) if out.decode().count('\n') != 1: - raise ShouldFailError("no error message") - - RED_CHARS = "\033[31m" - GREEN_CHARS = "\033[32m" - BOLD_CHARS = "\033[1m" - CLOSE_CHARS = "\033[0m" + raise error.ShouldFail("no error message") def _argv(self, basename=False): exec_path = os.path.basename(Test._exec_path) if basename else Test._exec_path @@ -123,12 +117,16 @@ class Test: argv.append(str(self._meal_num)) return argv + @property + def _argv_str(self): + return ' '.join(self._argv(basename=True)) + + RED_CHARS = "\033[31m" + GREEN_CHARS = "\033[32m" + CLOSE_CHARS = "\033[0m" + def _print_fail(self, msg): print("{}[FAIL] {}: {}{}".format(Test.RED_CHARS, self._argv_str, msg, Test.CLOSE_CHARS)) def _print_pass(self): print("{}[PASS] {}{}".format(Test.GREEN_CHARS, self._argv_str, Test.CLOSE_CHARS)) - - @property - def _argv_str(self): - return ' '.join(self._argv(basename=True)) |
