[PATCH for-11.0 15/15] tests/functional: Add a generic test that checks the files with pylint

Thomas Huth posted 15 patches 1 day, 4 hours ago
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, "Alex Bennée" <alex.bennee@linaro.org>, Radoslaw Biernacki <rad@semihalf.com>, Peter Maydell <peter.maydell@linaro.org>, Leif Lindholm <leif.lindholm@oss.qualcomm.com>, Eric Auger <eric.auger@redhat.com>, Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>, Dmitry Osipenko <dmitry.osipenko@collabora.com>, "Cédric Le Goater" <clg@kaod.org>, Steven Lee <steven_lee@aspeedtech.com>, Troy Lee <leetroy@gmail.com>, Jamin Lin <jamin_lin@aspeedtech.com>, Andrew Jeffery <andrew@codeconstruct.com.au>, Joel Stanley <joel@jms.id.au>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Aurelien Jarno <aurelien@aurel32.net>, BALATON Zoltan <balaton@eik.bme.hu>, Glenn Miles <milesg@linux.ibm.com>, Nicholas Piggin <npiggin@gmail.com>, Harsh Prateek Bora <harshpb@linux.ibm.com>, Thomas Huth <thuth@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Palmer Dabbelt <palmer@dabbelt.com>, Alistair Francis <alistair.francis@wdc.com>, Weiwei Li <liwei1518@gmail.com>, Daniel Henrique Barboza <dbarboza@ventanamicro.com>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>, Zhao Liu <zhao1.liu@intel.com>
[PATCH for-11.0 15/15] tests/functional: Add a generic test that checks the files with pylint
Posted by Thomas Huth 1 day, 4 hours ago
From: Thomas Huth <thuth@redhat.com>

To avoid that new pylint-related warnings get committed, let's check
the files with pylint during each run (similar to what we are doing
for the iotests already).

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 tests/functional/generic/meson.build     |  1 +
 tests/functional/generic/test_linters.py | 41 ++++++++++++++++++++++++
 2 files changed, 42 insertions(+)
 create mode 100755 tests/functional/generic/test_linters.py

diff --git a/tests/functional/generic/meson.build b/tests/functional/generic/meson.build
index 013cc96fbf8..09763c5d229 100644
--- a/tests/functional/generic/meson.build
+++ b/tests/functional/generic/meson.build
@@ -3,6 +3,7 @@
 tests_generic_system = [
   'empty_cpu_model',
   'info_usernet',
+  'linters',
   'version',
   'vnc',
 ]
diff --git a/tests/functional/generic/test_linters.py b/tests/functional/generic/test_linters.py
new file mode 100755
index 00000000000..b5b90fcf7a3
--- /dev/null
+++ b/tests/functional/generic/test_linters.py
@@ -0,0 +1,41 @@
+#!/usr/bin/env python3
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+'''Python linter tests'''
+
+import os
+
+from pathlib import Path
+from qemu_test import QemuBaseTest, skipIfMissingImports
+
+
+class LinterTest(QemuBaseTest):
+    '''
+    Run python linters on the test *.py files
+    '''
+
+    @skipIfMissingImports("pylint")
+    def test_pylint(self):
+        '''Check source files with pylint'''
+        from pylint.lint import Run as pylint_run
+        from pylint.reporters.collecting_reporter import CollectingReporter
+        srcdir = os.path.join(Path(__file__).parent.parent, self.arch)
+        rcfile = os.path.join(Path(__file__).parent.parent, "pylintrc")
+        self.log.info('Checking files in %s with pylint', srcdir)
+        reporter = CollectingReporter()
+        pylint_run(["--rcfile", rcfile, srcdir], reporter=reporter, exit=False)
+        if reporter.messages:
+            fmt = '"{path}:{line}: {msg_id}: {msg} ({symbol})"'
+            for msg in reporter.messages:
+                if msg.category == "error":
+                    self.log.error(msg.format(fmt))
+                elif msg.category == "warning":
+                    self.log.warning(msg.format(fmt))
+                else:
+                    self.log.info(msg.format(fmt))
+            self.fail("Pylint failed, see base.log for details.")
+
+
+if __name__ == '__main__':
+    QemuBaseTest.main()
-- 
2.51.1