From d4c4a76ed1427c947fcbbe692625b3f644cf3aaf Mon Sep 17 00:00:00 2001 From: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> Date: Sat, 16 Apr 2022 19:59:52 +0100 Subject: gh-89770: Implement PEP-678 - Exception notes (GH-31317) --- Lib/test/test_exceptions.py | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'Lib/test/test_exceptions.py') 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: -- cgit v1.2.3