Testing (Experimental)
Experimental
The testing functionality in this module is experimental. It does not support all data types and port types, and only works with Table._to_pandas(). Expect potential API changes.
class knime.extension.testing.TestingConfigurationContext
This is a mock implementation of a configuration context for testing. In unit tests, create an instance of the TestConfigurationContext and pass it to your node when you test configure
Examples
python
>>> import knime.extension as knext
... import knime.extension.testing as ktest
...
... # set up test input schema
... schema = knext.Schema.from_columns(
... [
... knext.Column(knext.int64(), "Integers"),
... knext.Column(knext.double(), "Doubles"),
... ]
... )
...
... # assume TestNode is your Python node with one input and one output table
... node = TestNode()
... node.column = "Test" # configure parameter "column" to the value "Test"
...
... # create testing configuration context
... config_context = ktest.TestingConfigurationContext()
...
... # configure node, passing the testing configuration context
... output_schema = node.configure(config_context, input_schema)
...
... # TODO: check that the output schema matches your expectationsmethod __init__() → None
property flow_variables → Dict[str, Any]
The flow variables coming in from KNIME as a dictionary with string keys.
Notes
The dictionary can be edited and supports flow variables of the following types:
- bool
- list[bool]
- float
- list[float]
- int
- list[int]
- str
- list[str]
method get_credential_names()
method get_credentials(identifier: str)
method set_warning(message: str) → None
class knime.extension.testing.TestingExecutionContext
This is a mock implementation of an execution context for testing. In unit tests, create an instance of the TestExecutionContext and pass it to your node when testing execute.
Examples
python
>>> import knime.extension as knext
... import knime.extension.testing as ktest
...
... # set up test input
... input_df = pd.DataFrame({"Test": [1, 2, 3, 4]})
... input = knext.Table.from_pandas(input_df)
...
... # assume TestNode is your Python node with one input and one output table
... node = TestNode()
... node.column = "Test" # configure parameter "column" to the value "Test"
...
... # create testing execution context
... exec_context = ktest.TestingExecutionContext()
...
... # execute node, passing the testing execution context
... output = node.execute(exec_context, input)
... output_df = output.to_pandas()
...
... # TODO: check that the output DataFrame matches your expectationsmethod __init__() → None
property flow_variables → Dict[str, Any]
The flow variables coming in from KNIME as a dictionary with string keys.
Notes
The dictionary can be edited and supports flow variables of the following types:
- bool
- list[bool]
- float
- list[float]
- int
- list[int]
- str
- list[str]
method get_credential_names()
method get_credentials(identifier: str)
method get_knime_home_dir() → str
method get_workflow_data_area_dir() → str
method get_workflow_temp_dir() → str
method is_canceled() → bool
method set_progress(progress: float, message: str = None)
method set_warning(message: str) → None
function knime.extension.testing.register_extension(plugin_xml: str, value_factory_to_type_name_map: dict = None)
Registers the Python extension types found in the given plugin.xml file and puts all modules with extension types on the Pythonpath.
Parameters
- plugin_xml :
str— Provide the path to a plugin.xml that registers Python types at the extension point. - value_factory_to_type_name_map :
dict— An optional mapping from value factory to readable type names e.g.org.knime.chem.types.SmilesAdapterCellValueFactory->Smiles