def test_pass_no_unroll(): j = 3 @apply_passes([loop_unroll()]) def foo(): for i in range(j): print(i) assert inspect.getsource(foo) == """\
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) == """\
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) == """\
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) == """\
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
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) == """\
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self._passes = loop_unroll(), *self._passes