diff options
author | Chris Jerdonek <chris.jerdonek@gmail.com> | 2016-07-23 17:15:12 -0700 |
---|---|---|
committer | Chris Jerdonek <chris.jerdonek@gmail.com> | 2016-07-23 17:15:12 -0700 |
commit | 0c67be102f73f3b628af0d83ee5bc20190397133 (patch) | |
tree | 305cb333fa483ee4f0bc6c395ee54a245706c9d9 | |
parent | c3e170312df8d5efd64d33a55b7f66496117a86e (diff) | |
download | raven-0c67be102f73f3b628af0d83ee5bc20190397133.tar.gz |
Add failing tests for issue #550: exception chaining.
-rw-r--r-- | tests/events/tests.py | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/events/tests.py b/tests/events/tests.py new file mode 100644 index 0000000..cb100af --- /dev/null +++ b/tests/events/tests.py @@ -0,0 +1,68 @@ +from raven.utils.testutils import TestCase + +from raven.base import Client +from raven.events import Exception as ExceptionEvent + + +class ExceptionTest(TestCase): + + # Handle compatibility. + if hasattr(Exception, '__suppress_context__'): + # Then exception chains are supported. + def transform_expected(self, expected): + return expected + else: + # Otherwise, we only report the first element. + def transform_expected(self, expected): + return expected[:1] + + def check_capture(self, expected): + """ + Check the return value of capture(). + + Args: + expected: the expected "type" values. + """ + c = Client() + event = ExceptionEvent(c) + result = event.capture() + info = result['exception'] + values = info['values'] + + type_names = [value['type'] for value in values] + expected = self.transform_expected(expected) + + self.assertEqual(type_names, expected) + + def test_simple(self): + try: + raise ValueError() + except Exception: + self.check_capture(['ValueError']) + + def test_nested(self): + try: + raise ValueError() + except Exception: + try: + raise KeyError() + except Exception: + self.check_capture(['KeyError', 'ValueError']) + + def test_raise_from(self): + try: + raise ValueError() + except Exception as exc: + try: + raise KeyError() from exc + except Exception: + self.check_capture(['KeyError', 'ValueError']) + + def test_raise_from_different(self): + try: + raise ValueError() + except Exception as exc: + try: + raise KeyError() from TypeError() + except Exception: + self.check_capture(['KeyError', 'TypeError']) |