Ejemplo n.º 1
0
class TestConditionTask(object):
    """Test ConditionalTask.

    """

    def setup(self):
        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = ConditionalTask(name='Test')
        self.root.add_child_task(0, self.task)
        self.check = CheckTask(name='check')
        self.task.add_child_task(0, self.check)

    def test_check1(self):
        """Test that everything is ok if condition is evaluable.

        """
        self.task.condition = 'True'

        test, traceback = self.task.check()
        assert test
        assert not traceback
        assert self.check.check_called

    def test_check2(self):
        """Test handling a wrong condition.

        """
        self.task.condition = '*True'

        test, traceback = self.task.check(test_instr=True)
        assert not test
        assert len(traceback) == 1
        assert 'root/Test-condition' in traceback

    def test_perform1(self):
        """Test performing when condition is True.

        """
        self.task.condition = 'True'
        self.root.database.prepare_for_running()
        self.root.check()

        self.task.perform()
        assert self.check.perform_called

    def test_perform2(self):
        """Test performing when condition is False.

        """
        self.task.condition = '1 < 0'
        self.root.database.prepare_for_running()
        self.root.check()

        self.task.perform()
        assert not self.check.perform_called
Ejemplo n.º 2
0
class TestConditionTask(object):
    """Test ConditionalTask.

    """
    def setup(self):
        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = ConditionalTask(name='Test')
        self.root.add_child_task(0, self.task)
        self.check = CheckTask(name='check')
        self.task.add_child_task(0, self.check)

    def test_check1(self):
        """Test that everything is ok if condition is evaluable.

        """
        self.task.condition = 'True'

        test, traceback = self.task.check()
        assert test
        assert not traceback
        assert self.check.check_called

    def test_check2(self):
        """Test handling a wrong condition.

        """
        self.task.condition = '*True'

        test, traceback = self.task.check(test_instr=True)
        assert not test
        assert len(traceback) == 1
        assert 'root/Test-condition' in traceback

    def test_perform1(self):
        """Test performing when condition is True.

        """
        self.task.condition = 'True'
        self.root.prepare()

        self.task.perform()
        assert self.check.perform_called

    def test_perform2(self):
        """Test performing when condition is False.

        """
        self.task.condition = '1 < 0'
        self.root.prepare()

        self.task.perform()
        assert not self.check.perform_called
Ejemplo n.º 3
0
def test_view(windows):
    """Test the ConditionalTask view.

    """
    show_and_close_widget(ConditionalView(task=ConditionalTask(name='Test')))
Ejemplo n.º 4
0
 def setup(self):
     self.root = RootTask(should_stop=Event(), should_pause=Event())
     self.task = ConditionalTask(name='Test')
     self.root.add_child_task(0, self.task)
     self.check = CheckTask(name='check')
     self.task.add_child_task(0, self.check)
Ejemplo n.º 5
0
 def setup(self):
     self.root = RootTask(should_stop=Event(), should_pause=Event())
     self.task = ConditionalTask(name='Test')
     self.root.add_child_task(0, self.task)
     self.check = CheckTask(name='check')
     self.task.add_child_task(0, self.check)