TestCenter Reference
TestSupport.Base Namespace Reference

Basic support functions. More...

Classes

class  HtmlDiff
 
class  MacrosShouldLogOnSuccessDecorator
 Decorator to globally enable or disable if the ASSERT_*/EXPECT_* macros log an info message on success. More...
 

Functions

def clearEncodingCache ()
 
def getSourceFileEncoding (filename)
 
def decodeSourceCodeLine (filename, line)
 
def getPackageList ()
 Returns the list of available packages. More...
 
def getTestCaseContext ()
 Get the context of the test. More...
 
def getModuleName ()
 Return the name of the currently tested module. More...
 
def getTestFunctionName ()
 Returns the name of the current test function. More...
 
def setMacrosShouldLogOnSuccess (logOnSuccess)
 Globally enables or disables if the ASSERT_*/EXPECT_* macros log an info message on success. More...
 
def shouldLogOnSuccess (logOnSuccess=None)
 
def LoggingDecorator (func)
 Internal decorator used for creating messages in compare methods. More...
 
def escapedUnicode (value)
 
def compareEqual (a, b, comment="", logOnSuccess=None)
 Compare the two given values for equality. More...
 
def compareNotEqual (a, b, comment="", logOnSuccess=None)
 Compare the two given values for inequality. More...
 
def compareLessThan (a, b, comment="", logOnSuccess=None)
 Compare the two given values if the first one is less than the second. More...
 
def compareLessThanOrEqual (a, b, comment="", logOnSuccess=None)
 Compare the two given values if the first one is less than or equal to the second. More...
 
def compareFloatEqual (a, b, comment="", epsilon=0.0001, logOnSuccess=None)
 Compare the two given float values if they are epsilon-equal. More...
 
def compareFloatNotEqual (a, b, comment="", epsilon=0.0001, logOnSuccess=None)
 Compare the two given float values if they are epsilon-unequal. More...
 
def compareFloatLessThan (a, b, comment="", logOnSuccess=None)
 Compare the two given float values if the first is less than the second. More...
 
def compareFloatLessThanOrEqual (a, b, comment="", epsilon=0.0001, logOnSuccess=None)
 Compare the two given float values if the first is less than or equal to the second. More...
 
def verifyTrue (expr, comment="", logOnSuccess=None, msg=None)
 If the given expression evaluates to False, an error is logged. More...
 
def verifyFalse (expr, comment="", logOnSuccess=None, msg=None)
 If the given expression evaluates to True, an error is logged. More...
 
def expectError (function, args=[], kargs={}, errorRegExp=None)
 Call the given function with the given parameters and expect an error. More...
 
def expectWarning (function, args=[], kargs={}, warningRegExp=None)
 Call the given function with the given parameters and expect a warning. More...
 
def expectWarningAndError (function, args=[], kargs={}, errorRegExp=None, warningRegExp=None)
 Call the given function with the given parameters and expect both a warning and an error. More...
 
def expectInfo (function, args=[], kargs={}, infoRegExp=None, allowUnexpectedMessages=True)
 Call the given function with the given parameters and expect an info message. More...
 
def getResultDirectory ()
 Getter for the directory used to save results. More...
 
def getDataDirectory ()
 Method to return path to the data files. More...
 
def getFileInDataDirectory (filename)
 Returns the absolute filename of a file in the data directory using getDataDirectory(). More...
 
def existsFileInDataDirectory (filename)
 Checks if the given file exists in the data directory. More...
 
def getExternalDataDirectory (name, subDirectory=None)
 Method to return path to the external data directory. More...
 
def pushChangeSet ()
 Push a new ChangeSet to the stack. More...
 
def popChangeSet ()
 Pop the last ChangeSet from the stack. More...
 
def getHash (filename, hash="SHA1", encoder="Hex")
 Compute a hash for the content of the given file. More...
 
def createExtraTestCaseResult (testCaseName, package, author, duration, maintainer=None, file=None, line=None, comment=None, showTestFunctionSortingLiterals=False)
 Creates an ExtraTestCaseResult object. More...
 
def addExtraTestCaseResult (extraTestCaseResult)
 Adds an ExtraTestCaseResult object. More...
 
def pushEnvironment ()
 Pushes the current environment dictionary on a stack, so that modifications can be applied and be popped again later. More...
 
def popEnvironment ()
 Pops the last pushed environment dictionary from a stack and makes it the current one. More...
 
def pushEnvironmentDecorator (func)
 
def EnableHighPrecisionLoggingTimeStampsDecorator (func)
 
def createHtmlDiff (fromLines, toLines, showOnlyContextOfDiff=False, numberOfContextLines=10)
 
def disableTestFunctionIf (condition)
 
def hardwareSupportsOffscreenRendering ()
 
def runProcess (command, wait=True, expectSuccess=True, expectFailure=False, verbose=True)
 
def verifyProcessResult (command, shortCommand, returncode, stdout, stderr, expectSuccess=True, expectFailure=False, verbose=True)
 
def runPythonScript (script, arguments, wait=True, expectSuccess=True, expectFailure=False, verbose=True)
 

Variables

 gEncodingRegExp = re.compile("^[ \t\v]*#.*?coding[:=][ \t]*([-_.a-zA-Z0-9]+)")
 
dictionary gEncodingCache = {}
 

Detailed Description

Basic support functions.

Function Documentation

◆ addExtraTestCaseResult()

def TestSupport.Base.addExtraTestCaseResult (   extraTestCaseResult)

Adds an ExtraTestCaseResult object.

See createExtraTestCaseResult().

Parameters
extraTestCaseResultA ExtraTestCaseResult object.

Definition at line 551 of file Base.py.

◆ clearEncodingCache()

def TestSupport.Base.clearEncodingCache ( )

Definition at line 31 of file Base.py.

Referenced by TestCenterAdvanced.Slave.Slave.unloadTestCase().

◆ compareEqual()

def TestSupport.Base.compareEqual (   a,
  b,
  comment = "",
  logOnSuccess = None 
)

Compare the two given values for equality.

If the two values are unequal an error is logged.

Parameters
aThe first value.
bThe second value.
commentOptional comment shown if comparison fails.
logOnSuccessPrint message in case of success.
Returns
True if values are equal.

Definition at line 187 of file Base.py.

◆ compareFloatEqual()

def TestSupport.Base.compareFloatEqual (   a,
  b,
  comment = "",
  epsilon = 0.0001,
  logOnSuccess = None 
)

Compare the two given float values if they are epsilon-equal.

Parameters
aThe first value.
bThe second value.
commentComment shown if comparison fails.
epsilonEpsilon used for float comparison.
logOnSuccesPrint message in case of success.
Returns
True if values are equal.

Definition at line 244 of file Base.py.

◆ compareFloatLessThan()

def TestSupport.Base.compareFloatLessThan (   a,
  b,
  comment = "",
  logOnSuccess = None 
)

Compare the two given float values if the first is less than the second.

Parameters
aThe first value.
bThe second value.
commentComment shown if comparison fails.
logOnSuccesPrint message in case of success.
Returns
True if first value is less than the second.

Definition at line 271 of file Base.py.

◆ compareFloatLessThanOrEqual()

def TestSupport.Base.compareFloatLessThanOrEqual (   a,
  b,
  comment = "",
  epsilon = 0.0001,
  logOnSuccess = None 
)

Compare the two given float values if the first is less than or equal to the second.

Parameters
aThe first value.
bThe second value.
commentComment shown if comparison fails.
epsilonEpsilon used for float comparison.
logOnSuccesPrint message in case of success.
Returns
True if first value is less than or equal to the second.

Definition at line 286 of file Base.py.

◆ compareFloatNotEqual()

def TestSupport.Base.compareFloatNotEqual (   a,
  b,
  comment = "",
  epsilon = 0.0001,
  logOnSuccess = None 
)

Compare the two given float values if they are epsilon-unequal.

Parameters
aThe first value.
bThe second value.
commentComment shown if comparison fails.
epsilonEpsilon used for float comparison.
logOnSuccesPrint message in case of success.
Returns
True if values are unequal.

Definition at line 258 of file Base.py.

◆ compareLessThan()

def TestSupport.Base.compareLessThan (   a,
  b,
  comment = "",
  logOnSuccess = None 
)

Compare the two given values if the first one is less than the second.

Parameters
aThe first value.
bThe second value.
commentOptional comment shown if comparison fails.
logOnSuccessPrint message in case of success.
Returns
True if the first value is less than the second.

Definition at line 218 of file Base.py.

◆ compareLessThanOrEqual()

def TestSupport.Base.compareLessThanOrEqual (   a,
  b,
  comment = "",
  logOnSuccess = None 
)

Compare the two given values if the first one is less than or equal to the second.

Parameters
aThe first value.
bThe second value.
commentOptional comment shown if comparison fails.
logOnSuccessPrint message in case of success.
Returns
True if the first value less than or equal to the second.

Definition at line 231 of file Base.py.

◆ compareNotEqual()

def TestSupport.Base.compareNotEqual (   a,
  b,
  comment = "",
  logOnSuccess = None 
)

Compare the two given values for inequality.

If the two values are equal an error is logged.

Parameters
aThe first value.
bThe second value.
commentOptional comment shown if comparison fails.
logOnSuccessPrint message in case of success.
Returns
True if the values are unequal.

Definition at line 203 of file Base.py.

◆ createExtraTestCaseResult()

def TestSupport.Base.createExtraTestCaseResult (   testCaseName,
  package,
  author,
  duration,
  maintainer = None,
  file = None,
  line = None,
  comment = None,
  showTestFunctionSortingLiterals = False 
)

Creates an ExtraTestCaseResult object.

The extra test case results enable test cases to provide additional results as a test case. For example, this is used for web tests, where the web application generates an xml report.

Parameters
testCaseNameThe name of the test case.
packageThe MeVisLab package of the test case.
authorThe author of the test case.
maintainerThe current maintainer of the test case.
Returns
The ExtraTestCaseResult object.

Definition at line 542 of file Base.py.

◆ createHtmlDiff()

def TestSupport.Base.createHtmlDiff (   fromLines,
  toLines,
  showOnlyContextOfDiff = False,
  numberOfContextLines = 10 
)

Definition at line 653 of file Base.py.

◆ decodeSourceCodeLine()

def TestSupport.Base.decodeSourceCodeLine (   filename,
  line 
)

Definition at line 56 of file Base.py.

References TestSupport.Base.getSourceFileEncoding().

Referenced by TestSupport.Base.LoggingDecorator().

◆ disableTestFunctionIf()

def TestSupport.Base.disableTestFunctionIf (   condition)

Definition at line 661 of file Base.py.

◆ EnableHighPrecisionLoggingTimeStampsDecorator()

def TestSupport.Base.EnableHighPrecisionLoggingTimeStampsDecorator (   func)

Definition at line 588 of file Base.py.

◆ escapedUnicode()

def TestSupport.Base.escapedUnicode (   value)
Returns a unicode representation of value. If value is of type bytes then non-ASCII characters
    are escaped and a representation of the string is returned.
    For example, the 8-bit literal b'\x01' becomes 'u"\x01"'.

Definition at line 168 of file Base.py.

◆ existsFileInDataDirectory()

def TestSupport.Base.existsFileInDataDirectory (   filename)

Checks if the given file exists in the data directory.

Returns
True if the file exists in the data directory, False otherwise.

Definition at line 451 of file Base.py.

◆ expectError()

def TestSupport.Base.expectError (   function,
  args = [],
  kargs = {},
  errorRegExp = None 
)

Call the given function with the given parameters and expect an error.

Please note that nesting the expect{Warning, Error} methods will lead to invalid line numbers in the reports!

Parameters
functionThe function to be called.
argsList of parameters for the function.
kargsDictionary of named parameters for the function.
errorRegExpOptional RegexObject to control which errors are handled. (Strings will be assumed to be regular expressions and compiled automatically.)
Returns
Return value of the called function.

Definition at line 330 of file Base.py.

◆ expectInfo()

def TestSupport.Base.expectInfo (   function,
  args = [],
  kargs = {},
  infoRegExp = None,
  allowUnexpectedMessages = True 
)

Call the given function with the given parameters and expect an info message.

Please note that nesting the expect{Warning, Error, Info} methods will lead to invalid line numbers in the reports!

Parameters
functionThe function to be called.
argsList of parameters for the function.
kargsDictionary of named parameters for the function.
infoRegExpOptional RegexObject to control which info messages are expected.
allowUnexpectedMessagesOptional flag to specify if unexpected messages are allowed.
Returns
Return value of the called function.

Definition at line 406 of file Base.py.

◆ expectWarning()

def TestSupport.Base.expectWarning (   function,
  args = [],
  kargs = {},
  warningRegExp = None 
)

Call the given function with the given parameters and expect a warning.

Please note that nesting the expect{Warning, Error, Info} methods will lead to invalid line numbers in the reports!

Parameters
functionThe function to be called.
argsList of parameters for the function.
kargsDictionary of named parameters for the function.
warningRegExpOptional RegexObject to control which warnings are handled. (Strings will be assumed to be regular expressions and compiled automatically.)
Returns
Return value of the called function.

Definition at line 355 of file Base.py.

◆ expectWarningAndError()

def TestSupport.Base.expectWarningAndError (   function,
  args = [],
  kargs = {},
  errorRegExp = None,
  warningRegExp = None 
)

Call the given function with the given parameters and expect both a warning and an error.

Please note that nesting the expect{Warning, Error, Info} methods will lead to invalid line numbers in the reports!

Parameters
functionThe function to be called.
argsList of parameters for the function.
kargsDictionary of named parameters for the function.
errorRegExpOptional RegexObject to control which errors are handled.
warningRegExpOptional RegexObject to control which warnings are handled.
Returns
Return value of the called function.

Definition at line 380 of file Base.py.

◆ getDataDirectory()

def TestSupport.Base.getDataDirectory ( )

Method to return path to the data files.

Sometimes data is required for test case that should not reside inside the repository. This is where the dataDirectory option in the test case definition comes into play. This is the value that can be changed using this tag. The default is /Data.

Returns
The path to the directory where required data lives.

Definition at line 437 of file Base.py.

◆ getExternalDataDirectory()

def TestSupport.Base.getExternalDataDirectory (   name,
  subDirectory = None 
)

Method to return path to the external data directory.

Sometimes test cases require large data that should not be added to the version control. The external data directories provide a solution for such situations. If the subDirectory parameter is not given the same folder structure is used like in the calling test case. If the data directory does not exist None is returned. name The name of the external data directory (FME or MMS for example). subDirectory The sub directory in the external data store.

Returns
The path to the directory where required data lives.

Definition at line 465 of file Base.py.

◆ getFileInDataDirectory()

def TestSupport.Base.getFileInDataDirectory (   filename)

Returns the absolute filename of a file in the data directory using getDataDirectory().

Returns
The absolute filename of a file in the data directory.

Definition at line 444 of file Base.py.

◆ getHash()

def TestSupport.Base.getHash (   filename,
  hash = "SHA1",
  encoder = "Hex" 
)

Compute a hash for the content of the given file.

The hash is computed using the ImageHash module for images and using python's hashlib for other files.

Parameters
filenameThe file that should be hashed.
hashThe hash algorithm to use.
encoderThe encoder to use.
Returns
The computed hash or None in case of failure.

Definition at line 511 of file Base.py.

◆ getModuleName()

def TestSupport.Base.getModuleName ( )

Return the name of the currently tested module.

If the current test case is not a generic one None is returned.

Returns
The name of currently tested module.

Definition at line 89 of file Base.py.

◆ getPackageList()

def TestSupport.Base.getPackageList ( )

Returns the list of available packages.

The list of packages that is said to be thought of being available. This is for example helpful if a developer having installed all the source, but wants to verify only modules are used in seeAlso that are available in public installers.

Returns
List of packages that should be thought available.

Definition at line 72 of file Base.py.

◆ getResultDirectory()

def TestSupport.Base.getResultDirectory ( )

Getter for the directory used to save results.

All results should be collected in the given directory such that the generated data will be cleaned up when appropriate.

Returns
Path to the result directory.

Definition at line 426 of file Base.py.

◆ getSourceFileEncoding()

def TestSupport.Base.getSourceFileEncoding (   filename)

Definition at line 35 of file Base.py.

Referenced by TestSupport.Base.decodeSourceCodeLine().

◆ getTestCaseContext()

def TestSupport.Base.getTestCaseContext ( )

Get the context of the test.

The context in which the current test is loaded. This is where the test related network is available.

Returns
The current test case's context.

Definition at line 81 of file Base.py.

◆ getTestFunctionName()

def TestSupport.Base.getTestFunctionName ( )

Returns the name of the current test function.

Returns
The name of current test function.

