summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_capi/test_watchers.py52
1 files changed, 50 insertions, 2 deletions
diff --git a/Lib/test/test_capi/test_watchers.py b/Lib/test/test_capi/test_watchers.py
index 1922614..93f6ef7 100644
--- a/Lib/test/test_capi/test_watchers.py
+++ b/Lib/test/test_capi/test_watchers.py
@@ -109,10 +109,21 @@ class TestDictWatchers(unittest.TestCase):
self.watch(wid, d)
with catch_unraisable_exception() as cm:
d["foo"] = "bar"
- self.assertIs(cm.unraisable.object, d)
+ self.assertIn(
+ "PyDict_EVENT_ADDED watcher callback for <dict at",
+ cm.unraisable.object
+ )
self.assertEqual(str(cm.unraisable.exc_value), "boom!")
self.assert_events([])
+ def test_dealloc_error(self):
+ d = {}
+ with self.watcher(kind=self.ERROR) as wid:
+ self.watch(wid, d)
+ with catch_unraisable_exception() as cm:
+ del d
+ self.assertEqual(str(cm.unraisable.exc_value), "boom!")
+
def test_two_watchers(self):
d1 = {}
d2 = {}
@@ -389,6 +400,25 @@ class TestCodeObjectWatchers(unittest.TestCase):
del co4
self.assert_event_counts(0, 0, 0, 0)
+ def test_error(self):
+ with self.code_watcher(2):
+ with catch_unraisable_exception() as cm:
+ co = _testcapi.code_newempty("test_watchers", "dummy0", 0)
+
+ self.assertEqual(
+ cm.unraisable.object,
+ f"PY_CODE_EVENT_CREATE watcher callback for {co!r}"
+ )
+ self.assertEqual(str(cm.unraisable.exc_value), "boom!")
+
+ def test_dealloc_error(self):
+ co = _testcapi.code_newempty("test_watchers", "dummy0", 0)
+ with self.code_watcher(2):
+ with catch_unraisable_exception() as cm:
+ del co
+
+ self.assertEqual(str(cm.unraisable.exc_value), "boom!")
+
def test_clear_out_of_range_watcher_id(self):
with self.assertRaisesRegex(ValueError, r"Invalid code watcher ID -1"):
_testcapi.clear_code_watcher(-1)
@@ -479,7 +509,25 @@ class TestFuncWatchers(unittest.TestCase):
def myfunc():
pass
- self.assertIs(cm.unraisable.object, myfunc)
+ self.assertEqual(
+ cm.unraisable.object,
+ f"PyFunction_EVENT_CREATE watcher callback for {myfunc!r}"
+ )
+
+ def test_dealloc_watcher_raises_error(self):
+ class MyError(Exception):
+ pass
+
+ def watcher(*args):
+ raise MyError("testing 123")
+
+ def myfunc():
+ pass
+
+ with self.add_watcher(watcher):
+ with catch_unraisable_exception() as cm:
+ del myfunc
+
self.assertIsInstance(cm.unraisable.exc_value, MyError)
def test_clear_out_of_range_watcher_id(self):