def test_normal(self): output = StringIO() rep = reporter.JsonReporter(output) t1 = Task("t1", None) t2 = Task("t2", None) t3 = Task("t3", None) t4 = Task("t4", None) expected = {'t1':'fail', 't2':'up-to-date', 't3':'success', 't4':'ignore'} # t1 fail rep.get_status(t1) rep.execute_task(t1) rep.add_failure(t1, CatchedException('t1 failed!')) # t2 skipped rep.get_status(t2) rep.skip_uptodate(t2) # t3 success rep.get_status(t3) rep.execute_task(t3) rep.add_success(t3) # t4 ignore rep.get_status(t4) rep.skip_ignore(t4) rep.teardown_task(t4) rep.complete_run() got = json.loads(output.getvalue()) for task_result in got['tasks']: assert expected[task_result['name']] == task_result['result'], got if task_result['name'] == 't1': assert 't1 failed!' in task_result['error']
def test_complete_run_verbosity2(self): rep = reporter.ConsoleReporter(StringIO(), {}) catched = CatchedException("catched exception there", Exception("foo")) rep.add_failure(Task("t_name", None, verbosity=2), catched) # assign new StringIO so output is only from complete_run() rep.outstream = StringIO() rep.complete_run() got = rep.outstream.getvalue() assert "<stdout>" not in got assert "<stderr>" not in got
def _handle_grid_fail(cmd, out, err, retcode, tries, mem, time): exc = CatchedException("srun command failed: "+cmd +"\n"+out+"\n"+err) keep_going = False outerr = out+err if "Exceeded job memory limit" in outerr: used = re.search(r'memory limit \((\d+) > \d+\)', outerr).group(1) mem = int(used)/1024 * (1.3**tries) keep_going = True if re.search(r"due to time limit", outerr, re.IGNORECASE): time = time * (sigmoid(tries/10.)*2.7) keep_going = True return exc, keep_going, int(mem), int(time)
def test_complete_run_verbosity2_redisplay(self): rep = reporter.ConsoleReporter(StringIO(), {'failure_verbosity': 2}) catched = CatchedException("catched exception there", Exception("foo")) task = Task("t_name", None, verbosity=2) task.executed = True rep.add_failure(task, catched) # assign new StringIO so output is only from complete_run() rep.outstream = StringIO() rep.complete_run() got = rep.outstream.getvalue() assert "<stdout>" in got assert "<stderr>" in got
def test_addFailure(self): rep = reporter.ConsoleReporter(StringIO(), {}) try: raise Exception("original 中文 exception message here") except Exception as e: catched = CatchedException("catched exception there", e) rep.add_failure(Task("t_name", None), catched) rep.complete_run() got = rep.outstream.getvalue() # description assert "Exception: original 中文 exception message here" in got, got # traceback assert """raise Exception("original 中文 exception message here")""" in got # catched message assert "catched exception there" in got
def test_cleanup_error(self, capsys): output = StringIO() rep = reporter.JsonReporter(output) t1 = Task("t1", None) msg = "cleanup error" exception = CatchedException(msg) assert [] == rep.errors rep.get_status(t1) rep.execute_task(t1) rep.add_success(t1) rep.cleanup_error(exception) assert [msg+'\n'] == rep.errors assert "" in rep.outstream.getvalue() rep.complete_run() got = json.loads(output.getvalue()) assert msg in got['err']
def test_cleanupError(self, capsys): rep = reporter.ConsoleReporter(StringIO(), {}) exception = CatchedException("I got you") rep.cleanup_error(exception) err = capsys.readouterr()[1] assert "I got you" in err
def test_addFailure(self): rep = reporter.ConsoleReporter(io.StringIO(), {}) try: raise Exception("original exception message here") except Exception, e: catched = CatchedException("catched exception there", e)
def _handle_grid_fail(cmd, out, err, retcode, tries, mem, time): exc = CatchedException("Command failed: "+cmd+"\n"+out+"\n"+err) keep_going = False return exc, keep_going, int(mem), int(time)