コード例 #1
0
 def testEchoBadInput(self):
     bad_syntax = '  a = 1\n'
     with patched_input(bad_syntax):
         with captured_output() as (_, _):
             with self.assertRaisesRegex(yapf.errors.YapfError,
                                         'unexpected indent'):
                 yapf.main([])
コード例 #2
0
ファイル: main_test.py プロジェクト: Anondo/yapf
 def testEchoInput(self):
   code = "a = 1\nb = 2\n"
   with patched_input(code):
     with captured_output() as (out, err):
       ret = yapf.main([])
       self.assertEqual(ret, 0)
       self.assertEqual(out.getvalue(), code)
コード例 #3
0
ファイル: main_test.py プロジェクト: wushiyuan/yapf
 def testEchoInput(self):
   code = "a = 1\nb = 2\n"
   with patched_input(code):
     with captured_output() as (out, err):
       ret = yapf.main([])
       self.assertEqual(ret, 0)
       self.assertEqual(out.getvalue(), code)
コード例 #4
0
ファイル: setup.py プロジェクト: visemet/winnan
    def run(self):  # pylint: disable=missing-docstring
        import yapf  # pylint: disable=import-error

        try:
            yapf.main([
                None,
                "--in-place",
                "--recursive",
                "--verbose",
                "setup.py",
                "tests/",
                "winnan/",
            ])
        except yapf.errors.YapfError as err:
            msg = "yapf: {}".format(err)
            self.announce(msg, distutils.log.ERROR)  # pylint: disable=no-member
            raise distutils.errors.DistutilsError(msg)  # pylint: disable=no-member
コード例 #5
0
ファイル: main_test.py プロジェクト: wushiyuan/yapf
 def testHelp(self):
   with captured_output() as (out, err):
     ret = yapf.main(['-', '--style-help', '--style=pep8'])
     self.assertEqual(ret, 0)
     help_message = out.getvalue()
     self.assertIn("INDENT_WIDTH=4", help_message)
     self.assertIn("The number of spaces required before a trailing comment.",
                   help_message)
コード例 #6
0
ファイル: main_test.py プロジェクト: wushiyuan/yapf
 def testEchoInputWithStyle(self):
   code = "def f(a = 1):\n    return 2*a\n"
   chromium_code = "def f(a=1):\n  return 2 * a\n"
   with patched_input(code):
     with captured_output() as (out, err):
       ret = yapf.main(['-', '--style=chromium'])
       self.assertEqual(ret, 0)
       self.assertEqual(out.getvalue(), chromium_code)
コード例 #7
0
ファイル: main_test.py プロジェクト: Anondo/yapf
 def testHelp(self):
   with captured_output() as (out, err):
     ret = yapf.main(['-', '--style-help', '--style=pep8'])
     self.assertEqual(ret, 0)
     help_message = out.getvalue()
     self.assertIn("INDENT_WIDTH=4", help_message)
     self.assertIn("The number of spaces required before a trailing comment.",
                   help_message)
コード例 #8
0
 def testEchoInputWithStyle(self):
     code = 'def f(a = 1):\n    return 2*a\n'
     yapf_code = 'def f(a=1):\n  return 2 * a\n'
     with patched_input(code):
         with captured_output() as (out, _):
             ret = yapf.main(['-', '--style=yapf'])
             self.assertEqual(ret, 0)
             self.assertEqual(out.getvalue(), yapf_code)
コード例 #9
0
ファイル: main_test.py プロジェクト: Anondo/yapf
 def testEchoInputWithStyle(self):
   code = "def f(a = 1):\n    return 2*a\n"
   chromium_code = "def f(a=1):\n  return 2 * a\n"
   with patched_input(code):
     with captured_output() as (out, err):
       ret = yapf.main(['-', '--style=chromium'])
       self.assertEqual(ret, 2)
       self.assertEqual(out.getvalue(), chromium_code)
コード例 #10
0
 def testHelp(self):
   with captured_output() as (out, _):
     ret = yapf.main(['-', '--style-help', '--style=pep8'])
     self.assertEqual(ret, 0)
     help_message = out.getvalue()
     self.assertIn('indent_width=4', help_message)
     self.assertIn('The number of spaces required before a trailing comment.',
                   help_message)
コード例 #11
0
ファイル: format.py プロジェクト: vector-of-bool/dds
def format_py(args: FormatArguments) -> None:
    py_files = paths.TOOLS_DIR.rglob('*.py')
    rc = yapf.main(
        list(
            proc.flatten_cmd([
                '--parallel',
                '--verbose',
                ('--diff') if args.check else ('--in-place'),
                py_files,
            ])))
    if rc and args.check:
        raise RuntimeError(
            'Format checks for one or more Python files. (See above.)')
    if rc:
        raise RuntimeError(
            'Format execution failed for Python code. See above.')
