summaryrefslogtreecommitdiff
path: root/tests/test_process.py
diff options
context:
space:
mode:
authorAndrew Hoos <andrewjhoos@gmail.com>2016-11-30 15:07:51 -0800
committerAndrew Hoos <andrewjhoos@gmail.com>2016-11-30 15:07:51 -0800
commit8ccdedf3ec46cb51130af886be36b85b9e3015b7 (patch)
treeb2966d8733706c8db8203199cff0ce00f7afe9ad /tests/test_process.py
parentd1da15f12e248954adc1d6bf222304ba1e16f9d9 (diff)
downloadpython-coveragepy-8ccdedf3ec46cb51130af886be36b85b9e3015b7.tar.gz
Update change with tests and fixes for tests
Diffstat (limited to 'tests/test_process.py')
-rw-r--r--tests/test_process.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/test_process.py b/tests/test_process.py
index 75d420a..dda43ba 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."""