master
py 41 lines 1.34 KB
Raw
1 #!/usr/bin/env python3
2 #
3 # SPDX-License-Identifier: GPL-2.0-or-later
4 #
5 '''Python linter tests'''
6
7 import os
8
9 from pathlib import Path
10 from qemu_test import QemuBaseTest, skipIfMissingImports
11
12
13 class LinterTest(QemuBaseTest):
14 '''
15 Run python linters on the test *.py files
16 '''
17
18 @skipIfMissingImports("pylint")
19 def test_pylint(self):
20 '''Check source files with pylint'''
21 from pylint.lint import Run as pylint_run
22 from pylint.reporters.collecting_reporter import CollectingReporter
23 srcdir = os.path.join(Path(__file__).parent.parent, self.arch)
24 rcfile = os.path.join(Path(__file__).parent.parent, "pylintrc")
25 self.log.info('Checking files in %s with pylint', srcdir)
26 reporter = CollectingReporter()
27 pylint_run(["--rcfile", rcfile, srcdir], reporter=reporter, exit=False)
28 if reporter.messages:
29 fmt = '"{path}:{line}: {msg_id}: {msg} ({symbol})"'
30 for msg in reporter.messages:
31 if msg.category == "error":
32 self.log.error(msg.format(fmt))
33 elif msg.category == "warning":
34 self.log.warning(msg.format(fmt))
35 else:
36 self.log.info(msg.format(fmt))
37 self.fail("Pylint failed, see base.log for details.")
38
39
40 if __name__ == '__main__':
41 QemuBaseTest.main()