diff --git a/tests/fake_env.py b/tests/fake_env.py index 2e2a5c7..2bc9a51 100644 --- a/tests/fake_env.py +++ b/tests/fake_env.py @@ -77,6 +77,16 @@ class FakeInput(): if md.__name__ == 'pubs.uis': md.InputUI.editor_input = self md.InputUI.edit_file = self.input_to_file + # Do not catch UnexpectedInput + original_handler = md.InputUI.handle_exception + + def handler(ui, exc): + if isinstance(exc, self.UnexpectedInput): + raise + else: + original_handler(ui, exc) + + md.InputUI.handle_exception = handler def input_to_file(self, path_to_file, temporary=True): content.write_file(path_to_file, self()) diff --git a/tests/test_usecase.py b/tests/test_usecase.py index 4f3d805..bdc1de5 100644 --- a/tests/test_usecase.py +++ b/tests/test_usecase.py @@ -131,7 +131,7 @@ class CommandTestCase(fake_env.TestFakeFs): outs.append(color.undye(actual_out)) else: pubs_cmd.execute(actual_cmd.split()) - except fake_env.FakeInput.UnexpectedInput as e: + except fake_env.FakeInput.UnexpectedInput: self.fail('Unexpected input asked by command: {}.'.format( actual_cmd)) return outs @@ -200,7 +200,7 @@ class TestAlone(CommandTestCase): def test_alone_misses_command(self): with self.assertRaises(FakeSystemExit) as cm: self.execute_cmds(['pubs']) - self.assertEqual(cm.exception.code, 2) + self.assertEqual(cm.exception.code, 2) def test_alone_prints_help(self): # capturing the output of `pubs --help` is difficult because argparse @@ -682,13 +682,11 @@ class TestUsecase(DataCommandTestCase): self.assertFileContentEqual(os.path.expanduser('~/.pubsrc'), str_fixtures.sample_conf) - def test_editor_abort(self): + def test_editor_aborts(self): with self.assertRaises(FakeSystemExit): cmds = ['pubs init', - ('pubs add', ['abc', 'n']), - ('pubs add', ['abc', 'y', 'abc', 'n']), 'pubs add data/pagerank.bib', - ('pubs edit Page99', ['', 'a']), + ('pubs edit Page99', ['', 'n']), ] self.execute_cmds(cmds)