Esempio n. 1
0
def test_pass_no_unroll():
    j = 3
    @apply_passes([loop_unroll()])
    def foo():
        for i in range(j):
            print(i)
    assert inspect.getsource(foo) == """\
Esempio n. 2
0
def test_list_of_ints():
    j = [1, 2, 3]
    @apply_passes([loop_unroll()])
    def foo():
        for i in ast_tools.macros.unroll(j):
            print(i)
    assert inspect.getsource(foo) == """\
Esempio n. 3
0
def test_pass_nested():
    @apply_passes([loop_unroll()])
    def foo():
        for i in ast_tools.macros.unroll(range(2)):
            for j in ast_tools.macros.unroll(range(3)):
                print(i + j)
    assert inspect.getsource(foo) == """\
Esempio n. 4
0
def test_pass_env():
    j = 3
    @apply_passes([loop_unroll()])
    def foo():
        for i in ast_tools.macros.unroll(range(j)):
            print(i)
    assert inspect.getsource(foo) == """\
Esempio n. 5
0
def test_bad_iter():
    with pytest.raises(Exception):
        @apply_passes([loop_unroll()])
        def foo():
            count = 0
            for k in ast_tools.macros.unroll([object(), object()]):
                count += 1
            return count
Esempio n. 6
0
def test_pass_no_unroll_nested():
    j = 3
    @apply_passes([loop_unroll()])
    def foo():
        for i in range(j):
            for k in ast_tools.macros.unroll(range(3)):
                print(i * k)
    assert inspect.getsource(foo) == """\
Esempio n. 7
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self._passes = loop_unroll(), *self._passes