Fix fake input behavior in tests on unexpected input.
Because of the mechanism for catching exceptions in pubs, the UnexpectedInput exception raised by FakeInput never reached the catch statement in the CommandTestCase and raised a FakeSystemExit instead. This commit monkey-patches the exception handler in the ui at the same time as the patching of the input functions to ignore UnexptectedInput at the ui level.
This commit is contained in:
parent
2f48f37199
commit
d8dc386a18
@ -77,6 +77,16 @@ class FakeInput():
|
|||||||
if md.__name__ == 'pubs.uis':
|
if md.__name__ == 'pubs.uis':
|
||||||
md.InputUI.editor_input = self
|
md.InputUI.editor_input = self
|
||||||
md.InputUI.edit_file = self.input_to_file
|
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):
|
def input_to_file(self, path_to_file, temporary=True):
|
||||||
content.write_file(path_to_file, self())
|
content.write_file(path_to_file, self())
|
||||||
|
@ -131,7 +131,7 @@ class CommandTestCase(fake_env.TestFakeFs):
|
|||||||
outs.append(color.undye(actual_out))
|
outs.append(color.undye(actual_out))
|
||||||
else:
|
else:
|
||||||
pubs_cmd.execute(actual_cmd.split())
|
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(
|
self.fail('Unexpected input asked by command: {}.'.format(
|
||||||
actual_cmd))
|
actual_cmd))
|
||||||
return outs
|
return outs
|
||||||
@ -682,13 +682,11 @@ class TestUsecase(DataCommandTestCase):
|
|||||||
self.assertFileContentEqual(os.path.expanduser('~/.pubsrc'),
|
self.assertFileContentEqual(os.path.expanduser('~/.pubsrc'),
|
||||||
str_fixtures.sample_conf)
|
str_fixtures.sample_conf)
|
||||||
|
|
||||||
def test_editor_abort(self):
|
def test_editor_aborts(self):
|
||||||
with self.assertRaises(FakeSystemExit):
|
with self.assertRaises(FakeSystemExit):
|
||||||
cmds = ['pubs init',
|
cmds = ['pubs init',
|
||||||
('pubs add', ['abc', 'n']),
|
|
||||||
('pubs add', ['abc', 'y', 'abc', 'n']),
|
|
||||||
'pubs add data/pagerank.bib',
|
'pubs add data/pagerank.bib',
|
||||||
('pubs edit Page99', ['', 'a']),
|
('pubs edit Page99', ['', 'n']),
|
||||||
]
|
]
|
||||||
self.execute_cmds(cmds)
|
self.execute_cmds(cmds)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user