From f807c4271e59a8016f15c8ba4763b0c2d92645a9 Mon Sep 17 00:00:00 2001 From: Andrew Hoos Date: Wed, 30 Nov 2016 15:07:51 -0800 Subject: Update change with tests and fixes for tests --- tests/test_process.py | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'tests/test_process.py') diff --git a/tests/test_process.py b/tests/test_process.py index 75d420a0..dda43ba8 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -785,6 +785,66 @@ class ProcessTest(CoverageTest): out = self.run_command("python -m coverage") self.assertIn("Use 'coverage help' for help", out) + def test_excepthook(self): + self.make_file("test_excepthook.py", """\ + import sys + + def excepthook(*args): + print('in excepthook') + + sys.excepthook = excepthook + + raise RuntimeError('Error Outside') + """) + cov_st, cov_out = self.run_command_status("coverage run test_excepthook.py") + py_st, py_out = self.run_command_status("python test_excepthook.py") + self.assertEqual(cov_st, py_st) + self.assertEqual(cov_st, 1) + + self.assertIn("in excepthook", py_out) + self.assertEqual(cov_out, py_out) + + def test_excepthook_exit(self): + self.make_file("test_excepthook_exit.py", """\ + import sys + + def excepthook(*args): + print('in excepthook') + sys.exit(0) + + sys.excepthook = excepthook + + raise RuntimeError('Error Outside') + """) + cov_st, cov_out = self.run_command_status("coverage run test_excepthook_exit.py") + py_st, py_out = self.run_command_status("python test_excepthook_exit.py") + self.assertEqual(cov_st, py_st) + self.assertEqual(cov_st, 0) + + self.assertIn("in excepthook", py_out) + self.assertEqual(cov_out, py_out) + + def test_excepthook_throw(self): + self.make_file("test_excepthook_exit.py", """\ + import sys + + def excepthook(*args): + print('in excepthook') + raise RuntimeError('Error Inside') + + sys.excepthook = excepthook + + raise RuntimeError('Error Outside') + """) + cov_st, cov_out = self.run_command_status("coverage run test_excepthook_exit.py") + py_st, py_out = self.run_command_status("python test_excepthook_exit.py") + self.assertEqual(cov_st, py_st) + self.assertEqual(cov_st, 0) + + self.assertIn("in excepthook", py_out) + self.assertEqual(cov_out, py_out) + + class AliasedCommandTest(CoverageTest): """Tests of the version-specific command aliases.""" -- cgit v1.2.1