From: Martin Mares Date: Fri, 14 Aug 2009 09:01:34 +0000 (+0200) Subject: Better logging of exceptions X-Git-Tag: python-dummy-working~67 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=c80aa556a07b88cafe5a18f6b86a90f30b199ba9;p=eval.git Better logging of exceptions --- diff --git a/t/config b/t/config index 411443f..b84cb73 100644 --- a/t/config +++ b/t/config @@ -14,6 +14,8 @@ TESTCASE_RAW=${TEST}.raw # backward compatibility TESTCASE_PTS=${TEST}.pts +DEBUG=1 + # HOOKS # TESTCASE_HOOKS diff --git a/t/moe/batch.py b/t/moe/batch.py index 15f3b90..9c83983 100644 --- a/t/moe/batch.py +++ b/t/moe/batch.py @@ -114,12 +114,18 @@ def test_in(e): if in_type == "file": in_name = e["IN_NAME"] e.log.verbose("Input file: %s (copied from %s)\n" % (in_name, os.path.join(e["PDIR"], inn))) - shutil.copyfile(os.path.join(tdir, inn), os.path.join(boxdir, in_name)) + try: + shutil.copyfile(os.path.join(tdir, inn), os.path.join(boxdir, in_name)) + except IOError: + raise moe.MoeError, "Input file not found" if not is_interactive: sandbox_opts += " -i/dev/null" elif in_type == "stdio": e.log.verbose("Input file: (copied from %s)\n" % os.path.join(e["PDIR"], inn)) - shutil.copyfile(os.path.join(tdir, inn), os.path.join(boxdir, ".stdin")) + try: + shutil.copyfile(os.path.join(tdir, inn), os.path.join(boxdir, ".stdin")) + except IOError: + raise moe.MoeError, "Input file not found" sandbox_opts += " -i.stdin" elif in_type == "none": e.log.verbose("Input file: \n") diff --git a/t/moe/log.py b/t/moe/log.py index 56dbe8f..592fb84 100644 --- a/t/moe/log.py +++ b/t/moe/log.py @@ -2,8 +2,11 @@ import sys import os +import traceback -progress_file = os.fdopen(os.dup(1), "w", 0) +orig_stdout_fd = os.dup(1) +orig_stderr_fd = os.dup(2) +progress_file = os.fdopen(orig_stdout_fd, "w", 0) class MoeLog: @@ -37,3 +40,8 @@ class MoeLog: self.log_file.flush() default = MoeLog() + +def fatal_exception(): + os.dup2(orig_stderr_fd, 2) + traceback.print_exc() + sys.exit(1) diff --git a/t/moe/testcase.py b/t/moe/testcase.py index e129a53..36d335b 100644 --- a/t/moe/testcase.py +++ b/t/moe/testcase.py @@ -6,6 +6,7 @@ import moe.config import moe.eval import moe.log import shutil +import traceback def configure_test(e, test): e.cfgs = moe.config.MoeConfigStack(e.cfgs) @@ -167,6 +168,11 @@ def wrap_run_test(e, test): run_test(e, test) except moe.MoeError, err: raise moe.TestError(err, "XX") + except Exception: + if e["DEBUG"]: + moe.log.fatal_exception() + traceback.print_exc(file = e.log.log_file) + raise moe.TestError("Internal exception", "XX") def conclude_test(e): stat = e.test_stat diff --git a/t/test.py b/t/test.py index 37a21c9..26d1a29 100755 --- a/t/test.py +++ b/t/test.py @@ -9,6 +9,7 @@ import moe.log import moe.eval import moe.pipeline import moe.batch +import os e = moe.eval.Eval() @@ -36,6 +37,8 @@ except moe.MoeError, err: except moe.SolutionError, err: e.stat["error"] = err e.log.shout("%s\n" % err) +except Exception: + moe.log.fatal_exception() moe.log.default.progress_file.write("\nFinal status file:\n") e.stat.write(file=moe.log.default.progress_file)