8000 Fix test_long_loop() (sort of) · python/cpython@0caa9f9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0caa9f9

Browse files
committed
Fix test_long_loop() (sort of)
1 parent 22f981b commit 0caa9f9

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

Lib/test/test_capi/test_misc.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2411,14 +2411,20 @@ def loop():
24112411
self.assertEqual(opt.get_count(), 1000)
24122412

24132413
def test_long_loop(self):
2414-
"Check that we aren't confused by EXTENDED_ARG"
2414+
# Check that we aren't confused by EXTENDED_ARG
24152415

24162416
# Generate a new function at each call
24172417
ns = {}
24182418
exec(textwrap.dedent("""
24192419
def nop():
24202420
pass
24212421
2422+
def short_loop():
2423+
for _ in range(10):
2424+
nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();
2425+
nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();
2426+
nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();
2427+
24222428
def long_loop():
24232429
for _ in range(10):
24242430
nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();
@@ -2429,14 +2435,21 @@ def long_loop():
24292435
nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();
24302436
nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();
24312437
"""), ns, ns)
2438+
short_loop = ns['short_loop']
24322439
long_loop = ns['long_loop']
24332440

24342441
opt = _testinternalcapi.get_counter_optimizer()
24352442
with temporary_optimizer(opt):
24362443
self.assertEqual(opt.get_count(), 0)
2437-
long_loop()
2444+
short_loop()
24382445
self.assertEqual(opt.get_count(), 10)
24392446

2447+
opt = _testinternalcapi.get_counter_optimizer()
2448+
with temporary_optimizer(opt):
2449+
self.assertEqual(opt.get_count(), 0)
2450+
long_loop() # Should not optimize!
2451+
self.assertEqual(opt.get_count(), 0)
2452+
24402453
def test_code_restore_for_ENTER_EXECUTOR(self):
24412454
def testfunc(x):
24422455
i = 0

0 commit comments

Comments
 (0)
0