[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openembedded-core
Subject:    [OE-core] [PATCH 2/4] QA, ptest: Detect python and perl based tests
From:       "Yoann Congal" <yoann.congal () smile ! fr>
Date:       2023-09-29 22:05:01
Message-ID: 20230929220503.3169745-3-yoann.congal () smile ! fr
[Download RAW message or body]

From: Jérémy Rosen <jeremy.rosen@smile.fr>

match_line_in_files will look for a regex in all files matching a glob.

we use iglob to avoid a complete, recursive scan of all source. iglob is
based on python iterators and will scan as we walk through the directories

pytest are detected by looking for "import pytest" or "from pytest" in any
python file.

perl Test:: is detetected by looking for any t/*.t in the toplevel source
directory.

Signed-off-by: Jérémy Rosen <jeremy.rosen@smile.fr>
Reviewed-by: Yoann Congal <yoann.congal@smile.fr>
---
 meta/classes-global/insane.bbclass | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/meta/classes-global/insane.bbclass b/meta/classes-global/insane.bbclass
index 857f0a3736..31db707a33 100644
--- a/meta/classes-global/insane.bbclass
+++ b/meta/classes-global/insane.bbclass
@@ -1351,6 +1351,24 @@ python do_qa_patch() {
     ###########################################################################
     # Check for missing ptests
     ###########################################################################
+    def match_line_in_files(toplevel, filename_glob, line_regex):
+        import glob
+        # python 3.10 adds a root_dir parameter, but in 3.8 we must manually cwd
+        curdir = os.getcwd()
+        os.chdir(toplevel)
+        for entry in glob.iglob(filename_glob, recursive=True):
+            try:
+                with open(entry, 'r', encoding='utf-8', errors='ignore') as f:
+                    for line in f.readlines():
+                        if re.match(line_regex, line):
+                            os.chdir(curdir)
+                            return True
+            except FileNotFoundError:
+                # Broken symlink in source
+                pass
+        os.chdir(curdir)
+        return False
+
     srcdir = d.getVar('S')
     if not bb.utils.contains('DISTRO_FEATURES', 'ptest', True, False, d):
         pass
@@ -1360,6 +1378,14 @@ python do_qa_patch() {
     elif bb.data.inherits_class('ptest', d):
         bb.note("Package %s QA: skipping unimplemented-ptest: ptest implementation \
detected" % d.getVar('PN'))  
+    # Detect perl Test:: based tests
+    elif "t" in os.listdir(srcdir) and any(filename.endswith('.t') for filename in \
os.listdir(os.path.join(srcdir, 't'))): +        \
oe.qa.handle_error("unimplemented-ptest", "%s: perl Test:: based tests detected" % \
d.getVar('PN'), d) +
+    # Detect pytest-based tests
+    elif match_line_in_files(srcdir, "**/*.py", \
r'\s*(?:import\s*pytest|from\s*pytest)'): +        \
oe.qa.handle_error("unimplemented-ptest", "%s: pytest-based tests detected" % \
d.getVar('PN'), d) +
     oe.qa.exit_if_errors(d)
 }
 
-- 
2.30.2



-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#188450): https://lists.openembedded.org/g/openembedded-core/message/188450
Mute This Topic: https://lists.openembedded.org/mt/101667586/4454766
Group Owner: openembedded-core+owner@lists.openembedded.org
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [openembedded-core@marc.info]
-=-=-=-=-=-=-=-=-=-=-=-



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic