Source code for exopy.testing.tasks.util

# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright 2015-2018 by Exopy Authors, see AUTHORS for more details.
#
# Distributed under the terms of the BSD license.
#
# The full license is in the file LICENCE, distributed with this software.
# -----------------------------------------------------------------------------
"""Utility object to test the execution of tasks.

"""
from atom.api import Value, Int, Callable

from exopy.tasks.tasks.base_tasks import SimpleTask


[docs]class CheckTask(SimpleTask): """Task keeping track of check and perform call and value passed to perform """ #: Number of time the check method has been called. check_called = Int() #: Number of time the perform method has been called. perform_called = Int() #: Value passed to the perform method. perform_value = Value() #: Function to call in the perform method custom = Callable(lambda t, x: None)
[docs] def check(self, *args, **kwargs): self.check_called += 1 return super(CheckTask, self).check(*args, **kwargs)
[docs] def perform(self, value=None): self.perform_called += 1 self.perform_value = value self.custom(self, value)
[docs]class ExceptionTask(SimpleTask): """Task raising an exception when executed. """
[docs] def perform(self): raise Exception()