fmeTestSupport

Context

fmeTestSupport.Context.Context(doAction: Callable[[], YieldType] | Callable[[MemoryType], YieldType], undoAction: Callable[[YieldType], None] | Callable[[YieldType, MemoryType], None], undoOnError: bool = True, memory: MemoryType = None) ContextManager[YieldType][source]

Generic context manager to temporarily do something, and then undo it on exit, but (optionally) only if no exception has occurred in between.

Parameters:
  • doAction – Callback to be called before yielding

  • undoAction – Callback to be called on exit

  • undoOnError – If set, the undoAction is NOT executed if an exception occurred within the context manager body

  • memory – Optional mutable object (e.g. a dict) that doAction can use to remember stuff required by undoAction. If provided, it is passed to both functions as first/second parameter.

Yields:

The return value of doAction

fmeTestSupport.Context.TemporaryItems(dictionary: MutableMapping, additionalItems: dict, unsetOnError: bool = True)[source]

Contextmanager that temporarily extends a dictionary with additional items. If the provided additionalItems overwrite pre-existing ones, the original valus will be restored afterwards.

Parameters:
  • dictionary – Target dictionary to be extended.

  • additionalItems – Source dictionary to be used to extend the given target dictionary.

  • unsetOnError – If set, the variables are NOT unset if an exception occurred within the context manager body.

Yields:

None

fmeTestSupport.Context.EnvironmentVariables(additionalItems: Dict[str, str], unsetOnError: bool = True)[source]

Context manager to temporarily set environment variables. Internally uses AdditionalItems().

Parameters:
  • additionalItems – Dictionary to be used to extend environment variables.

  • unsetOnError – If set, the variables are NOT unset if an exception occurred within the context manager body.

Yields:

None

MlabContext

fmeTestSupport.MlabContext.ScriptVariable(context: ModuleContext, variableName: str, value: Any, unsetOnError=True) ContextManager[None][source]

Context manager to temporarily set a script variable (via MLAB.setScriptVariable()).

Parameters:
  • context – The module context.

  • variableName – Name of the variable

  • unsetOnError – If set, the variable is NOT unset if an exception occurred within the context manager body.

Yields:

None

fmeTestSupport.MlabContext.MlabVariable(variableName: str, value: Any, unsetOnError=True) ContextManager[None][source]

Context manager to temporarily set an MLAB (MDL) variable (via MLAB.setVariable()).

Parameters:
  • context – The module context.

  • variableName – Name of the variable

  • unsetOnError – If set, the variable is NOT unset if an exception occurred within the context manager body.

Yields:

None

fmeTestSupport.MlabContext.MlabVariables(varDict: Dict[str, Any], unsetOnError=True) ContextManager[None][source]

Context manager to temporarily set multiple MLAB (MDL) variables (via MLAB.setVariable()).

Parameters:
  • context – The module context.

  • variableName – Name of the variable

  • unsetOnError – If set, the variable is NOT unset if an exception occurred within the context manager body.

Yields:

None

fmeTestSupport.MlabContext.FieldValues(moduleContext, fieldDict: Dict[str, Any], unsetOnError=True) ContextManager[None][source]

Context manager to temporarily set multiple MeVisLab fields to different values. Note that ‘updateValue’ is used to set/unset the value, so notifications will only arise if a value changes.

Parameters:
  • moduleContext – The module context.

  • fieldDict – Dictionary with field names and values. The field names must be relative to the passed module context.

  • unsetOnError – If set, the variable is NOT unset if an exception occurred within the context manager body.

Yields:

None

fmeTestSupport.MlabContext.NewModule(moduleType: str, instanceName: str | None = None, context: ModuleContext | None = None, addAsRemoteModule=False, alsoRemoveOnError=True) ContextManager[ModuleContext][source]

Context manager to temporarily add a module to the network.

Parameters:
  • moduleType – The module type

  • instanceName – Optional instance name for the created module

  • context – Optional context for the created module. If omitted/None, Base.getTestCaseContext() is assumed.

  • addAsRemoteModule – Id true, the module is added as a remote module (instead of in the same process)

  • alsoRemoveOnError – If set, the module is NOT removed if an exception occurred in the context manager body.

Yields:

The created module

Paths

fmeTestSupport.Paths.GuaranteedTemporaryPath(path: str, removeOnError=True) ContextManager[None][source]

Context manager to return a “guaranteed” temporary path, that is reused if existing, or created and afterwards deleted if not.

Parameters:

removeOnError – If set, the directory is NOT removed if an exception occurred within the context manager body, even if it was previously created.

Yields:

None

fmeTestSupport.Paths.TemporaryDirectory(removeOnError=True) ContextManager[str][source]

Creates a temporary directory and removes it automatically afterwards.

Parameters:

removeOnError – If set, the directory is NOT removed if an exception occurred within the context manager body.

Yields:

Path to the created temporary directory

fmeTestSupport.Paths.isSubPath(path: [<class 'str'>, <class 'pathlib.Path'>], baseFolder: [<class 'str'>, <class 'pathlib.Path'>]) bool[source]

Returns True if path is a sub-path of baseFolder, i.e. if path starts with baseFolder, e.g. IsSubPath(“a/b/c”, “a/b”) == True. Will not do anything on the file system, just does a plain comparison that compensates for slash/backslash and, under Windows, case differences.

Parameters:
  • path – Path to check if it is a sub directory of path

  • baseFolder – Expected base directory of path

Returns:

