Ejemplo n.º 1
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.º 2
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
    out, _ = capsys.readouterr()
    assert out == '{} is non-utf-8 (not supported)\n'.format(f.strpath)
Ejemplo n.º 3
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.º 4
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'
Ejemplo n.º 5
0
def test_main_trivial():
    assert main(()) == 0
Ejemplo n.º 6
0
def test_main_stdin_with_changes(capsys):
    stdin = io.TextIOWrapper(io.BytesIO(b'set((1, 2))\n'), 'UTF-8')
    with mock.patch.object(sys, 'stdin', stdin):
        assert main(('-', )) == 1
    out, err = capsys.readouterr()
    assert out == '{1, 2}\n'
Ejemplo n.º 7
0
def test_main_exit_zero_even_if_changed(tmpdir):
    f = tmpdir.join('t.py')
    f.write('set((1, 2))\n')
    assert not main((str(f), '--exit-zero-even-if-changed'))
    assert f.read() == '{1, 2}\n'
    assert not main((str(f), '--exit-zero-even-if-changed'))
Ejemplo n.º 8
0
def test_main_py27_syntaxerror_coding(tmpdir):
    f = tmpdir.join('f.py')
    f.write('# -*- coding: utf-8\nset((1, 2))\n')
    assert main((f.strpath, )) == 1
    assert f.read() == '# -*- coding: utf-8\n{1, 2}\n'
Ejemplo n.º 9
0
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""pyupgrade"""
import sys
import pyupgrade

print("pyupgrade: ", sys.argv)
sys.exit(pyupgrade.main(sys.argv[1:]))