def test_render_exception(self): """ Application.render_exception() displays formatted exception. """ application = Application() application.set_auto_exit(False) application.get_terminal_width = self.mock().MagicMock(return_value=120) tester = ApplicationTester(application) tester.run([("command", "foo")], {"decorated": False}) self.assertEqual(self.open_fixture("application_renderexception1.txt"), tester.get_display()) tester.run([("command", "foo")], {"decorated": False, "verbosity": Output.VERBOSITY_VERBOSE}) self.assertRegex(tester.get_display(), "Exception trace") tester.run([("command", "list"), ("--foo", True)], {"decorated": False}) self.assertEqual(self.open_fixture("application_renderexception2.txt"), tester.get_display()) application.add(Foo3Command()) tester = ApplicationTester(application) tester.run([("command", "foo3:bar")], {"decorated": False}) self.assertEqual(self.open_fixture("application_renderexception3.txt"), tester.get_display()) tester = ApplicationTester(application) tester.run([("command", "foo3:bar")], {"decorated": True}) self.assertEqual(self.open_fixture("application_renderexception3decorated.txt"), tester.get_display()) application = Application() application.set_auto_exit(False) application.get_terminal_width = self.mock().MagicMock(return_value=31) tester = ApplicationTester(application) tester.run([("command", "foo")], {"decorated": False}) self.assertEqual(self.open_fixture("application_renderexception4.txt"), tester.get_display())
def test_render_exception(self): """ Application.render_exception() displays formatted exception. """ application = Application() application.set_auto_exit(False) application.get_terminal_width = self.mock().MagicMock(return_value=120) tester = ApplicationTester(application) tester.run([('command', 'foo')], {'decorated': False}) self.assertEqual( self.open_fixture('application_renderexception1.txt'), tester.get_display() ) tester.run([('command', 'foo')], {'decorated': False, 'verbosity': Output.VERBOSITY_VERBOSE}) self.assertRegex( tester.get_display(), 'Exception trace' ) tester.run([('command', 'list'), ('--foo', True)], {'decorated': False}) self.assertEqual( self.open_fixture('application_renderexception2.txt'), tester.get_display() ) application.add(Foo3Command()) tester = ApplicationTester(application) tester.run([('command', 'foo3:bar')], {'decorated': False}) self.assertEqual( self.open_fixture('application_renderexception3.txt'), tester.get_display() ) tester = ApplicationTester(application) tester.run([('command', 'foo3:bar')], {'decorated': True}) self.assertEqual( self.open_fixture('application_renderexception3decorated.txt'), tester.get_display() ) application = Application() application.set_auto_exit(False) application.get_terminal_width = self.mock().MagicMock(return_value=31) tester = ApplicationTester(application) tester.run([('command', 'foo')], {'decorated': False}) self.assertEqual( self.open_fixture('application_renderexception4.txt'), tester.get_display() )
def test_set_catch_exceptions(self): application = Application() application.set_auto_exit(False) application.get_terminal_width = self.mock().MagicMock(return_value=120) tester = ApplicationTester(application) application.set_catch_exceptions(True) tester.run([("command", "foo")], {"decorated": False}) self.assertEqual(self.open_fixture("application_renderexception1.txt"), tester.get_display()) application.set_catch_exceptions(False) try: tester.run([("command", "foo")], {"decorated": False}) self.fail(".set_catch_exceptions() sets the catch exception flag") except Exception as e: self.assertEqual('Command "foo" is not defined.', str(e))
def test_set_catch_exceptions(self): application = Application() application.set_auto_exit(False) application.get_terminal_width = self.mock().MagicMock(return_value=120) tester = ApplicationTester(application) application.set_catch_exceptions(True) tester.run([('command', 'foo')], {'decorated': False}) self.assertEqual( self.open_fixture('application_renderexception1.txt'), tester.get_display() ) application.set_catch_exceptions(False) try: tester.run([('command', 'foo')], {'decorated': False}) self.fail('.set_catch_exceptions() sets the catch exception flag') except Exception as e: self.assertEqual('Command "foo" is not defined.', str(e))