예제 #1
0
def test_decorator_runtime_code_replace():
    remove_test_modules()
    from tests.patcher.first import decorated_func, another_decorated_func

    result = decorated_func(1)
    assert result == 2

    result = another_decorated_func(3)
    assert result == 16

    code = '''
def decorator(func):
    def inner(x):
        return func(x+3)

    return inner
    '''

    patch('tests.patcher.first', code)

    result = decorated_func(1)
    assert result == 4

    result = another_decorated_func(3)
    assert result == 36
예제 #2
0
def test_decorated_funcs_runtime_code_replace():
    remove_test_modules()
    from tests.patcher.first import decorated_func, another_decorated_func

    result = decorated_func(1)
    assert result == 2

    result = another_decorated_func(3)
    assert result == 16

    code = '''
@decorator
def decorated_func(x):
    return x + 1
    '''

    patch('tests.patcher.first', code)

    result = decorated_func(1)
    assert result == 3

    result = another_decorated_func(3)
    assert result == 16