Merge tag 'v9.0.0-rc3'
[qemu/ar7.git] / tests / qemu-iotests / 297
blobee78a627359dd02e33f97fc8e26ae1d451453788
1 #!/usr/bin/env python3
2 # group: meta
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/>.
19 import os
20 import subprocess
21 import sys
22 from typing import List
24 import iotests
25 import linters
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:
36     try:
37         linters.run_linter(linter, ['--version'], suppress_output=True)
38     except subprocess.CalledProcessError:
39         iotests.case_notrun(f"'{linter}' not found")
40         return False
41     return True
44 def test_pylint(files: List[str]) -> None:
45     print('=== pylint ===')
46     sys.stdout.flush()
48     if not check_linter('pylint'):
49         return
51     linters.run_linter('pylint', files)
54 def test_mypy(files: List[str]) -> None:
55     print('=== mypy ===')
56     sys.stdout.flush()
58     if not check_linter('mypy'):
59         return
61     env = os.environ.copy()
62     env['MYPYPATH'] = env['PYTHONPATH']
64     linters.run_linter('mypy', files, env=env, suppress_output=True)
67 def main() -> None:
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):
74         try:
75             test(files)
76         except subprocess.CalledProcessError as exc:
77             # Linter failure will be caught by diffing the IO.
78             if exc.output:
79                 print(exc.output)
82 iotests.script_main(main)