summaryrefslogtreecommitdiffstats
path: root/meta/lib/patchtest/tests/test_python_pylint.py
diff options
context:
space:
mode:
authorTrevor Gamblin <tgamblin@baylibre.com>2023-09-13 13:00:46 -0400
committerRichard Purdie <richard.purdie@linuxfoundation.org>2023-09-14 15:20:08 +0100
commit4a6f38c5327b40a45c340af49fee9a0d5cc890bd (patch)
tree669ae555ecc031990579baa207d40f38ab7e1335 /meta/lib/patchtest/tests/test_python_pylint.py
parente12e6d94ecbea6e0dafc080f2f196e12228730eb (diff)
downloadpoky-4a6f38c5327b40a45c340af49fee9a0d5cc890bd.tar.gz
patchtest: Add tests from patchtest oe repo
Copy the core components of the patchtest-oe repo into meta/lib/patchtest in oe-core. (From OE-Core rev: 257f64f4e4414b78981104aec132b067beb5a92a) Signed-off-by: Trevor Gamblin <tgamblin@baylibre.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/patchtest/tests/test_python_pylint.py')
-rw-r--r--meta/lib/patchtest/tests/test_python_pylint.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/meta/lib/patchtest/tests/test_python_pylint.py b/meta/lib/patchtest/tests/test_python_pylint.py
new file mode 100644
index 0000000000..ea8efb7c2a
--- /dev/null
+++ b/meta/lib/patchtest/tests/test_python_pylint.py
@@ -0,0 +1,61 @@
1# Checks related to the python code done with pylint
2#
3# Copyright (C) 2016 Intel Corporation
4#
5# SPDX-License-Identifier: GPL-2.0
6
7import base
8from data import PatchTestInput
9import pylint.epylint as lint
10
11class PyLint(base.Base):
12 pythonpatches = []
13 pylint_pretest = {}
14 pylint_test = {}
15 pylint_options = " -E --disable='E0611, E1101, F0401, E0602' --msg-template='L:{line} F:{module} I:{msg}'"
16
17 @classmethod
18 def setUpClassLocal(cls):
19 # get just those patches touching python files
20 cls.pythonpatches = []
21 for patch in cls.patchset:
22 if patch.path.endswith('.py'):
23 if not patch.is_removed_file:
24 cls.pythonpatches.append(patch)
25
26 def setUp(self):
27 if self.unidiff_parse_error:
28 self.skip('Python-unidiff parse error')
29 if not PatchTestInput.repo.canbemerged:
30 self.skip('Patch cannot be merged, no reason to execute the test method')
31 if not PyLint.pythonpatches:
32 self.skip('No python related patches, skipping test')
33
34 def pretest_pylint(self):
35 for pythonpatch in self.pythonpatches:
36 if pythonpatch.is_modified_file:
37 (pylint_stdout, pylint_stderr) = lint.py_run(command_options = pythonpatch.path + self.pylint_options, return_std=True)
38 for line in pylint_stdout.readlines():
39 if not '*' in line:
40 if line.strip():
41 self.pylint_pretest[line.strip().split(' ',1)[0]] = line.strip().split(' ',1)[1]
42
43 def test_pylint(self):
44 for pythonpatch in self.pythonpatches:
45 # a condition checking whether a file is renamed or not
46 # unidiff doesn't support this yet
47 if pythonpatch.target_file is not pythonpatch.path:
48 path = pythonpatch.target_file[2:]
49 else:
50 path = pythonpatch.path
51 (pylint_stdout, pylint_stderr) = lint.py_run(command_options = path + self.pylint_options, return_std=True)
52 for line in pylint_stdout.readlines():
53 if not '*' in line:
54 if line.strip():
55 self.pylint_test[line.strip().split(' ',1)[0]] = line.strip().split(' ',1)[1]
56
57 for issue in self.pylint_test:
58 if self.pylint_test[issue] not in self.pylint_pretest.values():
59 self.fail('Errors in your Python code were encountered',
60 'Correct the lines introduced by your patch',
61 data=[('Output', 'Please, fix the listed issues:'), ('', issue + ' ' + self.pylint_test[issue])])