tpcp.testing.TestAlgorithmMixin#

class tpcp.testing.TestAlgorithmMixin[source]#

A mixin for all common tests that should be run on all algorithm classes.

You can use this mixin to test your algorithm class OR Pipeline sub-class (as pipelines are just algorithms).

This mixin is intended to be used in a pytest testclass. For this, create a new class that inherits from this mixin and set the ALGORITHM_CLASS attribute to the algorithm class that should be tested. Then set __test__ = True to enable the tests.

You can further customize the tests by setting the following attributes:

  • ONLY_DEFAULT_PARAMS: If set to False, the testclass can have non-optional kwargs in the constructor.

  • ASSUME_HASHABLE: If set to False, the testclass is not expected to be hashable by joblib.

  • CHECK_DOCSTRING: If set to False, the docstring tests are skipped.

In some very specific cases you might want to ignore some parameters in the docstring tests. For this, set the _IGNORED_NAMES attribute to a tuple of parameter names that should be ignored.

Examples

>>> class TestMyAlgorithm(TestAlgorithmMixin):
...    ALGORITHM_CLASS = MyAlgorithm
...    __test__ = True
...
...    ONLY_DEFAULT_PARAMS = False

Methods

after_action_instance(**kwargs)

Return an instance of the algorithm class AFTER the action is performed.

test_action_method_returns_self(...)

Test if the action method returns self.

test_after_action_instance_valid(...)

Test that the implemented after_action_fixture returns a valid instance.

test_algorithm_can_be_cloned(...)

Test if an algorithm can be cloned.

test_all_attributes_documented(...)

Test if all result attributes are documented.

test_all_other_parameters_documented(...)

Test if all other parameters (action method inputs) are documented.

test_all_parameters_documented()

Test if all init-parameters are documented.

test_hashing(after_action_instance)

Check if caching with joblib will work as expected.

test_init()

Test that all init paras are passed through untouched.

test_is_algorithm()

Test that the class is actually an algorithm.

test_nested_algo_marked_default()

Test that nested algorithms are wrapped with cf/CloneFactory.

test_only_optional_kwargs()

Test that the class has only optional kwargs.

test_passes_safe_action_checks(...)

Test that the algorithm passes the safe action checks.

test_set_params_invalid(after_action_instance)

Test that set_params raises an error if an invalid parameter is passed.

test_set_params_valid(after_action_instance)

Test that set_params works.

__init__(*args, **kwargs)#
after_action_instance(**kwargs) BaseTpcpObjectObjT[source]#

Return an instance of the algorithm class AFTER the action is performed.

This needs to be implemented by every testclass. The returned algorithm instance should have the result attributes and the “other parameters” (i.e. the action method inputs) set.

test_action_method_returns_self(after_action_instance)[source]#

Test if the action method returns self.

test_after_action_instance_valid(after_action_instance)[source]#

Test that the implemented after_action_fixture returns a valid instance.

test_algorithm_can_be_cloned(after_action_instance)[source]#

Test if an algorithm can be cloned.

test_all_attributes_documented(after_action_instance)[source]#

Test if all result attributes are documented.

test_all_other_parameters_documented(after_action_instance)[source]#

Test if all other parameters (action method inputs) are documented.

test_all_parameters_documented()[source]#

Test if all init-parameters are documented.

test_hashing(after_action_instance)[source]#

Check if caching with joblib will work as expected.

test_init()[source]#

Test that all init paras are passed through untouched.

test_is_algorithm()[source]#

Test that the class is actually an algorithm.

test_nested_algo_marked_default()[source]#

Test that nested algorithms are wrapped with cf/CloneFactory.

test_only_optional_kwargs()[source]#

Test that the class has only optional kwargs.

test_passes_safe_action_checks(after_action_instance)[source]#

Test that the algorithm passes the safe action checks.

test_set_params_invalid(after_action_instance)[source]#

Test that set_params raises an error if an invalid parameter is passed.

test_set_params_valid(after_action_instance)[source]#

Test that set_params works.