Testing#

class qiime2.plugin.testing.TestPluginBase(methodName='runTest')[source]#

Test harness for simplifying testing QIIME 2 plugins.

TestPluginBase extends unittest.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:

str

test_dir_prefix#

The prefix for the temporary testing dir created by the harness. Optional.

Type:

str

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)[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:

filename (str) – The name of the file to look up.

Returns:

filepath – The materialized filepath to the requested test data.

Return type:

str

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.

Parameters:
  • from_type (A View Type) – The View type of the source data.

  • to_type (A View Type) – The View type to transform to.

Returns:

transformer – The registered tranformer from from_type to to_type.

Return type:

A Transformer Function

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/, as source_format, then transform to the target 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 the filenames 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 the filename parameter.

Returns:

  • input (A Format) – The data loaded from data as the specified source_format.

  • obs (A View Type) – The loaded data, transformed to the specified target view type.

execute_examples()[source]#

Runs all usage examples defined in the plugin.

qiime2.plugin.testing.assert_no_nans_in_tables(fh)[source]#

Checks for NaNs present in any of the tables in the indicated file then resets to the head of the file.