Testing#
- class qiime2.plugin.testing.TestPluginBase(methodName='runTest')[source]#
Test harness for simplifying testing QIIME 2 plugins.
TestPluginBase
extendsunittest.TestCase
, with a few extra helpers and assertions.- package#
The name of the plugin package to be tested. Subclasses must define this as a class-attribute.
- Type:
- test_dir_prefix#
The prefix for the temporary testing dir created by the harness. Optional.
- Type:
Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.
- setUp()[source]#
Test runner setup hook.
If overriding this hook in a test, call
__super__
to invoke this method in the overridden hook, otherwise the harness might not work as expected.
- tearDown()[source]#
Test runner teardown hook.
If overriding this hook in a test, call
__super__
to invoke this method in the overridden hook, otherwise the harness might not work as expected.
- get_data_path(filename, result_as_str=True)[source]#
Convenience method for getting a data asset while testing.
Test data stored in the
data/
dir local to the running test can be accessed via this method.- Parameters:
- Returns:
filepath – The materialized filepath to the requested test data.
- Return type:
str (or pathlib.Path if result_as_str != True)
- get_transformer(from_type, to_type)[source]#
Convenience method for getting a registered transformer.
This helper deliberately side-steps the framework’s validation machinery, so that it is possible for plugin developers to test failing conditions.
- assertRegisteredSemanticType(semantic_type)[source]#
Test assertion for ensuring a plugin’s semantic type is registered.
Fails if the semantic type requested is not found in the Plugin Manager.
- Parameters:
semantic_type (A Semantic Type) – The Semantic Type to test the presence of.
- assertSemanticTypeRegisteredToFormat(semantic_type, exp_format)[source]#
Test assertion for ensuring a semantic type is registered to a format.
Fails if the semantic type requested is not registered to the format specified with
exp_format
. Also fails if the semantic type isn’t registered to any format.- Parameters:
semantic_type (A Semantic Type) – The Semantic Type to check for.
exp_format (A Format) – The Format to check that the Semantic Type is registed on.
- transform_format(source_format, target, filename=None, filenames=None)[source]#
Helper utility for loading data and transforming it.
Combines several other utilities in this class, will load files from
data/
, assource_format
, then transform to thetarget
view.This helper deliberately side-steps the framework’s validation machinery, so that it is possible for plugin developers to test failing conditions.
- Parameters:
source_format (A Format) – The Format to load the data as.
target (A View Type) – The View Type to transform the data to.
filename (str) – The name of the file to load from
data
. Use this for formats that use a single file in their format definition. Mutually exclusive with thefilenames
parameter.filenames (list[str]) – The names of the files to load from
data
. Use this for formats that use multiple files in their format definition. Mutually exclusive with thefilename
parameter.
- Returns:
input (A Format) – The data loaded from
data
as the specifiedsource_format
.obs (A View Type) – The loaded data, transformed to the specified
target
view type.