Exemplo n.º 1
0
def test_importer_wrapping_parentheses_longer(index):
    Imports.set_style(multiline='parentheses',
                      max_columns=80,
                      indent_with_tabs=False)
    src = dedent('''
        from injector import Binder, Injector, InstanceProvider, Key, MappingKey, Module, Scope, ScopeDecorator, SequenceKey, inject, provides, singleton, more, things, imported, foo, bar, baz, cux, lorem, ipsum
        from module_with_long_name.classes.some_prefix.another_prefix.waffle import stuff

        Binder, Injector, InstanceProvider, Key, MappingKey, Module, Scope, ScopeDecorator, SequenceKey, inject, provides, singleton, more, things, imported, foo, bar, baz, cux, lorem, ipsum, stuff
        ''').strip()
    expected_src = dedent('''
        from injector import (Binder, Injector, InstanceProvider, Key, MappingKey,
            Module, Scope, ScopeDecorator, SequenceKey, bar, baz, cux, foo, imported,
            inject, ipsum, lorem, more, provides, singleton, things)
        from module_with_long_name.classes.some_prefix.another_prefix.waffle import (
            stuff)


        Binder, Injector, InstanceProvider, Key, MappingKey, Module, Scope, ScopeDecorator, SequenceKey, inject, provides, singleton, more, things, imported, foo, bar, baz, cux, lorem, ipsum, stuff
        ''').strip()

    scope = Scope.from_source(src)
    new_src = update_imports(
        src, index, *scope.find_unresolved_and_unreferenced_symbols()).strip()
    assert expected_src == new_src
Exemplo n.º 2
0
def test_imports_partial_file(index):
    src = dedent('''
        import re
        import sys


        a = "

        print(
        ''')
    imports = Imports(index, src)
    assert imports.update_source() == src
Exemplo n.º 3
0
def test_imports_partial_file(index):
    src = dedent('''
        import re
        import sys


        a = "

        print(
        ''')
    imports = Imports(index, src)
    assert imports.update_source() == src
Exemplo n.º 4
0
def test_importer_wrapping_parentheses(index):
    Imports.set_style(multiline='parentheses', max_columns=80)
    src = dedent('''
        from injector import Binder, Injector, InstanceProvider, Key, MappingKey, Module, Scope, ScopeDecorator, SequenceKey, inject, provides, singleton
        from waffle import stuff

        Binder, Injector, InstanceProvider, Key, MappingKey, Module, Scope, ScopeDecorator, SequenceKey, inject, provides, singleton, stuff
        ''').strip()
    expected_src = dedent('''
        from injector import (Binder, Injector, InstanceProvider, Key, MappingKey,
            Module, Scope, ScopeDecorator, SequenceKey, inject, provides, singleton)
        from waffle import stuff


        Binder, Injector, InstanceProvider, Key, MappingKey, Module, Scope, ScopeDecorator, SequenceKey, inject, provides, singleton, stuff
        ''').strip()

    scope = Scope.from_source(src)
    new_src = update_imports(src, index, *scope.find_unresolved_and_unreferenced_symbols()).strip()
    assert expected_src == new_src
Exemplo n.º 5
0
def test_importer_wrapping_parentheses(index):
    Imports.set_style(multiline='parentheses', max_columns=80)
    src = dedent('''
        from injector import Binder, Injector, InstanceProvider, Key, MappingKey, Module, Scope, ScopeDecorator, SequenceKey, inject, provides, singleton
        from waffle import stuff

        Binder, Injector, InstanceProvider, Key, MappingKey, Module, Scope, ScopeDecorator, SequenceKey, inject, provides, singleton, stuff
        ''').strip()
    expected_src = dedent('''
        from injector import (Binder, Injector, InstanceProvider, Key, MappingKey,
            Module, Scope, ScopeDecorator, SequenceKey, inject, provides, singleton)
        from waffle import stuff


        Binder, Injector, InstanceProvider, Key, MappingKey, Module, Scope, ScopeDecorator, SequenceKey, inject, provides, singleton, stuff
        ''').strip()

    scope = Scope.from_source(src)
    new_src = update_imports(
        src, index, *scope.find_unresolved_and_unreferenced_symbols()).strip()
    assert expected_src == new_src
Exemplo n.º 6
0
def test_importer_wrapping_escaped_longer(index):
    Imports.set_style(multiline='backslash', max_columns=80)
    src = dedent('''
        from injector import Binder, Injector, InstanceProvider, Key, MappingKey, Module, Scope, ScopeDecorator, SequenceKey, inject, provides, singleton, more, things, imported, foo, bar, baz, cux, lorem, ipsum
        from waffle import stuff

        Binder, Injector, InstanceProvider, Key, MappingKey, Module, Scope, ScopeDecorator, SequenceKey, inject, provides, singleton, more, things, imported, foo, bar, baz, cux, lorem, ipsum, stuff
        ''').strip()
    expected_src = dedent('''
        from injector import Binder, Injector, InstanceProvider, Key, MappingKey, \\
            Module, Scope, ScopeDecorator, SequenceKey, bar, baz, cux, foo, imported, \\
            inject, ipsum, lorem, more, provides, singleton, things
        from waffle import stuff


        Binder, Injector, InstanceProvider, Key, MappingKey, Module, Scope, ScopeDecorator, SequenceKey, inject, provides, singleton, more, things, imported, foo, bar, baz, cux, lorem, ipsum, stuff
        ''').strip()

    scope = Scope.from_source(src)
    new_src = update_imports(src, index, *scope.find_unresolved_and_unreferenced_symbols()).strip()
    assert expected_src == new_src
