diff options
author | Irit Katriel <1055913+iritkatriel@users.noreply.github.com> | 2022-04-16 19:59:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-16 19:59:52 +0100 |
commit | d4c4a76ed1427c947fcbbe692625b3f644cf3aaf (patch) | |
tree | 2e503da40ff6459711ff5730b22e89962b175252 /Lib/test/test_exceptions.py | |
parent | 7fa3a5a2197896066e3fe53ee325ac6ab54c3414 (diff) | |
download | cpython-d4c4a76ed1427c947fcbbe692625b3f644cf3aaf.tar.gz cpython-d4c4a76ed1427c947fcbbe692625b3f644cf3aaf.zip |
gh-89770: Implement PEP-678 - Exception notes (GH-31317)
Diffstat (limited to 'Lib/test/test_exceptions.py')
-rw-r--r-- | Lib/test/test_exceptions.py | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index 6dca79efef1..2b5b5193456 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -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"]) - with self.assertRaises(TypeError): - del e.__note__ - self.assertEqual(e.__note__, "Your Note") + del e.__notes__ + self.assertFalse(hasattr(e, '__notes__')) + + e.add_note("Our Note") + self.assertEqual(e.__notes__, ["Our Note"]) - e.__note__ = None - self.assertIsNone(e.__note__) + e.__notes__ = 42 + self.assertEqual(e.__notes__, 42) + + with self.assertRaises(TypeError): + e.add_note("will not work") + self.assertEqual(e.__notes__, 42) def testWithTraceback(self): try: |