summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_cprofile.py
diff options
context:
space:
mode:
authorTian Gao <gaogaotiantian@hotmail.com>2023-05-05 17:38:47 (GMT)
committerGitHub <noreply@github.com>2023-05-05 17:38:47 (GMT)
commitb9797417315cc2d1700cb2d427685016d3380711 (patch)
treeedc2b967a95b6b63a324e904db4b22249fd3bf9d /Lib/test/test_cprofile.py
parenta0df9ee8fc77443510ab7e9ba8fd830f255a8fec (diff)
downloadcpython-b9797417315cc2d1700cb2d427685016d3380711.zip
cpython-b9797417315cc2d1700cb2d427685016d3380711.tar.gz
cpython-b9797417315cc2d1700cb2d427685016d3380711.tar.bz2
gh-103533: Use PEP 669 APIs for cprofile (GH-103534)
Diffstat (limited to 'Lib/test/test_cprofile.py')
-rw-r--r--Lib/test/test_cprofile.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/Lib/test/test_cprofile.py b/Lib/test/test_cprofile.py
index 9864852..484b8f8 100644
--- a/Lib/test/test_cprofile.py
+++ b/Lib/test/test_cprofile.py
@@ -25,7 +25,6 @@ class CProfileTest(ProfileTest):
with support.catch_unraisable_exception() as cm:
obj = _lsprof.Profiler(lambda: int)
obj.enable()
- obj = _lsprof.Profiler(1)
obj.disable()
obj.clear()
@@ -37,10 +36,11 @@ class CProfileTest(ProfileTest):
self.addCleanup(prof.disable)
prof.enable()
- self.assertIs(sys.getprofile(), prof)
+ self.assertEqual(
+ sys.monitoring.get_tool(sys.monitoring.PROFILER_ID), "cProfile")
prof.disable()
- self.assertIs(sys.getprofile(), None)
+ self.assertIs(sys.monitoring.get_tool(sys.monitoring.PROFILER_ID), None)
def test_profile_as_context_manager(self):
prof = self.profilerclass()
@@ -53,10 +53,19 @@ class CProfileTest(ProfileTest):
# profile should be set as the global profiler inside the
# with-block
- self.assertIs(sys.getprofile(), prof)
+ self.assertEqual(
+ sys.monitoring.get_tool(sys.monitoring.PROFILER_ID), "cProfile")
# profile shouldn't be set once we leave the with-block.
- self.assertIs(sys.getprofile(), None)
+ self.assertIs(sys.monitoring.get_tool(sys.monitoring.PROFILER_ID), None)
+
+ def test_second_profiler(self):
+ pr = self.profilerclass()
+ pr2 = self.profilerclass()
+ pr.enable()
+ self.assertRaises(ValueError, pr2.enable)
+ pr.disable()
+
class TestCommandLine(unittest.TestCase):
def test_sort(self):