Ejemplo n.º 1
0
def test_main_py36_plus_function_trailing_commas(tmpdir):
    f = tmpdir.join('f.py')
    f.write('def f(\n    **kwargs\n): pass\n')
    assert main((f.strpath, )) == 0
    assert f.read() == 'def f(\n    **kwargs\n): pass\n'
    assert main((f.strpath, '--py36-plus')) == 1
    assert f.read() == 'def f(\n    **kwargs,\n): pass\n'
Ejemplo n.º 2
0
def test_main_py35_plus_argument_star_star_kwargs(tmpdir):
    f = tmpdir.join('f.py')
    f.write('x(\n    **args\n)\n')
    assert main((f.strpath, )) == 0
    assert f.read() == 'x(\n    **args\n)\n'
    assert main((f.strpath, '--py35-plus')) == 1
    assert f.read() == 'x(\n    **args,\n)\n'
Ejemplo n.º 3
0
def test_main_py36_plus_implies_py35_plus(tmpdir):
    f = tmpdir.join('f.py')
    f.write('x(\n    **kwargs\n)\n')
    assert main((f.strpath, )) == 0
    assert f.read() == 'x(\n    **kwargs\n)\n'
    assert main((f.strpath, '--py36-plus')) == 1
    assert f.read() == 'x(\n    **kwargs,\n)\n'
Ejemplo n.º 4
0
def test_main_preserves_line_endings(tmpdir, capsys):
    f = tmpdir.join('f.py')
    f.write_binary(b'x(\r\n    1\r\n)\r\n')
    assert main((f.strpath, )) == 1
    _, err = capsys.readouterr()
    assert err == f'Rewriting {f}\n'
    assert f.read_binary() == b'x(\r\n    1,\r\n)\r\n'
Ejemplo n.º 5
0
def test_main_changes_a_file(tmpdir, capsys):
    f = tmpdir.join('f.py')
    f.write('x(\n    1\n)\n')
    assert main((f.strpath, )) == 1
    _, err = capsys.readouterr()
    assert err == f'Rewriting {f}\n'
    assert f.read() == 'x(\n    1,\n)\n'
Ejemplo n.º 6
0
def test_main_stdin_no_changes(capsys):
    stdin = io.TextIOWrapper(io.BytesIO(b'x = 5\n'), 'UTF-8')
    with mock.patch.object(sys, 'stdin', stdin):
        assert main(('-', )) == 0
    out, err = capsys.readouterr()
    assert out == 'x = 5\n'
Ejemplo n.º 7
0
def test_main_trivial():
    assert main(()) == 0
Ejemplo n.º 8
0
def test_main_py27_syntaxerror_coding(tmpdir):
    f = tmpdir.join('f.py')
    f.write('# -*- coding: utf-8 -*-\n[1, 2,]\n')
    assert main((f.strpath, )) == 1
    assert f.read() == '# -*- coding: utf-8 -*-\n[1, 2]\n'
Ejemplo n.º 9
0
def test_main_non_utf8_bytes(tmpdir, capsys):
    f = tmpdir.join('f.py')
    f.write_binary('# -*- coding: cp1252 -*-\nx = €\n'.encode('cp1252'))
    assert main((f.strpath, )) == 1
    _, err = capsys.readouterr()
    assert err == f'{f} is non-utf-8 (not supported)\n'
Ejemplo n.º 10
0
def test_main_syntax_error(tmpdir):
    f = tmpdir.join('f.py')
    f.write('from __future__ import print_function\nprint 1\n')
    assert main((f.strpath, )) == 0
Ejemplo n.º 11
0
def test_main_noop(tmpdir):
    f = tmpdir.join('f.py')
    f.write('x = 5\n')
    assert main((f.strpath, )) == 0
    assert f.read() == 'x = 5\n'
Ejemplo n.º 12
0
def test_main_exit_zero_even_if_changed(tmpdir):
    f = tmpdir.join('t.py')
    f.write('x(\n    1\n)')
    assert not main((str(f), '--exit-zero-even-if-changed'))
    assert f.read() == 'x(\n    1,\n)'
    assert not main((str(f), '--exit-zero-even-if-changed'))
Ejemplo n.º 13
0
from add_trailing_comma._main import main

if __name__ == '__main__':
    exit(main())