| OLD | NEW |
| 1 # Copyright 2007 Google, Inc. All Rights Reserved. | 1 # Copyright 2007 Google, Inc. All Rights Reserved. |
| 2 # Licensed to PSF under a Contributor Agreement. | 2 # Licensed to PSF under a Contributor Agreement. |
| 3 | 3 |
| 4 """Tests for the raise statement.""" | 4 """Tests for the raise statement.""" |
| 5 | 5 |
| 6 from test import support | 6 from test import support |
| 7 import sys | 7 import sys |
| 8 import types | 8 import types |
| 9 import unittest | 9 import unittest |
| 10 | 10 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 | 69 |
| 70 def test_nested_reraise(self): | 70 def test_nested_reraise(self): |
| 71 def nested_reraise(): | 71 def nested_reraise(): |
| 72 raise | 72 raise |
| 73 def reraise(): | 73 def reraise(): |
| 74 try: | 74 try: |
| 75 raise TypeError("foo") | 75 raise TypeError("foo") |
| 76 except: | 76 except: |
| 77 nested_reraise() | 77 nested_reraise() |
| 78 self.assertRaises(TypeError, reraise) | 78 self.assertRaises(TypeError, reraise) |
| 79 |
| 80 def test_raise_from_None(self): |
| 81 try: |
| 82 try: |
| 83 raise TypeError("foo") |
| 84 except: |
| 85 raise ValueError() from None |
| 86 except ValueError as e: |
| 87 self.assertTrue(isinstance(e.__context__, TypeError)) |
| 88 self.assertIsNone(e.__cause__) |
| 79 | 89 |
| 80 def test_with_reraise1(self): | 90 def test_with_reraise1(self): |
| 81 def reraise(): | 91 def reraise(): |
| 82 try: | 92 try: |
| 83 raise TypeError("foo") | 93 raise TypeError("foo") |
| 84 except: | 94 except: |
| 85 with Context(): | 95 with Context(): |
| 86 pass | 96 pass |
| 87 raise | 97 raise |
| 88 self.assertRaises(TypeError, reraise) | 98 self.assertRaises(TypeError, reraise) |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 pass | 391 pass |
| 382 else: | 392 else: |
| 383 self.fail("No exception raised") | 393 self.fail("No exception raised") |
| 384 | 394 |
| 385 | 395 |
| 386 def test_main(): | 396 def test_main(): |
| 387 support.run_unittest(__name__) | 397 support.run_unittest(__name__) |
| 388 | 398 |
| 389 if __name__ == "__main__": | 399 if __name__ == "__main__": |
| 390 unittest.main() | 400 unittest.main() |
| OLD | NEW |