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
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
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
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
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
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