コード例 #12
0
ファイル: setup.py プロジェクト: trayboat/vault-ca
 def run(self):
     import yapf
     yapf.main([
         sys.executable, '--in-place', '--recursive', 'bin', 'vault_ca',
         'tests'
     ])
コード例 #13
0
ファイル: main_test.py プロジェクト: purpleP/yapf
 def testEchoBadInput(self):
     bad_syntax = "  a = 1\n"
     with patched_input(bad_syntax):
         with captured_output() as (out, err):
             ret = yapf.main([])
コード例 #14
0
ファイル: main_test.py プロジェクト: wushiyuan/yapf
 def testNoPythonFilesMatched(self):
   with self.assertRaisesRegexp(yapf.errors.YapfError,
                                'did not match any python files'):
     yapf.main(['yapf', 'foo.c'])
コード例 #15
0
ファイル: main_test.py プロジェクト: Anondo/yapf
 def testEchoBadInput(self):
   bad_syntax = "  a = 1\n"
   with patched_input(bad_syntax):
     with captured_output() as (out, err):
       with self.assertRaisesRegexp(SyntaxError, "unexpected indent"):
         ret = yapf.main([])
コード例 #16
0
ファイル: main_test.py プロジェクト: Anondo/yapf
 def testNoPythonFilesMatched(self):
   with self.assertRaisesRegexp(yapf.errors.YapfError,
                                'did not match any python files'):
     yapf.main(['yapf', 'foo.c'])
コード例 #17
0
ファイル: main_test.py プロジェクト: wushiyuan/yapf
 def testEchoBadInput(self):
   bad_syntax = "  a = 1\n"
   with patched_input(bad_syntax):
     with captured_output() as (out, err):
       with self.assertRaisesRegexp(SyntaxError, "unexpected indent"):
         yapf.main([])
コード例 #18
0
ファイル: main_test.py プロジェクト: wushiyuan/yapf
 def testVersion(self):
   with captured_output() as (out, err):
     ret = yapf.main(['-', '--version'])
     self.assertEqual(ret, 0)
     version = 'yapf {}\n'.format(yapf.__version__)
     self.assertEqual(version, out.getvalue())
コード例 #19
0
def test_format():
    assert 0 == yapf.main(
        ['yapf', '--diff', '--recursive', 'setup.py', 'tests'] +
        find_packages())
コード例 #20
0
ファイル: main_test.py プロジェクト: boada/yapf
 def testEchoBadInput(self):
   bad_syntax = '  a = 1\n'
   with patched_input(bad_syntax):
     with captured_output() as (_, _):
       with self.assertRaisesRegexp(SyntaxError, 'unexpected indent'):
         yapf.main([])
コード例 #21
0
ファイル: setup.py プロジェクト: fabregaszy/construi
 def run(self):
     import yapf
     yapf.main(['yapf', '--recursive', '--in-place', 'setup.py', 'test'] +
               find_packages())
コード例 #22
0
# Copyright 2015 Google Inc. 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.
import sys

import yapf

sys.exit(yapf.main(sys.argv))
コード例 #23
0
ファイル: main_test.py プロジェクト: Anondo/yapf
 def testVersion(self):
   with captured_output() as (out, err):
     ret = yapf.main(['-', '--version'])
     self.assertEqual(ret, 0)
     version = 'yapf {}\n'.format(yapf.__version__)
     self.assertEqual(version, out.getvalue())
コード例 #24
0
ファイル: main_test.py プロジェクト: purpleP/yapf
 def testEchoBadInput(self):
   bad_syntax = "  a = 1\n"
   with patched_input(bad_syntax):
     with captured_output() as (out, err):
       ret = yapf.main([])
コード例 #25
0
 def run(self):
     import yapf
     yapf.main(['yapf', '--recursive', '--in-place', 'setup.py', 'test'] +
               find_packages())
コード例 #26
0
        )
        print(
            "auto-format. Please stage, stash, or revert these changes. You may "
        )
        print("find `git stash -k` helpful here.")
        print(f"Files with unstaged changes: {' '.join(changed)}")
        sys.exit(1)

    # Format all staged files, then exit with an error code if any have uncommitted changes.
    print("Formatting staged Python files . . .")

    out = subprocess.run(["git", "rev-parse", "--show-toplevel"],
                         stdout=subprocess.PIPE)
    repo_root = Path(out.stdout.decode(sys.stdout.encoding).splitlines()[0])
    python_files = [str(repo_root / f) for f in python_files]
    out = yapf.main(["yapf", "-i", "-r"] + python_files)
    if out != 0:
        sys.exit(out)

    out = subprocess.run(["git", "diff", "--name-only", "--"] +
                         [str(f) for f in python_files],
                         stdout=subprocess.PIPE)
    changed = [
        str(Path(f))
        for f in out.stdout.decode(sys.stdout.encoding).splitlines()
    ]
    if len(changed) > 0:
        print("Reformatted staged files. Please review and stage the changes.")
        print(f"Files updated: {' '.join(changed)}")
        sys.exit(1)