Definition at line 95 of file Base.py.

◆ hardwareSupportsOffscreenRendering()

def TestSupport.Base.hardwareSupportsOffscreenRendering ( )

Definition at line 674 of file Base.py.

◆ LoggingDecorator()

def TestSupport.Base.LoggingDecorator (   func)

Internal decorator used for creating messages in compare methods.

Definition at line 150 of file Base.py.

References TestSupport.Base.decodeSourceCodeLine().

Referenced by TestSupport.Logging.setStopped().

◆ popChangeSet()

def TestSupport.Base.popChangeSet ( )

Pop the last ChangeSet from the stack.

At least two ChangeSets (the global one and the one for the function) must remain on the stack as they are not in the control of the user.

Definition at line 494 of file Base.py.

Referenced by TestCenterAdvanced.TestCase.TestCase.callFieldValueTestCase(), and TestCenterAdvanced.TestCase.TestCase.deactivate().

◆ popEnvironment()

def TestSupport.Base.popEnvironment ( )

Pops the last pushed environment dictionary from a stack and makes it the current one.

See pushEnvironment().

Returns
Returns if there was an environment dictionary to pop.

Definition at line 569 of file Base.py.

◆ pushChangeSet()

◆ pushEnvironment()

def TestSupport.Base.pushEnvironment ( )

Pushes the current environment dictionary on a stack, so that modifications can be applied and be popped again later.

See popEnvironment().

Definition at line 560 of file Base.py.

◆ pushEnvironmentDecorator()

def TestSupport.Base.pushEnvironmentDecorator (   func)

Definition at line 576 of file Base.py.

◆ runProcess()

def TestSupport.Base.runProcess (   command,
  wait = True,
  expectSuccess = True,
  expectFailure = False,
  verbose = True 
)

Definition at line 691 of file Base.py.

◆ runPythonScript()

def TestSupport.Base.runPythonScript (   script,
  arguments,
  wait = True,
  expectSuccess = True,
  expectFailure = False,
  verbose = True 
)

Definition at line 762 of file Base.py.

◆ setMacrosShouldLogOnSuccess()

def TestSupport.Base.setMacrosShouldLogOnSuccess (   logOnSuccess)

Globally enables or disables if the ASSERT_*/EXPECT_* macros log an info message on success.

It does not have to be reset, because the TestCenter enables it before each TestCase.

For example:

def setUpTestCase():

Definition at line 116 of file Base.py.

Referenced by TestSupport.Base.MacrosShouldLogOnSuccessDecorator.__call__(), and TestSupport.UnitTestSupport.TestCaseWithSupportData.getFileInTestSupportDataDirectory().

◆ shouldLogOnSuccess()

def TestSupport.Base.shouldLogOnSuccess (   logOnSuccess = None)

Definition at line 119 of file Base.py.

◆ verifyFalse()

def TestSupport.Base.verifyFalse (   expr,
  comment = "",
  logOnSuccess = None,
  msg = None 
)

If the given expression evaluates to True, an error is logged.

Parameters
exprThe expression that must evaluate to False.
commentOptional comment shown if expression is True.
logOnSuccesPrint message in case of success.
Returns
True if expression evaluates to False.

Definition at line 312 of file Base.py.

◆ verifyProcessResult()

def TestSupport.Base.verifyProcessResult (   command,
  shortCommand,
  returncode,
  stdout,
  stderr,
  expectSuccess = True,
  expectFailure = False,
  verbose = True 
)

Definition at line 726 of file Base.py.

◆ verifyTrue()

def TestSupport.Base.verifyTrue (   expr,
  comment = "",
  logOnSuccess = None,
  msg = None 
)

If the given expression evaluates to False, an error is logged.

Parameters
exprThe expression that must evaluate to True.
commentOptional comment shown if expression is not True.
logOnSuccesPrint message in case of success.
Returns
True if expression evaluates to True.

Definition at line 298 of file Base.py.

Variable Documentation

◆ gEncodingCache

dictionary TestSupport.Base.gEncodingCache = {}

Definition at line 29 of file Base.py.

◆ gEncodingRegExp

TestSupport.Base.gEncodingRegExp = re.compile("^[ \t\v]*#.*?coding[:=][ \t]*([-_.a-zA-Z0-9]+)")

Definition at line 28 of file Base.py.