| 1 |
import pytest, sys |
| 2 |
from pypy.module.pypyjit.test_pypy_c.test_00_model import BaseTestPyPyC |
| 3 |
|
| 4 |
|
| 5 |
class TestMisc(BaseTestPyPyC): |
| 6 |
def test_islice_step_is_1(self): |
| 7 |
def f1(n): |
| 8 |
import itertools |
| 9 |
l = [1] * 10000 |
| 10 |
res = 0 |
| 11 |
for x in itertools.islice(l, n): |
| 12 |
res += x |
| 13 |
return res |
| 14 |
log = self.run(f1, [2117]) |
| 15 |
assert log.result == 2117 |
| 16 |
loop, = log.loops_by_filename(self.filepath) |
| 17 |
opnames = log.opnames(loop.allops()) |
| 18 |
assert not any("call" in name for name in opnames) |
| 19 |
|
| 20 |
def test_islice_uses_greenkey(self): |
| 21 |
def f1(n): |
| 22 |
def f(a): |
| 23 |
return a + 1 |
| 24 |
def g(a): |
| 25 |
return a + 2 |
| 26 |
import itertools |
| 27 |
l = [1] * 10000 |
| 28 |
res = 0 |
| 29 |
for x in itertools.islice(map(f, l), 0, n, 2000): |
| 30 |
res += x |
| 31 |
for x in itertools.islice(map(g, l), 0, n, 2000): |
| 32 |
res += x |
| 33 |
return res |
| 34 |
log = self.run(f1, [2117]) |
| 35 |
|
| 36 |
loop0, loop1 = [loop for loop in log.loops if 'islice_ignore_items' in str(loop)] |
| 37 |
assert not any(getattr(op, 'bridge', None) is not None for op in loop0.allops()) |