def test_can_get_source_of_functions_from_exec():
    assert 'foo(x)' in inspect.getsource(
        source_exec_as_module(DEFINE_FOO_FUNCTION).foo
    )
def test_exec_as_module_caches():
    assert (
        source_exec_as_module(DEFINE_FOO_FUNCTION) is
        source_exec_as_module(DEFINE_FOO_FUNCTION)
    )
def test_exec_leaves_sys_path_unchanged():
    old_path = deepcopy(sys.path)
    source_exec_as_module('hello_world = 42')
    assert sys.path == old_path
def test_can_call_self_recursively():
    source_exec_as_module(RECURSIVE).test_recurse()
def test_exec_as_module_execs():
    m = source_exec_as_module(DEFINE_FOO_FUNCTION)
    assert m.foo(1) == 1
def test_can_eval_as_source():
    assert source_exec_as_module('foo=1').foo == 1
def test_caches():
    x = source_exec_as_module('foo=2')
    y = source_exec_as_module('foo=2')
    assert x is y
def test_exec_as_module_caches():
    assert source_exec_as_module(DEFINE_FOO_FUNCTION) is source_exec_as_module(
        DEFINE_FOO_FUNCTION)
def test_exec_leaves_sys_path_unchanged():
    old_path = deepcopy(sys.path)
    source_exec_as_module("hello_world = 42")
    assert sys.path == old_path
def test_exec_as_module_execs():
    m = source_exec_as_module(DEFINE_FOO_FUNCTION)
    assert m.foo(1) == 1
Exemple #11
0
def test_does_not_put_eval_directory_on_path():
    source_exec_as_module("hello = 'world'")
    assert eval_directory() not in sys.path
Exemple #12
0
def test_can_get_source_of_functions_from_exec():
    assert u'foo(x)' in inspect.getsource(
        source_exec_as_module(DEFINE_FOO_FUNCTION).foo)
def test_caches():
    x = source_exec_as_module("foo=2")
    y = source_exec_as_module("foo=2")
    assert x is y
def test_does_not_put_eval_directory_on_path():
    source_exec_as_module("hello = 'world'")
    assert eval_directory() not in sys.path