Esempio n. 1
0
def load_symbol_wrap_exc_eval_1():
    def foo31617859():
        1 / 0

    ns = [{"foo": foo31617859()}]
    try:
        load_symbol("foo()", ns, auto_eval=True)
    except LoadSymbolError as e:
        assert type(e.__cause__) == ZeroDivisionError
    else:
        assert False
Esempio n. 2
0
def load_symbol_wrap_exc_eval_getattr_1():
    class Foo15356301(object):
        def __getattr__(self, k):
            1 / 0

    ns = [{"foo": Foo15356301()}]
    try:
        load_symbol("foo.bar", ns, auto_eval=True)
    except LoadSymbolError as e:
        assert type(e.__cause__) == ZeroDivisionError
    else:
        assert False
Esempio n. 3
0
def load_symbol_wrap_exc_1():
    class Foo89503828(object):
        def __getattr__(self, k):
            1 / 0

    ns = [{"foo": Foo89503828()}]
    try:
        load_symbol("foo.bar", ns)
    except LoadSymbolError as e:
        assert type(e.__cause__) == ZeroDivisionError
    else:
        assert False
Esempio n. 4
0
def load_symbol_eval_2(capsys):
    assert '/' == load_symbol("(os.path.sep[0])", {},
                              autoimport=True,
                              allow_eval=True)
    out, _ = capsys.readouterr()
    expected = dedent("""
        [PYFLYBY] import os
    """).lstrip()
    assert expected == out
Esempio n. 5
0
def load_symbol_no_eval_1():
    with pytest.raises(LoadSymbolError):
        load_symbol("os.path.join('a','b')", {"os": os})
    with pytest.raises(LoadSymbolError):
        load_symbol("os.path.join('a','b')[1]", {"os": os})
    with pytest.raises(LoadSymbolError):
        load_symbol("os.path.join('a','b')[0].upper", {"os": os})
Esempio n. 6
0
def load_symbol_eval_1():
    assert 'a/b' == load_symbol("os.path.join('a','b')", {"os": os})
    assert '/' == load_symbol("os.path.join('a','b')[1]", {"os": os})
    assert 'A' == load_symbol("os.path.join('a','b')[0].upper()", {"os": os})
Esempio n. 7
0
def test_load_symbol_missing_2():
    with pytest.raises(LoadSymbolError):
        load_symbol("os.path.join", {})
Esempio n. 8
0
def test_load_symbol_missing_1():
    with pytest.raises(LoadSymbolError):
        load_symbol("os.path.join.asdfasdf", {"os": os})
Esempio n. 9
0
def test_load_symbol_2():
    assert load_symbol("os.path.join.func_name", {"os": os}) == "join"
Esempio n. 10
0
def test_load_symbol_1():
    assert load_symbol("os.path.join", {"os": os}) is os.path.join