import copy import os import sys import unittest import pickle import weakref import errno from textwrap import dedent from test.support import (captured_stderr, check_impl_detail, cpython_only, gc_collect, no_tracing, script_helper, SuppressCrashReport, force_not_colorized) from test.support.import_helper import import_module from test.support.os_helper import TESTFN, unlink from test.support.warnings_helper import check_warnings from test import support def test_notes(self): for e in [BaseException(1), Exception(2), ValueError(3)]: with self.subTest(e=e): self.assertFalse(hasattr(e, '__notes__')) e.add_note("My Note") self.assertEqual(e.__notes__, ["My Note"]) with self.assertRaises(TypeError): e.add_note(42) self.assertEqual(e.__notes__, ["My 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): e.add_note("will not work") self.assertEqual(e.__notes__, 42)