Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(223)

Delta Between Two Patch Sets: Lib/test/test_exceptions.py

Issue 6210: Exception Chaining missing method for suppressing context
Left Patch Set: Created 1 year, 3 months ago
Right Patch Set: Created 1 year, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Include/pyerrors.h ('k') | Lib/test/test_raise.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # Python test set -- part 5, built-in exceptions 1 # Python test set -- part 5, built-in exceptions
2 2
3 import os 3 import os
4 import sys 4 import sys
5 import unittest 5 import unittest
6 import pickle 6 import pickle
7 import weakref 7 import weakref
8 import errno 8 import errno
9 9
10 from test.support import (TESTFN, unlink, run_unittest, captured_output, 10 from test.support import (TESTFN, unlink, run_unittest, captured_output,
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 except: 380 except:
381 tb = sys.exc_info()[2] 381 tb = sys.exc_info()[2]
382 382
383 e = Exception() 383 e = Exception()
384 e.__traceback__ = tb 384 e.__traceback__ = tb
385 e.__traceback__ = None 385 e.__traceback__ = None
386 self.assertEqual(e.__traceback__, None) 386 self.assertEqual(e.__traceback__, None)
387 387
388 def testChainingAttrs(self): 388 def testChainingAttrs(self):
389 e = Exception() 389 e = Exception()
390 self.assertEqual(e.__context__, None) 390 self.assertIsNone(e.__context__)
391 self.assertEqual(e.__cause__, False) 391 self.assertIs(e.__cause__, Ellipsis)
392 392
393 e = TypeError() 393 e = TypeError()
394 self.assertEqual(e.__context__, None) 394 self.assertIsNone(e.__context__)
395 self.assertEqual(e.__cause__, False) 395 self.assertIs(e.__cause__, Ellipsis)
396 396
397 class MyException(EnvironmentError): 397 class MyException(EnvironmentError):
398 pass 398 pass
399 399
400 e = MyException() 400 e = MyException()
401 self.assertEqual(e.__context__, None) 401 self.assertIsNone(e.__context__)
402 self.assertEqual(e.__cause__, False) 402 self.assertIs(e.__cause__, Ellipsis)
403
404 def testChainingDescriptors(self):
405 try:
406 raise Exception()
407 except Exception as exc:
408 e = exc
409
410 self.assertIsNone(e.__context__)
411 self.assertIs(e.__cause__, Ellipsis)
412
413 e.__context__ = NameError()
414 e.__cause__ = None
415 self.assertIsInstance(e.__context__, NameError)
416 self.assertIsNone(e.__cause__)
417
418 e.__cause__ = Ellipsis
419 self.assertIs(e.__cause__, Ellipsis)
403 420
404 def testKeywordArgs(self): 421 def testKeywordArgs(self):
405 # test that builtin exception don't take keyword args, 422 # test that builtin exception don't take keyword args,
406 # but user-defined subclasses can if they want 423 # but user-defined subclasses can if they want
407 self.assertRaises(TypeError, BaseException, a=1) 424 self.assertRaises(TypeError, BaseException, a=1)
408 425
409 class DerivedException(BaseException): 426 class DerivedException(BaseException):
410 def __init__(self, fancy_arg): 427 def __init__(self, fancy_arg):
411 BaseException.__init__(self) 428 BaseException.__init__(self)
412 self.fancy_arg = fancy_arg 429 self.fancy_arg = fancy_arg
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 with self.assertRaises(OSError) as cm: 900 with self.assertRaises(OSError) as cm:
884 os.listdir(__file__) 901 os.listdir(__file__)
885 self.assertEqual(cm.exception.errno, errno.ENOTDIR, cm.exception) 902 self.assertEqual(cm.exception.errno, errno.ENOTDIR, cm.exception)
886 903
887 904
888 def test_main(): 905 def test_main():
889 run_unittest(ExceptionTests) 906 run_unittest(ExceptionTests)
890 907
891 if __name__ == '__main__': 908 if __name__ == '__main__':
892 unittest.main() 909 unittest.main()
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld cbc36f91f3f7