generic_unittest¶
Module: tests.generic_unittest
¶
Provides a class to implement a generic unittest
The unittests will only instantiate the given class with either
a default input set (see test_default_data
)
or will interpret the data given by the user. In the case that there
already is a specialized unittest available, this class will not be
called for that specific node.
Author: | Andrei Ignat, Mario Michael Krell |
---|---|
Created: | 2014/05/02 |
Inheritance diagram for pySPACE.tests.generic_unittest
:
Class Summary¶
ParametrizedTestCase ([methodName, ...]) |
This class acts as a wrapper such that different parameters can be passed on to the test case. |
OutputTestCase ([methodName, current_node, ...]) |
Serves as a wrapper to test the output given the default input set |
InputOutputTestCase ([methodName, ...]) |
Serves as a wrapper for an easy way to test the input-output relation |
GenericTestCase ([methodName, current_node, ...]) |
Contains the methods and submethods needed to run the tests |
Function Summary¶
single_node_testing (node_name) |
This function facilitates the testing of a single node referred to by using its representation in the DEFAULT_NODE_MAPPING variable. |
multiple_node_testing ([verbose, report]) |
This function ensures the testing of all available nodes. |
Classes¶
ParametrizedTestCase
¶
-
class
pySPACE.tests.generic_unittest.
ParametrizedTestCase
(methodName='runTest', current_node=None, specific_input=None, desired_output=None)[source]¶ Bases:
unittest.case.TestCase
This class acts as a wrapper such that different parameters can be passed on to the test case. It is adapted from the example found here:
http://eli.thegreenplace.net/2011/08/02/python-unit-testing-parametrized-test-cases/
Parameters
methodName: The name of the test to be run current_node: A reference to the node. Should reference the node object and NOT A STRING with the same name specific_input: If a specific input is to be used, it should be defined here The reason behind the existence of this class is that passing parameters to a class that extends
GenericTestCase
is close to impossible. If the user does not want to implement an external unittesting package such as nose-parametrized, one must ‘fool’ Python and use a wrapper class such that the unit testing is done in a different class. The end result is that the unittest implementation is done within a class that has an initialization method which obviously accepts external parameters (such as different nodes) and which takes the actual tests from a class that inherits fromGenericTestCase
.While this is not the most elegant solution, it was preferred over importing a new module which would have just enlarged the list of the framework dependencies.
Class Components Summary
_get_the_call
()wrapper to get the YAML call _initialize_node
()initializes the node with the parameters from YAML _look_for_yaml
(the_docstring)takes a string as an argument and looks for a YAML _non_trainable_execute
()Execution call for non-trainable nodes _nspaces
(line)returns the indentation _trainable_execute
()Execution call for trainable nodes _which_input
(node)queries the node to find out what type of input it takes parametrize
(current_testcase[, node, input, ...])Instantiate a new testcase for current_node -
__init__
(methodName='runTest', current_node=None, specific_input=None, desired_output=None)[source]¶
-
static
parametrize
(current_testcase, node=None, input=None, output=None)[source]¶ Instantiate a new testcase for current_node
-
_nspaces
(line)[source]¶ returns the indentation
Parameters
line: string representation of the current line
-
_look_for_yaml
(the_docstring)[source]¶ takes a string as an argument and looks for a YAML code block inside the string
Parameters
the_docstring: the string in which the method should look for YAML code
-
_initialize_node
()[source]¶ initializes the node with the parameters from YAML
If no YAML specification exists at all, use default initialization.
-
OutputTestCase
¶
-
class
pySPACE.tests.generic_unittest.
OutputTestCase
(methodName='runTest', current_node=None, specific_input=None, desired_output=None)[source]¶ Bases:
pySPACE.tests.generic_unittest.ParametrizedTestCase
Serves as a wrapper to test the output given the default input set
Principle
The OutputTestCase serves as a framework for quick checks of a node whereby, for the default input set, which can be found in ,test_default_data
, a user defined output is expectedClass Components Summary
test_output
()compare the output with the expected output
InputOutputTestCase
¶
-
class
pySPACE.tests.generic_unittest.
InputOutputTestCase
(methodName='runTest', current_node=None, specific_input=None, desired_output=None)[source]¶ Bases:
pySPACE.tests.generic_unittest.ParametrizedTestCase
Serves as a wrapper for an easy way to test the input-output relation
Principle
The InputOutputTestCase serves as a framework for quick checks of a node whereby, for a user defined input, a user defined output is desired.Class Components Summary
test_input_output
()obtain output for given input and compare it with desired output
GenericTestCase
¶
-
class
pySPACE.tests.generic_unittest.
GenericTestCase
(methodName='runTest', current_node=None, specific_input=None, desired_output=None)[source]¶ Bases:
pySPACE.tests.generic_unittest.ParametrizedTestCase
Contains the methods and submethods needed to run the tests
- whether the node has some sort of documentation
- whether an exemplary call is present in the documentation
- whether the node can be initialized with the default data set
- whether the node can execute on the default data set
An example of how to implement the generic tests in a node specific manner can be found under
test_time_domain_features
This example is also explained in detail in the tutorial file
Class Components Summary
shortDescription
()overwritten method that will display the node name as output test_execution
()execute the node using the default data test_has_documentation
()check if the node has some sort of documentation test_has_exemplary_call
()check if there is an exemplary call in the documentation test_initialize
()check if the node can be initialized using the default data