Add support for test-os --cases option

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2022-12-04 16:44:14 +01:00
commit 142c1dbf6d
2 changed files with 16 additions and 2 deletions

View file

@ -82,7 +82,8 @@ class CmdTestOs(MachineCmd): # export
machine = None
try:
machine = await Machine.create(env)
test_cases = TestCases(env.args.test_case_path, dummies=env.args.dummy_tests)
case_filter = None if not env.args.cases else env.args.cases.split(',')
test_cases = TestCases(env.args.test_case_path, include=case_filter, dummies=env.args.dummy_tests)
for phase in TestPhases.Phase:
if not machine.clear_for_tests():
raise Exception("machine is not clear for running tests")
@ -123,5 +124,6 @@ class CmdTestOs(MachineCmd): # export
def add_parser(self, parsers):
p = super().add_parser(parsers)
p.add_argument( "--cases", help="List of dedicated test cases to run, wildcards are supported", default='')
self.__results.add_arguments(p)
return p

View file

@ -4,6 +4,7 @@ from abc import abstractmethod, ABC
import sys
import re
import inspect
import fnmatch
from jwutils.log import *
from jwutils.misc import *
from .TestCase import TestCase
@ -12,12 +13,21 @@ from .tcf import *
class TestCases: # export
def __init__(self, path, dummies=False):
def __match(self, case):
if self.__include is None:
return True
for pattern in self.__include:
if fnmatch.fnmatch(case.name, pattern):
return True
return False
def __init__(self, path, include=None, dummies=False):
self.__path = path.split(':')
self.__dummies = dummies
self.__idx = 0
self.__cases = []
self.__include = [include] if isinstance(include, str) else include
factories = set()
# use list() to avoid expansion of sys.modules during iteration
for name, mod in list(sys.modules.items()):
@ -35,6 +45,8 @@ class TestCases: # export
for c in cases:
if c.is_dummy and not self.__dummies:
continue
if not self.__match(c):
continue
c.factory = factory
self.__cases.append(c)