Beispiel #1
0
    def wrapper(func):
        if progress_bar:
            wrapped_func = inline(
                progress_pre_func,
                func,
                dict(
                    queue=queue,
                    index=index,
                    counter=counter,
                    progression=PROGRESSION,
                    state=state,
                    time=time,
                ),
            )
            return wrapped_func

        return func
def test_inline():
    python_version = sys.version_info
    if not (python_version.major == 3 and python_version.minor in (5, 6, 7)):
        with pytest.raises(SystemError):
            inliner.get_b_transitions(transitions, byte_source, byte_dest)
        return

    def pre_func(b, c):
        a = "hello"
        print(a + " " + b + " " + c)

    def func(x, y):
        try:
            if x > y:
                z = x + 2 * math.sin(y)
                return z**2
            elif x == y:
                return 4
            else:
                return 2**3
        except ValueError:
            foo = 0
            for i in range(4):
                foo += i
            return foo
        except TypeError:
            return 42
        else:
            return 33
        finally:
            print("finished")

    def target_inlined_func(x, y):
        # Pinned pre_func
        a = "hello"
        print(a + " " + "pretty" + " " + "world!")

        # func
        try:
            if x > y:
                z = x + 2 * math.sin(y)
                return z**2
            elif x == y:
                return 4
            else:
                return 2**3
        except ValueError:
            foo = 0
            for i in range(4):
                foo += i
            return foo
        except TypeError:
            return 42
        else:
            return 33
        finally:
            print("finished")

    inlined_func = inliner.inline(pre_func, func, dict(b="pretty", c="world!"))

    assert inliner.are_functions_equivalent(inlined_func, target_inlined_func)