summaryrefslogtreecommitdiff
path: root/Lib/test
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_sys_setprofile.py39
-rw-r--r--Lib/test/test_sys_settrace.py39
2 files changed, 78 insertions, 0 deletions
diff --git a/Lib/test/test_sys_setprofile.py b/Lib/test/test_sys_setprofile.py
index 21a09b5192..4c3053a1e3 100644
--- a/Lib/test/test_sys_setprofile.py
+++ b/Lib/test/test_sys_setprofile.py
@@ -2,6 +2,7 @@ import gc
import pprint
import sys
import unittest
+from test import support
class TestGetProfile(unittest.TestCase):
@@ -415,5 +416,43 @@ def show_events(callable):
pprint.pprint(capture_events(callable))
+class TestEdgeCases(unittest.TestCase):
+
+ def setUp(self):
+ self.addCleanup(sys.setprofile, sys.getprofile())
+ sys.setprofile(None)
+
+ def test_reentrancy(self):
+ def foo(*args):
+ ...
+
+ def bar(*args):
+ ...
+
+ class A:
+ def __call__(self, *args):
+ pass
+
+ def __del__(self):
+ sys.setprofile(bar)
+
+ sys.setprofile(A())
+ with support.catch_unraisable_exception() as cm:
+ sys.setprofile(foo)
+ self.assertEqual(cm.unraisable.object, A.__del__)
+ self.assertIsInstance(cm.unraisable.exc_value, RuntimeError)
+
+ self.assertEqual(sys.getprofile(), foo)
+
+
+ def test_same_object(self):
+ def foo(*args):
+ ...
+
+ sys.setprofile(foo)
+ del foo
+ sys.setprofile(sys.getprofile())
+
+
if __name__ == "__main__":
unittest.main()
diff --git a/Lib/test/test_sys_settrace.py b/Lib/test/test_sys_settrace.py
index 4b3d096f16..1f509eee55 100644
--- a/Lib/test/test_sys_settrace.py
+++ b/Lib/test/test_sys_settrace.py
@@ -2,6 +2,7 @@
from test import support
import unittest
+from unittest.mock import MagicMock
import sys
import difflib
import gc
@@ -2196,5 +2197,43 @@ output.append(4)
output.append(8)
+class TestEdgeCases(unittest.TestCase):
+
+ def setUp(self):
+ self.addCleanup(sys.settrace, sys.gettrace())
+ sys.settrace(None)
+
+ def test_reentrancy(self):
+ def foo(*args):
+ ...
+
+ def bar(*args):
+ ...
+
+ class A:
+ def __call__(self, *args):
+ pass
+
+ def __del__(self):
+ sys.settrace(bar)
+
+ sys.settrace(A())
+ with support.catch_unraisable_exception() as cm:
+ sys.settrace(foo)
+ self.assertEqual(cm.unraisable.object, A.__del__)
+ self.assertIsInstance(cm.unraisable.exc_value, RuntimeError)
+
+ self.assertEqual(sys.gettrace(), foo)
+
+
+ def test_same_object(self):
+ def foo(*args):
+ ...
+
+ sys.settrace(foo)
+ del foo
+ sys.settrace(sys.gettrace())
+
+
if __name__ == "__main__":
unittest.main()