def test_add_import_not_there():
    assert fix_file_contents(
        'import os',
        imports_to_add=('from __future__ import absolute_import', ),
    ) == ('from __future__ import absolute_import\n'
          '\n'
          'import os\n')
Ejemplo n.º 2
0
def test_does_not_put_before_leading_comment():
    assert fix_file_contents(
        '# -*- coding: UTF-8 -*-',
        imports_to_add=('from __future__ import absolute_import',),
    ) == (
        '# -*- coding: UTF-8 -*-\n'
        'from __future__ import absolute_import\n'
    )
Ejemplo n.º 3
0
def test_does_not_put_before_leading_comment():
    assert fix_file_contents(
        '# -*- coding: UTF-8 -*-',
        imports_to_add=('from __future__ import absolute_import',),
    ) == (
        '# -*- coding: UTF-8 -*-\n'
        'from __future__ import absolute_import\n'
    )
def test_separate_relative_and_separate_from():
    ret = fix_file_contents(
        'import thirdparty\n'
        'from . import bar\n',
        separate_from_import=True,
        separate_relative=True,
    )
    assert ret == ('import thirdparty\n' '\n' 'from . import bar\n')
Ejemplo n.º 5
0
def test_add_import_not_there():
    assert fix_file_contents(
        'import os',
        imports_to_add=('from __future__ import absolute_import',),
    ) == (
        'from __future__ import absolute_import\n'
        '\n'
        'import os\n'
    )
def test_separate_relative_and_separate_from():
    ret = fix_file_contents(
        'import thirdparty\n'
        'from . import bar\n',
        separate_from_import=True,
        separate_relative=True,
    )
    assert ret == (
        'import thirdparty\n'
        '\n'
        'from . import bar\n'
    )
Ejemplo n.º 7
0
def test_fix_file_contents(filename):
    input_contents = io.open(os.path.join('test_data/inputs', filename)).read()
    expected = io.open(os.path.join('test_data/outputs', filename)).read()
    assert fix_file_contents(input_contents) == expected
Ejemplo n.º 8
0
def test_remove_import_import_not_there():
    assert fix_file_contents(
        'import os\n',
        imports_to_remove=('from __future__ import with_statement',),
    ) == 'import os\n'
Ejemplo n.º 9
0
def test_remove_imports_actually_removes():
    assert fix_file_contents(
        'from __future__ import with_statement\n\n'
        'import os\n',
        imports_to_remove=('from  __future__ import with_statement',),
    ) == 'import os\n'
Ejemplo n.º 10
0
def test_add_import_trivial():
    assert fix_file_contents(
        '',
        imports_to_add=('from __future__ import absolute_import', ),
    ) == ''
Ejemplo n.º 11
0
def test_remove_import_trivial():
    assert fix_file_contents(
        '',
        imports_to_remove=('from __future__ import with_statement',),
    ) == ''
Ejemplo n.º 12
0
def test_add_import_import_already_there():
    assert fix_file_contents(
        'from __future__ import absolute_import\n',
        imports_to_add=('from __future__ import absolute_import',),
    ) == 'from __future__ import absolute_import\n'
Ejemplo n.º 13
0
def test_add_import_import_already_there():
    assert fix_file_contents(
        'from __future__ import absolute_import\n',
        imports_to_add=('from __future__ import absolute_import', ),
    ) == 'from __future__ import absolute_import\n'
Ejemplo n.º 14
0
def test_add_import_trivial():
    assert fix_file_contents(
        '',
        imports_to_add=('from __future__ import absolute_import',),
    ) == ''
Ejemplo n.º 15
0
def test_remove_import_trivial():
    assert fix_file_contents(
        '',
        imports_to_remove=('from __future__ import with_statement', ),
    ) == ''
Ejemplo n.º 16
0
def test_fix_file_contents(filename):
    input_contents = io.open(os.path.join('test_data/inputs', filename)).read()
    expected = io.open(os.path.join('test_data/outputs', filename)).read()
    assert fix_file_contents(input_contents) == expected
Ejemplo n.º 17
0
def test_remove_imports_actually_removes():
    assert fix_file_contents(
        'from __future__ import with_statement\n\n'
        'import os\n',
        imports_to_remove=('from  __future__ import with_statement', ),
    ) == 'import os\n'
Ejemplo n.º 18
0
def test_remove_import_import_not_there():
    assert fix_file_contents(
        'import os\n',
        imports_to_remove=('from __future__ import with_statement', ),
    ) == 'import os\n'