def test_py36_plus_fstrings(tmpdir): f = tmpdir.join('f.py') f.write('"{} {}".format(hello, world)') assert main((f.strpath, )) == 0 assert f.read() == '"{} {}".format(hello, world)' assert main((f.strpath, '--py36-plus')) == 1 assert f.read() == 'f"{hello} {world}"'
def test_py3_plus_argument_unicode_literals(tmpdir): f = tmpdir.join('f.py') f.write('u""') assert main((f.strpath, )) == 0 assert f.read() == 'u""' assert main((f.strpath, '--py3-plus')) == 1 assert f.read() == '""'
def test_py3_plus_new_style_classes(tmpdir): f = tmpdir.join('f.py') f.write('class C(object): pass\n') assert main((f.strpath, )) == 0 assert f.read() == 'class C(object): pass\n' assert main((f.strpath, '--py3-plus')) == 1 assert f.read() == 'class C: pass\n'
def test_py3_plus_super(tmpdir): f = tmpdir.join('f.py') f.write( 'class C(Base):\n' ' def f(self):\n' ' super(C, self).f()\n', ) assert main((f.strpath, )) == 0 assert f.read() == ('class C(Base):\n' ' def f(self):\n' ' super(C, self).f()\n') assert main((f.strpath, '--py3-plus')) == 1 assert f.read() == ('class C(Base):\n' ' def f(self):\n' ' super().f()\n')
def test_main_changes_a_file(tmpdir, capsys): f = tmpdir.join('f.py') f.write('x = set((1, 2, 3))\n') assert main((f.strpath, )) == 1 out, _ = capsys.readouterr() assert out == 'Rewriting {}\n'.format(f.strpath) assert f.read() == 'x = {1, 2, 3}\n'
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 out, _ = capsys.readouterr() assert out == '{} is non-utf-8 (not supported)\n'.format(f.strpath)
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
def test_main_keeps_line_endings(tmpdir, capsys): f = tmpdir.join('f.py') f.write_binary(b'x = set((1, 2, 3))\r\n') assert main((f.strpath, )) == 1 assert f.read_binary() == b'x = {1, 2, 3}\r\n'
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'
def test_main_trivial(): assert main(()) == 0
def test_no_percent(tmpdir): f = tmpdir.join('f.py') f.write('"%s %s" % (hello, world)') assert main((f.strpath, '--keep-percent-format')) == 0 assert f.read() == '"%s %s" % (hello, world)'