From c020c6bbf7bb3879b671607d4a7a0f6f8a1bb9e7 Mon Sep 17 00:00:00 2001 From: Andrey Maltsev Date: Sun, 2 Apr 2023 13:55:46 +0000 Subject: [PATCH] Update test_dynamic.py from Cpython v3.11.2 --- Lib/test/test_dynamic.py | 58 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/Lib/test/test_dynamic.py b/Lib/test/test_dynamic.py index 3ae090fd66..2155b40289 100644 --- a/Lib/test/test_dynamic.py +++ b/Lib/test/test_dynamic.py @@ -1,6 +1,7 @@ # Test the most dynamic corner cases of Python's runtime semantics. import builtins +import sys import unittest from test.support import swap_item, swap_attr @@ -133,6 +134,63 @@ def test_eval_gives_lambda_custom_globals(self): self.assertEqual(foo(), 7) + # TODO: RUSTPYTHON + @unittest.expectedFailure + def test_load_global_specialization_failure_keeps_oparg(self): + # https://github.com/python/cpython/issues/91625 + class MyGlobals(dict): + def __missing__(self, key): + return int(key.removeprefix("_number_")) + + code = "lambda: " + "+".join(f"_number_{i}" for i in range(1000)) + sum_1000 = eval(code, MyGlobals()) + expected = sum(range(1000)) + # Warm up the the function for quickening (PEP 659) + for _ in range(30): + self.assertEqual(sum_1000(), expected) + + +class TestTracing(unittest.TestCase): + + def setUp(self): + self.addCleanup(sys.settrace, sys.gettrace()) + sys.settrace(None) + + def test_after_specialization(self): + + def trace(frame, event, arg): + return trace + + turn_on_trace = False + + class C: + def __init__(self, x): + self.x = x + def __del__(self): + if turn_on_trace: + sys.settrace(trace) + + def f(): + # LOAD_GLOBAL[_BUILTIN] immediately follows the call to C.__del__ + C(0).x, len + + def g(): + # BINARY_SUSCR[_LIST_INT] immediately follows the call to C.__del__ + [0][C(0).x] + + def h(): + # BINARY_OP[_ADD_INT] immediately follows the call to C.__del__ + 0 + C(0).x + + for func in (f, g, h): + with self.subTest(func.__name__): + for _ in range(58): + func() + turn_on_trace = True + func() + sys.settrace(None) + turn_on_trace = False + if __name__ == "__main__": unittest.main()