Source code for fmeTestSupport.TestGrouping
# Copyright (c) Fraunhofer MEVIS, Germany. All rights reserved.
# **InsertLicense** code author="Jan-Martin Kuhnigk"
from mevis import MLAB
NUM_TEST_GROUP_INDEX_DIGITS = 4
[docs]def addTestGroup( groupID, prefix, functionScope, context ):
"""
Creates a new Test Case Group from all functions starting with a certain prefix (prefix starts after TEST, so
TEST01_Whatever matches the prefix 01, or 01_What, ...). Makes sure the order of the groups reflects the order
of the addTestGroup calls.
If no function matches the prefix, a warning is logged.
:param groupID: Name of the created group
:param prefix: Common prefix of test function names to be included into the group
:param functionScope: Scope to search for test functions, typically globals()
:param context: Context to create the group in, typically ctx or Base.getTestCaseContext()
:return: None
"""
def _getFunctionsWithPrefix( prefix ):
functions = [ ]
for fctName, fct in functionScope.items():
if fctName.startswith( prefix ) or fctName.startswith( "DISABLED_" + prefix ):
functions.append( fct )
return tuple( functions )
def _getGroupPrefixFromIndex( index ):
return "GROUP{0:0{1}}_".format( index, NUM_TEST_GROUP_INDEX_DIGITS )
def _getNextFreeGroupIndex( ):
index = context.scriptVariable("__nextFreeGroupIndex")
if index is None:
index = 0
context.setScriptVariable( "__nextFreeGroupIndex", index + 1 )
return index
matchingFunctions = _getFunctionsWithPrefix( "TEST" + prefix )
if matchingFunctions:
groupIndex = _getNextFreeGroupIndex()
groupName = "{}{}".format( _getGroupPrefixFromIndex( groupIndex ), groupID )
context.setScriptVariable( groupName, lambda: matchingFunctions )
else:
MLAB.logWarning( "Warning in addTestGroup: No test functions found that start with '{}'".format( prefix ))