[elbe-devel] [PATCH 10/10] elbepack: test: remove custom testrunner

Thomas Weißschuh thomas.weissschuh at linutronix.de
Mon Mar 11 18:03:03 CET 2024


Everything has been switched to pytest.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
 debian/control            |   2 -
 elbepack/commands/test.py | 189 ----------------------------------------------
 2 files changed, 191 deletions(-)

diff --git a/debian/control b/debian/control
index d88b78fcf228..2afe8f6dc848 100644
--- a/debian/control
+++ b/debian/control
@@ -21,7 +21,6 @@ Build-Depends: debhelper-compat (= 12),
   python3-beaker,
   python3-cherrypy3,
   python3-debian,
-  python3-junitxml,
   python3-passlib,
   python3-spyne,
   python3-sqlalchemy,
@@ -132,7 +131,6 @@ Depends: ${misc:Depends},
   gnupg,
   mtd-utils,
   python3-apt,
-  python3-junit.xml,
   python3-mako,
   python3-parted,
   python3-passlib,
diff --git a/elbepack/commands/test.py b/elbepack/commands/test.py
index eba7d0aa7064..108ff7727bb5 100644
--- a/elbepack/commands/test.py
+++ b/elbepack/commands/test.py
@@ -4,25 +4,8 @@
 
 # elbepack/commands/test.py - Elbe unit test wrapper
 
-import enum
-import io
-import optparse
-import os
-import re
-import unittest
-import warnings
-
 from elbepack.shellhelper import command_out
 
-import junitxml as junit
-
-
-class ElbeTestLevel(enum.IntEnum):
-    BASE = enum.auto()
-    EXTEND = enum.auto()
-    INITVM = enum.auto()
-    FULL = enum.auto()
-
 
 class ElbeTestException(Exception):
 
@@ -40,175 +23,3 @@ def system(cmd, allow_fail=False):
     ret, out = command_out(cmd)
     if ret != 0 and not allow_fail:
         raise ElbeTestException(cmd, ret, out)
-
-
-class ElbeTestCase(unittest.TestCase):
-
-    level = ElbeTestLevel.BASE
-
-    def __init__(self, methodName='runTest'):
-        self.methodName = methodName
-        self.stdout = None
-        super().__init__(methodName)
-
-
-class ElbeTestSuite:
-
-    # This must be a list not a set!!!
-    tests = []
-
-    def __init__(self, tests):
-
-        for test in tests:
-
-            if isinstance(test, ElbeTestSuite):
-                continue
-
-            self.tests.append(test)
-
-    def __iter__(self):
-        for test in self.tests:
-            yield test
-
-    def filter_test(self, parallel, regex, invert):
-
-        node_id, N = parallel.split(',')
-
-        node_id = int(node_id)
-        N = int(N)
-
-        elected = []
-
-        rc = re.compile(regex, re.IGNORECASE)
-
-        self.tests.sort(key=str)
-
-        # Tests filtered here are skipped quietly
-        i = 0
-        for test in self.tests:
-
-            skip = False
-
-            if i % N != node_id:
-                skip = True
-
-            if not skip and ((rc.search(str(test)) is None) ^ invert):
-                skip = True
-
-            if not skip:
-                elected.append(test)
-
-            i += 1
-
-        self.tests = elected
-
-    def ls(self):
-        for test in self:
-            print(test)
-
-
-class ElbeJUnitXmlResult(junit.JUnitXmlResult):
-    def addSubTest(self, test, subtest, error):
-        super().addSubTest(test, subtest, error)
-
-        if error is None:
-            self.addSuccess(subtest)
-        else:
-            self.addError(subtest, error)
-
-
-class ElbeTestResult(unittest.TestResult):
-
-    def __init__(self):
-        super().__init__()
-        self.buffer = io.StringIO()
-        self.result = ElbeJUnitXmlResult(self.buffer)
-        self.success = False
-
-    def run_testsuite(self, suite):
-        self.result.startTestRun()
-        unittest.TestSuite(suite).run(self.result)
-        self.result.stopTestRun()
-        self.success = self.result.wasSuccessful()
-
-    def wasSuccessful(self):
-        return self.success
-
-    def get_xml(self):
-        with warnings.catch_warnings():
-            warnings.simplefilter('ignore')
-            results = self.buffer.getvalue()
-
-        return results
-
-
-def run_command(argv):
-
-    this_dir = os.path.dirname(os.path.realpath(__file__))
-    top_dir = os.path.join(this_dir, '..', '..')
-
-    oparser = optparse.OptionParser(usage='usage: %prog [options]')
-
-    oparser.add_option('-f', '--filter', dest='filter',
-                       metavar='REGEX', type='string', default='.*',
-                       help='Run specific test according to a filter rule')
-
-    oparser.add_option('-l', '--level', dest='level',
-                       type='string', default='BASE',
-                       help='Set test level threshold')
-
-    oparser.add_option('-i', '--invert', dest='invert_re',
-                       action='store_true', default=False,
-                       help='Invert the matching of --filter')
-
-    oparser.add_option('-d', '--dry-run', dest='dry_run',
-                       action='store_true', default=False,
-                       help='List tests that would have been executed and exit')
-
-    oparser.add_option('-p', '--parallel', dest='parallel',
-                       type='string', default='0,1',
-                       help='Run every thest where test_ID % N == node_ID')
-
-    oparser.add_option('-o', '--output', dest='output',
-                       type='string', default=None,
-                       help='Write XML output to file')
-
-    (opt, _) = oparser.parse_args(argv)
-
-    # Set test level threshold
-    if opt.level not in ElbeTestLevel.__members__:
-        print(
-            f"Invalid level value '{opt.level}'. Valid values are: "
-            f"{', '.join(key for key in ElbeTestLevel.__members__)}")
-        os.sys.exit(76)
-
-    ElbeTestCase.level = ElbeTestLevel[opt.level]
-
-    # Find all tests
-    loader = unittest.defaultTestLoader
-    loader.suiteClass = ElbeTestSuite
-    suite = loader.discover(top_dir)
-
-    # then filter them
-    suite.filter_test(opt.parallel, opt.filter, opt.invert_re)
-
-    # Dry run? Just exit gently
-    if opt.dry_run:
-        suite.ls()
-        print('======================================================================\n'
-              'This was a dry run. No tests were executed')
-        os.sys.exit(0)
-
-    result = ElbeTestResult()
-
-    result.run_testsuite(suite)
-
-    if opt.output is None:
-        print(result.get_xml())
-    else:
-        with open(opt.output, 'w') as f:
-            f.write(result.get_xml())
-
-    if not result.wasSuccessful():
-        print('Testsuite failed.')
-        os.sys.exit(77)

-- 
2.44.0



More information about the elbe-devel mailing list