mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-89770: Implement PEP-678 - Exception notes (GH-31317)
This commit is contained in:
parent
7fa3a5a219
commit
d4c4a76ed1
12 changed files with 383 additions and 144 deletions
|
@ -547,26 +547,32 @@ class ExceptionTests(unittest.TestCase):
|
|||
'pickled "%r", attribute "%s' %
|
||||
(e, checkArgName))
|
||||
|
||||
def test_note(self):
|
||||
def test_notes(self):
|
||||
for e in [BaseException(1), Exception(2), ValueError(3)]:
|
||||
with self.subTest(e=e):
|
||||
self.assertIsNone(e.__note__)
|
||||
e.__note__ = "My Note"
|
||||
self.assertEqual(e.__note__, "My Note")
|
||||
self.assertFalse(hasattr(e, '__notes__'))
|
||||
e.add_note("My Note")
|
||||
self.assertEqual(e.__notes__, ["My Note"])
|
||||
|
||||
with self.assertRaises(TypeError):
|
||||
e.__note__ = 42
|
||||
self.assertEqual(e.__note__, "My Note")
|
||||
e.add_note(42)
|
||||
self.assertEqual(e.__notes__, ["My Note"])
|
||||
|
||||
e.__note__ = "Your Note"
|
||||
self.assertEqual(e.__note__, "Your Note")
|
||||
e.add_note("Your Note")
|
||||
self.assertEqual(e.__notes__, ["My Note", "Your Note"])
|
||||
|
||||
del e.__notes__
|
||||
self.assertFalse(hasattr(e, '__notes__'))
|
||||
|
||||
e.add_note("Our Note")
|
||||
self.assertEqual(e.__notes__, ["Our Note"])
|
||||
|
||||
e.__notes__ = 42
|
||||
self.assertEqual(e.__notes__, 42)
|
||||
|
||||
with self.assertRaises(TypeError):
|
||||
del e.__note__
|
||||
self.assertEqual(e.__note__, "Your Note")
|
||||
|
||||
e.__note__ = None
|
||||
self.assertIsNone(e.__note__)
|
||||
e.add_note("will not work")
|
||||
self.assertEqual(e.__notes__, 42)
|
||||
|
||||
def testWithTraceback(self):
|
||||
try:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue