Commit 8b342daf authored by Stefan Behnel's avatar Stefan Behnel

add tests for 'raise ... from None'

parent 464f389c
import sys
import unittest import unittest
# adapted from pyregr # adapted from pyregr
class TestCause(unittest.TestCase): class TestCause(unittest.TestCase):
def test_invalid_cause(self): def test_invalid_cause(self):
...@@ -9,6 +12,30 @@ class TestCause(unittest.TestCase): ...@@ -9,6 +12,30 @@ class TestCause(unittest.TestCase):
else: else:
self.fail("No exception raised") self.fail("No exception raised")
def test_raise_from_none_sets_no_cause(self):
try:
raise IndexError from None
except IndexError as e:
self.assertFalse(e.__cause__)
if sys.version_info[:2] >= (3,3):
self.assertTrue(e.__suppress_context__)
else:
self.fail("No exception raised")
def test_raise_from_none_covers_context(self):
try:
try:
raise IndexError("INDEX")
except IndexError as e:
raise ValueError("VALUE") from None
else:
self.fail("No exception raised")
except ValueError as e:
self.assertFalse(e.__cause__)
self.assertTrue(e.__context__)
if sys.version_info[:2] >= (3,3):
self.assertTrue(e.__suppress_context__)
def test_class_cause(self): def test_class_cause(self):
try: try:
raise IndexError from KeyError raise IndexError from KeyError
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment