Exemplo n.º 1
0
def test_class_imports(impfrom):
    """Confirm plugin works for imports in class bodies."""
    code = dedent("""
    class Bar:
        from {} import foo
    """).format(impfrom)

    tree = ast.parse(code)
    assert (len(list(Plugin(tree).run())) == 1) == (impfrom.startswith("."))
Exemplo n.º 2
0
def test_func_imports(impfrom):
    """Confirm plugin works for imports in functions."""
    code = dedent("""
    def func():
        from {} import foo
    """).format(impfrom)

    tree = ast.parse(code)
    assert (len(list(Plugin(tree).run())) == 1) == (impfrom.startswith("."))
Exemplo n.º 3
0
def test_correct_relative_import_linenos():
    """Confirm the multiple errors are reported on the correct lines."""
    code = dedent("""\
    from .core import Plugin
    from f8_absolute_import.core import Visitor
    from .version import __version__
    """)

    tree = ast.parse(code)
    assert {t[0] for t in Plugin(tree).run()} == {1, 3}
Exemplo n.º 4
0
def test_multilevel_relative_import():
    """Confirm error is found with a multi-dot relative import."""
    code = "from ..foo import bar"

    tree = ast.parse(code)
    assert len(list(Plugin(tree).run())) == 0
Exemplo n.º 5
0
def test_multiple_relative_imports():
    """Confirm multiple errors are found on multiple relative member imports."""
    code = "from .core import Plugin\nfrom .version import __version__"

    tree = ast.parse(code)
    assert len(list(Plugin(tree).run())) == 0
Exemplo n.º 6
0
def test_relative_import(code):
    """Confirm error *IS* found on relative member import."""
    tree = ast.parse(code)
    assert len(list(Plugin(tree).run())) == 0
Exemplo n.º 7
0
def test_absolute_import(code):
    """Confirm no error found on absolute member import."""
    tree = ast.parse(code)
    assert len(list(Plugin(tree).run())) == 0
Exemplo n.º 8
0
def test_module_import(code):
    """Confirm no error found on module import."""
    tree = ast.parse(code)
    assert len(list(Plugin(tree).run())) == 0