Exemplo n.º 7
0
def test_importer_wrapping_escaped_longer(index):
    Imports.set_style(multiline='backslash', max_columns=80)
    src = dedent('''
        from injector import Binder, Injector, InstanceProvider, Key, MappingKey, Module, Scope, ScopeDecorator, SequenceKey, inject, provides, singleton, more, things, imported, foo, bar, baz, cux, lorem, ipsum
        from waffle import stuff

        Binder, Injector, InstanceProvider, Key, MappingKey, Module, Scope, ScopeDecorator, SequenceKey, inject, provides, singleton, more, things, imported, foo, bar, baz, cux, lorem, ipsum, stuff
        ''').strip()
    expected_src = dedent('''
        from injector import Binder, Injector, InstanceProvider, Key, MappingKey, \\
            Module, Scope, ScopeDecorator, SequenceKey, bar, baz, cux, foo, imported, \\
            inject, ipsum, lorem, more, provides, singleton, things
        from waffle import stuff


        Binder, Injector, InstanceProvider, Key, MappingKey, Module, Scope, ScopeDecorator, SequenceKey, inject, provides, singleton, more, things, imported, foo, bar, baz, cux, lorem, ipsum, stuff
        ''').strip()

    scope = Scope.from_source(src)
    new_src = update_imports(
        src, index, *scope.find_unresolved_and_unreferenced_symbols()).strip()
    assert expected_src == new_src
Exemplo n.º 8
0
def test_importer_wrapping_parentheses_longer(index):
    Imports.set_style(multiline='parentheses', max_columns=80, indent_with_tabs=False)
    src = dedent('''
        from injector import Binder, Injector, InstanceProvider, Key, MappingKey, Module, Scope, ScopeDecorator, SequenceKey, inject, provides, singleton, more, things, imported, foo, bar, baz, cux, lorem, ipsum
        from module_with_long_name.classes.some_prefix.another_prefix.waffle import stuff

        Binder, Injector, InstanceProvider, Key, MappingKey, Module, Scope, ScopeDecorator, SequenceKey, inject, provides, singleton, more, things, imported, foo, bar, baz, cux, lorem, ipsum, stuff
        ''').strip()
    expected_src = dedent('''
        from injector import (Binder, Injector, InstanceProvider, Key, MappingKey,
            Module, Scope, ScopeDecorator, SequenceKey, bar, baz, cux, foo, imported,
            inject, ipsum, lorem, more, provides, singleton, things)
        from module_with_long_name.classes.some_prefix.another_prefix.waffle import (
            stuff)


        Binder, Injector, InstanceProvider, Key, MappingKey, Module, Scope, ScopeDecorator, SequenceKey, inject, provides, singleton, more, things, imported, foo, bar, baz, cux, lorem, ipsum, stuff
        ''').strip()

    scope = Scope.from_source(src)
    new_src = update_imports(src, index, *scope.find_unresolved_and_unreferenced_symbols()).strip()
    assert expected_src == new_src
Exemplo n.º 9
0
def test_get_style_from_config(index, tmpdir):
    conf_file = tmpdir.join(PROJECT_CONFIG_FILE)
    conf_file.write(dedent('''
        [importmagic]
        multiline = parentheses_test
        max_columns = 42
        indent_with_tabs = 1
    '''))
    src = dedent('''
        from injector import Binder, Injector, InstanceProvider, Key, MappingKey, Module, Scope, ScopeDecorator, SequenceKey, inject, provides, singleton
        from waffle import stuff

        Binder, Injector, InstanceProvider, Key, MappingKey, Module, Scope, ScopeDecorator, SequenceKey, inject, provides, singleton, stuff
        ''').strip()

    imports = Imports(index, src, root_dir=tmpdir.strpath)
    imports.get_style_from_config()
    assert Imports._style == {
        'multiline': 'parentheses_test',
        'max_columns': 42,
        'indent_with_tabs': True,
    }
Exemplo n.º 10
0
def test_get_style_from_config(index, tmpdir):
    conf_file = tmpdir.join(PROJECT_CONFIG_FILE)
    conf_file.write(
        dedent('''
        [importmagic]
        multiline = parentheses_test
        max_columns = 42
        indent_with_tabs = 1
    '''))
    src = dedent('''
        from injector import Binder, Injector, InstanceProvider, Key, MappingKey, Module, Scope, ScopeDecorator, SequenceKey, inject, provides, singleton
        from waffle import stuff

        Binder, Injector, InstanceProvider, Key, MappingKey, Module, Scope, ScopeDecorator, SequenceKey, inject, provides, singleton, stuff
        ''').strip()

    imports = Imports(index, src, root_dir=tmpdir.strpath)
    imports.get_style_from_config()
    assert Imports._style == {
        'multiline': 'parentheses_test',
        'max_columns': 42,
        'indent_with_tabs': True,
    }