Пример #1
0
    def setup(self):
        self.workbench = Workbench()
        self.workbench.register(CoreManifest())
        self.workbench.register(StateManifest())
        self.workbench.register(PreferencesManifest())
        self.workbench.register(TaskManagerManifest())

        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = ConditionalTask(task_name='Test', condition='rr')
        self.root.children_task.append(self.task)
class TestConditionTask(object):

    def setup(self):
        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = ConditionalTask(task_name='Test')
        self.root.children_task.append(self.task)
        self.check = CheckTask(task_name='check')
        self.task.children_task.append(self.check)

    def test_check1(self):
        # Simply test that everything is ok condition is evaluable.
        self.task.condition = 'True'

        test, traceback = self.task.check()
        assert_true(test)
        assert_false(traceback)
        assert_true(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_false(test)
        assert_equal(len(traceback), 1)
        assert_in('root/Test-cond', traceback)

    def test_perform1(self):
        # Test performing when condition is True.
        self.task.condition = 'True'

        self.root.task_database.prepare_for_running()

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

    def test_perform2(self):
        # Test performing when condition is False.
        self.task.condition = '1 < 0'

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_false(self.check.perform_called)
Пример #3
0
class TestConditionTask(object):
    def setup(self):
        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = ConditionalTask(task_name='Test')
        self.root.children_task.append(self.task)
        self.check = CheckTask(task_name='check')
        self.task.children_task.append(self.check)

    def test_check1(self):
        # Simply test that everything is ok condition is evaluable.
        self.task.condition = 'True'

        test, traceback = self.task.check()
        assert_true(test)
        assert_false(traceback)
        assert_true(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_false(test)
        assert_equal(len(traceback), 1)
        assert_in('root/Test-cond', traceback)

    def test_perform1(self):
        # Test performing when condition is True.
        self.task.condition = 'True'

        self.root.task_database.prepare_for_running()

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

    def test_perform2(self):
        # Test performing when condition is False.
        self.task.condition = '1 < 0'

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_false(self.check.perform_called)
Пример #4
0
 def setup(self):
     self.root = RootTask(should_stop=Event(), should_pause=Event())
     self.task = ConditionalTask(task_name='Test')
     self.root.children_task.append(self.task)
     self.check = CheckTask(task_name='check')
     self.task.children_task.append(self.check)
 def setup(self):
     self.root = RootTask(should_stop=Event(), should_pause=Event())
     self.task = ConditionalTask(task_name='Test')
     self.root.children_task.append(self.task)
     self.check = CheckTask(task_name='check')
     self.task.children_task.append(self.check)