TestCenter 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 | |
clearEncodingCache () | |
getSourceFileEncoding (filename) | |
decodeSourceCodeLine (filename, line) | |
getPackageList () | |
Returns the list of available packages. | |
getTestCaseContext () | |
Get the context of the test. | |
getModuleName () | |
Return the name of the currently tested module. | |
getTestFunctionName () | |
Returns the name of the current test function. | |
setMacrosShouldLogOnSuccess (logOnSuccess) | |
Globally enables or disables if the ASSERT_*/EXPECT_* macros log an info message on success. | |
shouldLogOnSuccess (logOnSuccess=None) | |
LoggingDecorator (func) | |
Internal decorator used for creating messages in compare methods. | |
escapedUnicode (value) | |
compareEqual (a, b, comment="", logOnSuccess=None) | |
Compare the two given values for equality. | |
compareNotEqual (a, b, comment="", logOnSuccess=None) | |
Compare the two given values for inequality. | |
compareLessThan (a, b, comment="", logOnSuccess=None) | |
Compare the two given values if the first one is less than the second. | |
compareLessThanOrEqual (a, b, comment="", logOnSuccess=None) | |
Compare the two given values if the first one is less than or equal to the second. | |
compareFloatEqual (a, b, comment="", epsilon=0.0001, logOnSuccess=None) | |
Compare the two given float values if they are epsilon-equal. | |
compareFloatNotEqual (a, b, comment="", epsilon=0.0001, logOnSuccess=None) | |
Compare the two given float values if they are epsilon-unequal. | |
compareFloatLessThan (a, b, comment="", logOnSuccess=None) | |
Compare the two given float values if the first is less than the second. | |
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. | |
verifyTrue (expr, comment="", logOnSuccess=None, msg=None) | |
If the given expression evaluates to False, an error is logged. | |
verifyFalse (expr, comment="", logOnSuccess=None, msg=None) | |
If the given expression evaluates to True, an error is logged. | |
expectError (function, args=[], kargs={}, errorRegExp=None, preventReplacingMessageSeverity=False) | |
Call the given function with the given parameters and expect an error. | |
expectWarning (function, args=[], kargs={}, warningRegExp=None) | |
Call the given function with the given parameters and expect a warning. | |
expectWarningAndError (function, args=[], kargs={}, errorRegExp=None, warningRegExp=None) | |
Call the given function with the given parameters and expect both a warning and an error. | |
ignoreError (function, args=(), kargs=None, errorRegExp=None, resultInfoDict=None) | |
Call the given function with the given parameters and ignores potential errors. | |
ignoreWarning (function, args=(), kargs=None, warningRegExp=None, resultInfoDict=None) | |
Call the given function with the given parameters and ignores potential warnings. | |
ignoreWarningAndError (function, args=[], kargs={}, errorRegExp=None, warningRegExp=None, resultInfoDict=None) | |
Call the given function with the given parameters and ignore both a warning and an error. | |
expectInfo (function, args=[], kargs={}, infoRegExp=None, allowUnexpectedMessages=True) | |
Call the given function with the given parameters and expect an info message. | |
hasNoWarning (warningRegExp=None) | |
hasWarning (warningRegExp=None) | |
hasError (errorRegExp=None) | |
hasWarningAndError (errorRegExp=None, warningRegExp=None) | |
hasInfo (infoRegExp=None, allowUnexpectedMessages=True) | |
getResultDirectory () | |
Getter for the directory used to save results. | |
getDataDirectory () | |
Method to return path to the data files. | |
getFileInDataDirectory (filename) | |
Returns the absolute filename of a file in the data directory using getDataDirectory(). | |
existsFileInDataDirectory (filename) | |
Checks if the given file exists in the data directory. | |
getExternalDataDirectory (name, subDirectory=None) | |
Method to return path to the external data directory. | |
pushChangeSet () | |
Push a new ChangeSet to the stack. | |
popChangeSet () | |
Pop the last ChangeSet from the stack. | |
getHash (filename, hash="SHA1", encoder="Hex") | |
Compute a hash for the content of the given file. | |
createExtraTestCaseResult (testCaseName, package, author, duration, maintainer=None, file=None, line=None, comment=None, showTestFunctionSortingLiterals=False) | |
Creates an ExtraTestCaseResult object. | |
addExtraTestCaseResult (extraTestCaseResult) | |
Adds an ExtraTestCaseResult object. | |
pushEnvironment () | |
Pushes the current environment dictionary on a stack, so that modifications can be applied and be popped again later. | |
popEnvironment () | |
Pops the last pushed environment dictionary from a stack and makes it the current one. | |
pushEnvironmentDecorator (func) | |
EnableHighPrecisionLoggingTimeStampsDecorator (func) | |
createHtmlDiff (fromLines, toLines, showOnlyContextOfDiff=False, numberOfContextLines=10) | |
disableTestFunctionIf (condition) | |
hardwareSupportsOffscreenRendering () | |
runProcess (command, wait=True, expectSuccess=True, expectFailure=False, verbose=True, env=None) | |
verifyProcessResult (command, shortCommand, returncode, stdout, stderr, expectSuccess=True, expectFailure=False, verbose=True) | |
runPythonScript (script, arguments, wait=True, expectSuccess=True, expectFailure=False, verbose=True, env=None) | |
Variables | |
gEncodingRegExp = re.compile("^[ \t\v]*#.*?coding[:=][ \t]*([-_.a-zA-Z0-9]+)") | |
dict | gEncodingCache = {} |
Basic support functions.
TestSupport.Base.addExtraTestCaseResult | ( | extraTestCaseResult | ) |
Adds an ExtraTestCaseResult object.
See createExtraTestCaseResult().
extraTestCaseResult | A ExtraTestCaseResult object. |
Definition at line 764 of file Base.py.
References TestSupport.Base.addExtraTestCaseResult().
Referenced by TestSupport.Base.addExtraTestCaseResult().
TestSupport.Base.clearEncodingCache | ( | ) |
Definition at line 39 of file Base.py.
Referenced by TestCenterAdvanced.Slave.Slave.unloadTestCase().
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.
a | The first value. |
b | The second value. |
comment | Optional comment shown if comparison fails. |
logOnSuccess | Print message in case of success. |
Definition at line 196 of file Base.py.
References TestSupport.Base.escapedUnicode(), and TestSupport.Base.shouldLogOnSuccess().
TestSupport.Base.compareFloatEqual | ( | a, | |
b, | |||
comment = "", | |||
epsilon = 0.0001, | |||
logOnSuccess = None ) |
Compare the two given float values if they are epsilon-equal.
a | The first value. |
b | The second value. |
comment | Comment shown if comparison fails. |
epsilon | Epsilon used for float comparison. |
logOnSucces | Print message in case of success. |
Definition at line 253 of file Base.py.
References TestSupport.Base.shouldLogOnSuccess().
TestSupport.Base.compareFloatLessThan | ( | a, | |
b, | |||
comment = "", | |||
logOnSuccess = None ) |
Compare the two given float values if the first is less than the second.
a | The first value. |
b | The second value. |
comment | Comment shown if comparison fails. |
logOnSucces | Print message in case of success. |
Definition at line 280 of file Base.py.
References TestSupport.Base.shouldLogOnSuccess().
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.
a | The first value. |
b | The second value. |
comment | Comment shown if comparison fails. |
epsilon | Epsilon used for float comparison. |
logOnSucces | Print message in case of success. |
Definition at line 295 of file Base.py.
References TestSupport.Base.shouldLogOnSuccess().
TestSupport.Base.compareFloatNotEqual | ( | a, | |
b, | |||
comment = "", | |||
epsilon = 0.0001, | |||
logOnSuccess = None ) |
Compare the two given float values if they are epsilon-unequal.
a | The first value. |
b | The second value. |
comment | Comment shown if comparison fails. |
epsilon | Epsilon used for float comparison. |
logOnSucces | Print message in case of success. |
Definition at line 267 of file Base.py.
References TestSupport.Base.shouldLogOnSuccess().
TestSupport.Base.compareLessThan | ( | a, | |
b, | |||
comment = "", | |||
logOnSuccess = None ) |
Compare the two given values if the first one is less than the second.
a | The first value. |
b | The second value. |
comment | Optional comment shown if comparison fails. |
logOnSuccess | Print message in case of success. |
Definition at line 227 of file Base.py.
References TestSupport.Base.escapedUnicode(), and TestSupport.Base.shouldLogOnSuccess().
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.
a | The first value. |
b | The second value. |
comment | Optional comment shown if comparison fails. |
logOnSuccess | Print message in case of success. |
Definition at line 240 of file Base.py.
References TestSupport.Base.escapedUnicode(), and TestSupport.Base.shouldLogOnSuccess().
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.
a | The first value. |
b | The second value. |
comment | Optional comment shown if comparison fails. |
logOnSuccess | Print message in case of success. |
Definition at line 212 of file Base.py.
References TestSupport.Base.escapedUnicode(), and TestSupport.Base.shouldLogOnSuccess().
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.
testCaseName | The name of the test case. |
package | The MeVisLab package of the test case. |
author | The author of the test case. |
maintainer | The current maintainer of the test case. |
TestSupport.Base.createHtmlDiff | ( | fromLines, | |
toLines, | |||
showOnlyContextOfDiff = False, | |||
numberOfContextLines = 10 ) |
TestSupport.Base.decodeSourceCodeLine | ( | filename, | |
line ) |
Definition at line 65 of file Base.py.
References TestSupport.Base.getSourceFileEncoding().
Referenced by TestSupport.Base.LoggingDecorator().
TestSupport.Base.EnableHighPrecisionLoggingTimeStampsDecorator | ( | func | ) |
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 177 of file Base.py.
Referenced by TestSupport.Base.compareEqual(), TestSupport.Base.compareLessThan(), TestSupport.Base.compareLessThanOrEqual(), TestSupport.Base.compareNotEqual(), and TestSupport.Base.verifyTrue().
TestSupport.Base.existsFileInDataDirectory | ( | filename | ) |
Checks if the given file exists in the data directory.
Definition at line 664 of file Base.py.
References TestSupport.Base.getFileInDataDirectory().
TestSupport.Base.expectError | ( | function, | |
args = [], | |||
kargs = {}, | |||
errorRegExp = None, | |||
preventReplacingMessageSeverity = False ) |
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!
function | The function to be called. |
args | List of parameters for the function. |
kargs | Dictionary of named parameters for the function. |
errorRegExp | Optional RegexObject to control which errors are handled. (Strings will be assumed to be regular expressions and compiled automatically.) |
preventReplacingMessageSeverity | If True, then the error state of the diagnosis console is not cleared. The test case must call MLAB.priv().clearLogState() itself in order to prevent it from failing. Default is False. |
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!
function | The function to be called. |
args | List of parameters for the function. |
kargs | Dictionary of named parameters for the function. |
infoRegExp | Optional RegexObject to control which info messages are expected. |
allowUnexpectedMessages | Optional flag to specify if unexpected messages are allowed. |
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!
function | The function to be called. |
args | List of parameters for the function. |
kargs | Dictionary of named parameters for the function. |
warningRegExp | Optional RegexObject to control which warnings are handled. (Strings will be assumed to be regular expressions and compiled automatically.) |
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!
function | The function to be called. |
args | List of parameters for the function. |
kargs | Dictionary of named parameters for the function. |
errorRegExp | Optional RegexObject to control which errors are handled. |
warningRegExp | Optional RegexObject to control which warnings are handled. |
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.
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. @params name The name of the external data directory (FME or MMS for example). @params subDirectory The sub directory in the external data store.
TestSupport.Base.getFileInDataDirectory | ( | filename | ) |
Returns the absolute filename of a file in the data directory using getDataDirectory().
Definition at line 657 of file Base.py.
Referenced by TestSupport.Base.existsFileInDataDirectory().
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.
filename | The file that should be hashed. |
hash | The hash algorithm to use. |
encoder | The encoder to use. |
TestSupport.Base.getModuleName | ( | ) |
Return the name of the currently tested module.
If the current test case is not a generic one None is returned.
Definition at line 98 of file Base.py.
References TestSupport.Base.getModuleName().
Referenced by TestSupport.Base.getModuleName().
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.
Definition at line 81 of file Base.py.
References TestSupport.Base.getPackageList().
Referenced by TestSupport.Base.getPackageList().
TestSupport.Base.getResultDirectory | ( | ) |
TestSupport.Base.getSourceFileEncoding | ( | filename | ) |
Definition at line 43 of file Base.py.
Referenced by TestSupport.Base.decodeSourceCodeLine().
TestSupport.Base.getTestCaseContext | ( | ) |
TestSupport.Base.getTestFunctionName | ( | ) |
TestSupport.Base.hasError | ( | errorRegExp = None | ) |
TestSupport.Base.hasInfo | ( | infoRegExp = None, | |
allowUnexpectedMessages = True ) |
Expect that the expression in the context logs an info entry that matches `infoRegExp`. If `infoRegExp` is not given, any info message is expected. If `allowUnexpectedMessages` is set to True (the default), messages that do not match `infoRegExp` are ignored, otherwise they are considered a failure. Usage: with hasInfo(infoRegExp=".*Unknown module.*"): doStuff()
TestSupport.Base.hasNoWarning | ( | warningRegExp = None | ) |
TestSupport.Base.hasWarning | ( | warningRegExp = None | ) |
TestSupport.Base.hasWarningAndError | ( | errorRegExp = None, | |
warningRegExp = None ) |
TestSupport.Base.ignoreError | ( | function, | |
args = (), | |||
kargs = None, | |||
errorRegExp = None, | |||
resultInfoDict = None ) |
Call the given function with the given parameters and ignores potential errors.
USE WITH CARE, usually you want to use expectError for explicit error handling!
Please note that nesting the ignore{Warning, Error} methods will lead to invalid line numbers in the reports!
function | The function to be called. |
args | List of parameters for the function. |
kargs | Dictionary of named parameters for the function. |
errorRegExp | Optional RegexObject to control which errors are ignored (non-matching ones will not be caught!). (Strings will be assumed to be regular expressions and compiled automatically.) |
resultInfoDict | Optional dictionary that, if provided, gets a new key 'hadIgnoredErrors' with a boolean value \ that allows the caller to react on whether there acually were errors or not |
TestSupport.Base.ignoreWarning | ( | function, | |
args = (), | |||
kargs = None, | |||
warningRegExp = None, | |||
resultInfoDict = None ) |
Call the given function with the given parameters and ignores potential warnings.
USE WITH CARE, usually you want to use expectWarning for explicit warning handling!
Please note that nesting the ignore{Warning, Warning} methods will lead to invalid line numbers in the reports!
function | The function to be called. |
args | List of parameters for the function. |
kargs | Dictionary of named parameters for the function. |
warningRegExp | Optional RegexObject to control which warnings are ignored (non-matching ones will not be caught!). (Strings will be assumed to be regular expressions and compiled automatically.) |
resultInfoDict | Optional dictionary that, if provided, gets a new key 'hadIgnoredWarnings' with a boolean value \ that allows the caller to react on whether there acually were warnings or not |
TestSupport.Base.ignoreWarningAndError | ( | function, | |
args = [], | |||
kargs = {}, | |||
errorRegExp = None, | |||
warningRegExp = None, | |||
resultInfoDict = None ) |
Call the given function with the given parameters and ignore both a warning and an error.
USE WITH CARE, usually you want to use expectWarningAndError for explicit warning handling!
Please note that nesting the ignore{Warning, Error, Info} methods will lead to invalid line numbers in the reports!
function | The function to be called. |
args | List of parameters for the function. |
kargs | Dictionary of named parameters for the function. |
errorRegExp | Optional RegexObject to control which errors are handled. |
warningRegExp | Optional RegexObject to control which warnings are handled. |
resultInfoDict | Optional dictionary that, if provided, gets new keys 'hadIgnoredWarnings' and 'hadIgnoredErrors' \ with boolean values that allow the caller to react on whether there acually were warnings/errors or not |
TestSupport.Base.LoggingDecorator | ( | func | ) |
Internal decorator used for creating messages in compare methods.
Definition at line 159 of file Base.py.
References TestSupport.Base.decodeSourceCodeLine().
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 707 of file Base.py.
References TestSupport.Base.popChangeSet().
Referenced by TestSupport.Base.popChangeSet().
TestSupport.Base.popEnvironment | ( | ) |
Pops the last pushed environment dictionary from a stack and makes it the current one.
See pushEnvironment().
Definition at line 782 of file Base.py.
References TestSupport.Base.popEnvironment().
Referenced by TestSupport.Base.popEnvironment(), and TestSupport.Base.pushEnvironmentDecorator().
TestSupport.Base.pushChangeSet | ( | ) |
Push a new ChangeSet to the stack.
Definition at line 699 of file Base.py.
References TestSupport.Base.pushChangeSet().
Referenced by TestSupport.Base.pushChangeSet().
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 773 of file Base.py.
References TestSupport.Base.pushEnvironment().
Referenced by TestSupport.Base.pushEnvironment(), and TestSupport.Base.pushEnvironmentDecorator().
TestSupport.Base.pushEnvironmentDecorator | ( | func | ) |
Definition at line 789 of file Base.py.
References TestSupport.Base.popEnvironment(), and TestSupport.Base.pushEnvironment().
TestSupport.Base.runProcess | ( | command, | |
wait = True, | |||
expectSuccess = True, | |||
expectFailure = False, | |||
verbose = True, | |||
env = None ) |
Definition at line 905 of file Base.py.
References TestSupport.Base.verifyProcessResult().
Referenced by TestSupport.Base.runPythonScript().
TestSupport.Base.runPythonScript | ( | script, | |
arguments, | |||
wait = True, | |||
expectSuccess = True, | |||
expectFailure = False, | |||
verbose = True, | |||
env = None ) |
Definition at line 979 of file Base.py.
References TestSupport.Base.runProcess().
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:
Definition at line 125 of file Base.py.
Referenced by TestSupport.Base.MacrosShouldLogOnSuccessDecorator.__call__().
TestSupport.Base.shouldLogOnSuccess | ( | logOnSuccess = None | ) |
Definition at line 128 of file Base.py.
Referenced by TestSupport.Base.compareEqual(), TestSupport.Base.compareFloatEqual(), TestSupport.Base.compareFloatLessThan(), TestSupport.Base.compareFloatLessThanOrEqual(), TestSupport.Base.compareFloatNotEqual(), TestSupport.Base.compareLessThan(), TestSupport.Base.compareLessThanOrEqual(), TestSupport.Base.compareNotEqual(), TestSupport.Base.verifyFalse(), and TestSupport.Base.verifyTrue().
TestSupport.Base.verifyFalse | ( | expr, | |
comment = "", | |||
logOnSuccess = None, | |||
msg = None ) |
If the given expression evaluates to True, an error is logged.
expr | The expression that must evaluate to False. |
comment | Optional comment shown if expression is True. |
logOnSucces | Print message in case of success. |
Definition at line 321 of file Base.py.
References TestSupport.Base.shouldLogOnSuccess().
TestSupport.Base.verifyProcessResult | ( | command, | |
shortCommand, | |||
returncode, | |||
stdout, | |||
stderr, | |||
expectSuccess = True, | |||
expectFailure = False, | |||
verbose = True ) |
Definition at line 942 of file Base.py.
Referenced by TestSupport.Base.runProcess().
TestSupport.Base.verifyTrue | ( | expr, | |
comment = "", | |||
logOnSuccess = None, | |||
msg = None ) |
If the given expression evaluates to False, an error is logged.
expr | The expression that must evaluate to True. |
comment | Optional comment shown if expression is not True. |
logOnSucces | Print message in case of success. |
Definition at line 307 of file Base.py.
References TestSupport.Base.escapedUnicode(), and TestSupport.Base.shouldLogOnSuccess().