def test_flake8(): with pytest.raises(SystemExit) as pytest_wrapped_e: main([ # "--verbose" ]) assert pytest_wrapped_e.value.code == 0
def test_output(file_regression: FileRegressionFixture, capsys): with pytest.raises(SystemExit): cli.main([str(bad_code), "--select", "F401,F404,F821,F701,E303", "--format", "github"]) stdout = capsys.readouterr().out.replace(str(bad_code), "bad_code.py") check_file_regression(stdout, file_regression) assert not capsys.readouterr().err
def _do_action(cls, parsed_args): from flake8.main.cli import main try: sys.argv = ['black', parsed_args.filename] main() except SystemExit: # flake8 calls quit(), ignore it pass
def test_report(bad_sourcedir, tmpdir): """Test that a report on a bad file creates the expected files.""" with chdir(bad_sourcedir): main(['--exit-zero', '--format=html', '--htmldir=%s' % tmpdir, '.']) names = ('index.html', 'styles.css', 'bad.report.html', 'bad.source.html') written = os.listdir(str(tmpdir)) for n in names: assert n in written, "File %s not written" % n
def test_flake8(): _root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) for dname in ['ex4mple', 'test']: try: cli.main([os.path.join(_root, dname)]) except SystemExit as exc: if exc.code != 0: raise
def _call_main(argv, retv=0): """Call flake8's main CLI entry point. This is how flake8 itself runs CLI tests. Copied from: https://gitlab.com/pycqa/flake8/-/blob/master/tests/integration/test_main.py#L12-15 """ with pytest.raises(SystemExit) as excinfo: cli.main(argv) assert excinfo.value.code == retv
def call_flake8(): log = logging.getLogger('flake8') log.setLevel(logging.INFO) log.addHandler(logging.StreamHandler(stream=sys.stdout)) logging.getLogger('flake8.plugins.manager').setLevel(logging.WARNING) try: flake8cli.main(argv=['.']) except SystemExit as e: if e.code is False: print('flake8, ok.') return raise
def _lint(cls, filepath): stdout = io.StringIO() with contextlib.redirect_stdout(stdout): try: main( [ str(filepath), "--exit-zero", "--max-line-length", "88", "--max-complexity", "10", # Q000: avoid "" strings # WPS305: avoid f-strings # WPS306: required explicit subclassing of object # WPS602: avoid @staticmethod (can be subclassed…) "--ignore=Q000,WPS305,WPS306,WPS602", ], ) except SystemExit: # TODO what do we do here? pass return cls._parse_output(stdout.getvalue())
def _call_main(argv, retv=0): with pytest.raises(SystemExit) as excinfo: cli.main(argv) assert excinfo.value.code == retv
import os import sys import flake8.main.cli as flake8 import nengo import pytest os.environ["NENGO_DL_TEST_PRECISION"] = "32" os.environ["NENGO_DL_TEST_UNROLL"] = "1" os.environ["NENGO_DL_TEST_DEVICE"] = "/gpu:0" # run nengo tests print("#" * 30, "NENGO TESTS", "#" * 30) pytest.main([ os.path.dirname(nengo.__file__), '--simulator', 'nengo_dl.tests.Simulator', '--ref-simulator', 'nengo_dl.tests.Simulator', ]) # run local tests print("#" * 30, "NENGO_DL TESTS", "#" * 30) pytest.main(['--gpu']) # run flake8 sys.argv += "--ignore E721 .".split() flake8.main()
import os import sys from flake8.main import cli cli.main([os.path.join(os.getcwd(), '..', 'cnl015_2_pysdl2')])
# Copyright 2019 Tulip Solutions B.V. # # 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. from flake8.main import cli """Wraps flake8 cli""" if __name__ == "__main__": cli.main()
def _lint(cls, filepath): stdout = io.StringIO() with contextlib.redirect_stdout(stdout): main([cls.path, str(filepath), "--exit-zero"]) messages = cls._parse_output(stdout.getvalue()) return messages
"""Module allowing for ``python -m flake8 ...``.""" from flake8.main import cli cli.main()
def lint(command): additional_args = [] if command.args.args is not None: additional_args = command.args.args.split(' ') flake8.main(['dags', 'tests'] + additional_args)