コード例 #1
0
ファイル: test_autoimp.py プロジェクト: rsaim/pyflyby
def test_auto_eval_proxy_module_1(tpp, capsys):
    os.mkdir("%s/tornado83183065" % tpp)
    writetext(
        tpp / "tornado83183065/__init__.py", """
        import sys
        twister = 54170888
        class P:
            def __getattr__(self, K):
                k = K.lower()
                if k == K:
                    raise AttributeError
                else:
                    return getattr(self, k)
        p = P()
        p.__dict__ = globals()
        p._m = sys.modules[__name__]
        sys.modules[__name__] = p
    """)
    writetext(tpp / "tornado83183065/hurricane.py", """
        cyclone = 79943637
    """)
    # Verify that we can auto-import a sub-module of a proxy module.
    result = auto_eval("tornado83183065.hurricane.cyclone")
    out, _ = capsys.readouterr()
    expected = dedent("""
        [PYFLYBY] import tornado83183065
        [PYFLYBY] import tornado83183065.hurricane
    """).lstrip()
    assert out == expected
    assert result == 79943637
    # Verify that the proxy module can do its magic stuff.
    result = auto_eval("tornado83183065.TWISTER")
    out, _ = capsys.readouterr()
    assert out == "[PYFLYBY] import tornado83183065\n"
    assert result == 54170888
    # Verify that the proxy module can do its magic stuff with a submodule
    # that's already imported.
    result = auto_eval("tornado83183065.HURRICANE.cyclone")
    out, _ = capsys.readouterr()
    assert out == "[PYFLYBY] import tornado83183065\n"
    assert result == 79943637
コード例 #2
0
ファイル: test_autoimp.py プロジェクト: rsaim/pyflyby
def test_auto_eval_auto_flags_ps_flag_pf1(capsys):
    auto_eval("print 3.00", flags="print_function", auto_flags=True)
    out, _ = capsys.readouterr()
    assert out == "3.0\n"
コード例 #3
0
ファイル: test_autoimp.py プロジェクト: rsaim/pyflyby
def test_auto_eval_auto_flags_pf_flag_pf1(capsys):
    auto_eval("print(3.00, file=sys.stdout)",
              flags="print_function",
              auto_flags=True)
    out, _ = capsys.readouterr()
    assert out == "[PYFLYBY] import sys\n3.0\n"
コード例 #4
0
ファイル: test_autoimp.py プロジェクト: rsaim/pyflyby
def test_auto_eval_no_auto_flags_pf_flagps_1():
    with pytest.raises(SyntaxError):
        auto_eval("print(3.00, file=sys.stdout)", flags=0, auto_flags=False)
コード例 #5
0
ファイル: test_autoimp.py プロジェクト: rsaim/pyflyby
def test_auto_eval_auto_flags_ps_flagps_1(capsys):
    auto_eval("print 3.00", flags=0, auto_flags=True)
    out, _ = capsys.readouterr()
    assert out == "3.0\n"
コード例 #6
0
ファイル: test_autoimp.py プロジェクト: rsaim/pyflyby
def test_auto_eval_no_auto_flags_ps_flag_pf1():
    with pytest.raises(SyntaxError):
        auto_eval("print 3.00", flags="print_function", auto_flags=False)
コード例 #7
0
ファイル: test_autoimp.py プロジェクト: rsaim/pyflyby
def test_auto_eval_exec_1():
    mylocals = dict(x=[])
    auto_eval("if True: x.append(b64decode('aGVsbG8='))", locals=mylocals)
    assert mylocals['x'] == ['hello']
    assert mylocals["b64decode"] is __import__("base64").b64decode
コード例 #8
0
ファイル: test_autoimp.py プロジェクト: rsaim/pyflyby
def test_auto_eval_custom_globals_1():
    result = auto_eval("b64decode('aGVsbG8=')",
                       globals=dict(b64decode=lambda x: "blah"))
    assert result == 'blah'
コード例 #9
0
ファイル: test_autoimp.py プロジェクト: rsaim/pyflyby
def test_auto_eval_globals_import_1():
    myglobals = {}
    result = auto_eval("b64decode('aGVsbG8=')", globals=myglobals)
    assert result == 'hello'
    assert myglobals["b64decode"] is __import__("base64").b64decode
コード例 #10
0
ファイル: test_autoimp.py プロジェクト: rsaim/pyflyby
def test_auto_eval_1():
    result = auto_eval("b64decode('aGVsbG8=')")
    assert result == 'hello'