True if path is identical to or a true sub-path of baseFolder

fmeTestSupport.Paths.isTrueSubPath(path: [<class 'str'>, <class 'pathlib.Path'>], baseFolder: [<class 'str'>, <class 'pathlib.Path'>]) bool[source]

Returns True if path is a true sub-path of baseFolder, i.e. if path starts with baseFolder, e.g. IsSubPath(“a/b/c”, “a/b”) == True, but path is not identical to baseFolder. Will not do anything on the file system, just does a plain comparison that compensates for slash/backslash and, under Windows, case differences.

Parameters:
  • path – Path to check if it is a sub directory of path

  • baseFolder – Expected base directory of path

Returns:

True if path is a true sub-path of baseFolder

fmeTestSupport.Paths.areIdenticalPaths(path1: [<class 'str'>, <class 'pathlib.Path'>], path2: [<class 'str'>, <class 'pathlib.Path'>]) bool[source]
Returns:

True if the two given path strings point to identical paths.

fmeTestSupport.Paths.normalizedPath(path: [<class 'str'>, <class 'pathlib.Path'>]) PurePath[source]

Apply to normalize a path before comparing for equality or similar.

Returns:

Normalized path as PurePath

PythonTestUtils

fmeTestSupport.PythonTestUtils.isMeVisLabAvailable()[source]
Returns:

TRUE if running in a MeVisLab python environment

TestCase

fmeTestSupport.TestCase.injectTestCase(testCaseClass, context)[source]
fmeTestSupport.TestCase.iterTestCenterTestCaseClasses(context)[source]

Generator yielding all TestCenterTestCaseBase derived classes in the given context.

fmeTestSupport.TestCase.injectAllTestCenterTestCases(context)[source]

Injects all test methods found in classes derived from TestCenterTestCaseBase into the given context (e.g. globals()). Will ignore test classes that are superclasses of other test classes in the given context to prevent duplicate test functions for test hierarchies.

TestCenterTestCase

class fmeTestSupport.TestCenterTestCase.TestCenterTestCaseBase[source]

Bases: object

Base class for all TestCenter tests, adding setup and tearDown.

setUp()[source]

Called before a test function is executed. Do not forget to first call this superclass implementation when overwriting in a derived class.

tearDown()[source]

Called after a test function is fully executed. When overwriting in a derived class, do not forget to call this superclass implementation at the end of your custom implementation.

class fmeTestSupport.TestCenterTestCase.TestCenterTestCase[source]

Bases: TestCenterTestCaseBase

Base class for TestCenter tests, adding extending TestCenterTestCaseBase with convenience methods implemented via dynamic module creation.

setUp()[source]

Called before a test function is executed. Do not forget to first call this superclass implementation when overwriting in a derived class.

tearDown()[source]

Called after a test function is fully executed. When overwriting in a derived class, do not forget to call this superclass implementation at the end of your custom implementation.

_loadImageFromDataTo(subPath, targetField)[source]

Loads an image file from a relative path in test’s local ‘Data’ directory and connects it to given ‘Image’ typed field.

_loadImageTo(fullPath, targetField)[source]

Loads an image file from given path and connects it to given ‘Image’ typed field.

_loadAndConnectImageFromDataDirectoryTo(filename, targetField)[source]

Just redirects to _loadImageFromDataTo().

_loadAndConnectImageTo(fullPath, targetField)[source]

Just redirects to _loadImageTo().

_addModule(name)[source]

Adds a new module temporary to test network and returns corresponding MLABModule object. The module will automatically be removed in tearDown().

_loadMLBaseFromDataTo(subPath, targetField)[source]

Loads an MLBase file from a relative path in test’s local ‘Data’ directory and connects it to given ‘MLBase’ typed field.

_loadMLBaseTo(fullPath, targetField)[source]

Loads an MLBase file from given path and connects it to given ‘MLBase’ typed field.

_loadCSOListFromDataTo(subPath, targetField)[source]

Loads a CSOList file from a relative path in test’s local ‘Data’ directory and connects it to given ‘MLBase’ typed field.

_loadCSOListTo(fullPath, targetField)[source]

Loads a CSOList file from given path and connects it to given ‘MLBase’ typed field.

_loadWEMFromDataTo(subPath, targetField)[source]

Loads a WEM file from a relative path in test’s local ‘Data’ directory and connects it to given ‘MLBase’ typed field.

_loadWEMTo(fullPath, targetField)[source]

Loads a WEM file from given path and connects it to given ‘MLBase’ typed field.

_compareImageValuesWithFileFromData(field, subPath, epsilon)[source]

Compares image values of ‘Image’ typed field with a file located in test’s local ‘Data’ directory using given epsilon.

_compareImageValuesWithFile(field, fullPath, epsilon)[source]

Compares image values of ‘Image’ typed field with a file using given epsilon.

TestGrouping

fmeTestSupport.TestGrouping.addTestGroup(groupID, prefix, functionScope, context)[source]

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.

Parameters:
  • groupID – Name of the created group

  • prefix – Common prefix of test function names to be included into the group

  • functionScope – Scope to search for test functions, typically globals()

  • context – Context to create the group in, typically ctx or Base.getTestCaseContext()

Returns:

None

TimeMeasurement

fmeTestSupport.TimeMeasurement.measureElapsedTime(fct, *args, **kwargs)[source]

Measure the time the given function runs when called. All additional arguments are passed to the function.

Returns:

Duration of the call in seconds.