summaryrefslogtreecommitdiff
path: root/Lib/test/test_sys_setprofile.py
diff options
context:
space:
mode:
authorPablo Galindo Salgado <Pablogsal@gmail.com>2022-07-05 19:52:33 +0100
committerGitHub <noreply@github.com>2022-07-05 19:52:33 +0100
commit5e24c80b948da6995990296cf262d9eae265e8ec (patch)
treeca0c20c8012eea7e14d34c7f1488587b88977b05 /Lib/test/test_sys_setprofile.py
parentfd34bfe48444fdb22ff1ae78941cf621854b351f (diff)
downloadcpython-git-5e24c80b948da6995990296cf262d9eae265e8ec.tar.gz
[3.10] gh-94510: Raise on re-entrant calls to sys.setprofile and syssettrace (GH-94511) (#94579)
Co-authored-by: Ɓukasz Langa <lukasz@langa.pl>. Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Diffstat (limited to 'Lib/test/test_sys_setprofile.py')
-rw-r--r--Lib/test/test_sys_setprofile.py39
1 files changed, 39 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()