4 # Copyright (C) 2020 Red Hat, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 from typing import List
28 # Looking for something?
30 # List of files to exclude from linting: linters.py
31 # mypy configuration: mypy.ini
32 # pylint configuration: pylintrc
35 def check_linter(linter: str) -> bool:
37 linters.run_linter(linter, ['--version'], suppress_output=True)
38 except subprocess.CalledProcessError:
39 iotests.case_notrun(f"'{linter}' not found")
44 def test_pylint(files: List[str]) -> None:
45 print('=== pylint ===')
48 if not check_linter('pylint'):
51 linters.run_linter('pylint', files)
54 def test_mypy(files: List[str]) -> None:
58 if not check_linter('mypy'):
61 env = os.environ.copy()
62 env['MYPYPATH'] = env['PYTHONPATH']
64 linters.run_linter('mypy', files, env=env, suppress_output=True)
68 files = linters.get_test_files()
70 iotests.logger.debug('Files to be checked:')
71 iotests.logger.debug(', '.join(sorted(files)))
73 for test in (test_pylint, test_mypy):
76 except subprocess.CalledProcessError as exc:
77 # Linter failure will be caught by diffing the IO.
82 iotests.script_main(main)