summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_dis.py
diff options
context:
space:
mode:
authorBrandt Bucher <brandtbucher@gmail.com>2022-05-06 14:18:09 (GMT)
committerGitHub <noreply@github.com>2022-05-06 14:18:09 (GMT)
commit93a666b5a56919a3633a3897dfdb9bddfb9614f0 (patch)
tree3567f32fdf0aa2787c06e1aa5bac3cd2237339e9 /Lib/test/test_dis.py
parenta79001ee16b3ea8b5d0fad595c969d9e1b7627f3 (diff)
downloadcpython-93a666b5a56919a3633a3897dfdb9bddfb9614f0.zip
cpython-93a666b5a56919a3633a3897dfdb9bddfb9614f0.tar.gz
cpython-93a666b5a56919a3633a3897dfdb9bddfb9614f0.tar.bz2
gh-90997: Show cached inline values in `dis` output (#92360)
Diffstat (limited to 'Lib/test/test_dis.py')
-rw-r--r--Lib/test/test_dis.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py
index b8d1c54..202b998 100644
--- a/Lib/test/test_dis.py
+++ b/Lib/test/test_dis.py
@@ -1011,6 +1011,37 @@ class DisTests(DisTestBase):
got = self.get_disassembly(loop_test, adaptive=True)
self.do_disassembly_compare(got, dis_loop_test_quickened_code, True)
+ def get_cached_values(self, quickened, adaptive):
+ def f():
+ l = []
+ for i in range(42):
+ l.append(i)
+ if quickened:
+ self.code_quicken(f)
+ else:
+ # "copy" the code to un-quicken it:
+ f.__code__ = f.__code__.replace()
+ for instruction in dis.get_instructions(
+ f, show_caches=True, adaptive=adaptive
+ ):
+ if instruction.opname == "CACHE":
+ yield instruction.argrepr
+
+ @cpython_only
+ def test_show_caches(self):
+ for quickened in (False, True):
+ for adaptive in (False, True):
+ with self.subTest(f"{quickened=}, {adaptive=}"):
+ if quickened and adaptive:
+ pattern = r"^(\w+: \d+)?$"
+ else:
+ pattern = r"^(\w+: 0)?$"
+ caches = list(self.get_cached_values(quickened, adaptive))
+ for cache in caches:
+ self.assertRegex(cache, pattern)
+ self.assertEqual(caches.count(""), 8)
+ self.assertEqual(len(caches), 25)
+
class DisWithFileTests(DisTests):