def test_formats_correctly(self): expected_formatted_tb = ['Traceback:\n', 'stuff\n', 'more stuff\n'] expected_ex = ValueError('test') expected_formatted_tb_str =\ """Traceback:\nstuff\nmore stuff\nValueError('test',)""" expected_ec = ExceptionContext( value=expected_ex, formatted_traceback=expected_formatted_tb_str) expected_tb = mock.Mock() mock_exc_info = (None, expected_ex, expected_tb) with mock.patch.object( vimap.exception_handling.sys, 'exc_info', autospec=True, return_value=mock_exc_info, ): with mock.patch.object( vimap.exception_handling.traceback, 'format_tb', autospec=True, return_value=expected_formatted_tb, ): found_ec = ExceptionContext.current() T.assert_equal(found_ec, expected_ec)
def test_no_exception_currently(self): with T.assert_raises(TypeError): ExceptionContext.current()