Exemplo n.º 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 = LoopTask(task_name='Test')
        self.root.children_task.append(self.task)
    def test_check3(self):
        # Test handling a wrong condition.
        loop = LoopTask(task_name='Parent', children_task=[self.task])
        self.root.children_task.append(loop)
        self.task.condition = '*True'

        test, traceback = self.task.check()
        assert_false(test)
        assert_equal(len(traceback), 1)
        assert_in('root/Parent/Test-cond', traceback)
    def test_check1(self):
        # Simply test that everything is ok condition is evaluable and parent
        # is a Loop.
        loop = LoopTask(children_task=[self.task])
        self.root.children_task.append(loop)
        self.task.condition = 'True'

        test, traceback = self.task.check()
        assert_true(test)
        assert_false(traceback)
Exemplo n.º 4
0
    def test_check_execution_order(self):
        # Test that the interface checks are run before the children checks.
        interface = IterableLoopInterface()
        interface.iterable = '[(1, 0)]'
        self.task.interface = interface

        subiter = IterableLoopInterface(iterable='{Test_value}')
        self.task.children_task = [LoopTask(interface=subiter)]

        test, traceback = self.task.check()
        assert_true(test)
Exemplo n.º 5
0
 def setup(self):
     self.root = RootTask(should_stop=Event(), should_pause=Event())
     self.task = LoopTask(task_name='Test')
     self.root.children_task.append(self.task)
Exemplo n.º 6
0
class TestLoopTask(object):

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

    def test_task_handling(self):
        # Test adding removing a task.
        aux = CheckTask()
        self.task.task = aux

        # Check value is not written in database if a task is present.
        assert_not_in('value', self.task.task_database_entries)
        # Confirm the child was added (_child_added called)
        assert_is(aux.root_task, self.root)

        del self.task.task

        # Check value is written in database if no task is present.
        assert_in('value', self.task.task_database_entries)
        # Confirm the child was added (_child_removed called)
        assert_is(aux.root_task, None)

    def test_timing_handling(self):
        # Test enabling/disabling the timing.
        assert_not_in('elapsed_time', self.task.task_database_entries)

        self.task.timing = True

        assert_in('elapsed_time', self.task.task_database_entries)

        self.task.timing = False

        assert_not_in('elapsed_time', self.task.task_database_entries)

    def test_check_linspace_interface1(self):
        # Simply test that everything is ok when all formulas are true.
        interface = LinspaceLoopInterface()
        interface.start = '1.0'
        interface.stop = '2.0'
        interface.step = '0.1'
        self.task.interface = interface

        test, traceback = self.task.check()
        assert_true(test)
        assert_false(traceback)
        assert_equal(self.task.get_from_database('Test_point_number'), 11)

    def test_check_linspace_interface2(self):
        # Test handling a wrong start.
        interface = LinspaceLoopInterface()
        interface.start = '1.0*'
        interface.stop = '2.0'
        interface.step = '0.1'
        self.task.interface = interface

        test, traceback = self.task.check(test_instr=True)
        assert_false(test)
        assert_equal(len(traceback), 1)
        assert_in('root/Test-start', traceback)

    def test_check_linspace_interface3(self):
        # Test handling a wrong stop.
        interface = LinspaceLoopInterface()
        interface.start = '1.0'
        interface.stop = '2.0*'
        interface.step = '0.1'
        self.task.interface = interface

        test, traceback = self.task.check(test_instr=True)
        assert_false(test)
        assert_equal(len(traceback), 1)
        assert_in('root/Test-stop', traceback)

    def test_check_linspace_interface4(self):
        # Test handling a wrong step.
        interface = LinspaceLoopInterface()
        interface.start = '1.0'
        interface.stop = '2.0'
        interface.step = '0.1*'
        self.task.interface = interface

        test, traceback = self.task.check(test_instr=True)
        assert_false(test)
        assert_equal(len(traceback), 1)
        assert_in('root/Test-step', traceback)

    def test_check_linspace_interface5(self):
        # Test handling a wrong number of point.
        interface = LinspaceLoopInterface()
        interface.start = '1.0'
        interface.stop = '2.0'
        interface.step = '0.0'
        self.task.interface = interface

        test, traceback = self.task.check(test_instr=True)
        assert_false(test)
        assert_equal(len(traceback), 2)
        assert_in('root/Test-points', traceback)
        assert_in('root/Test-linspace', traceback)

    def test_check_iterable_interface1(self):
        # Simply test that everything is ok when all formulas are true.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface

        test, traceback = self.task.check()
        assert_true(test)
        assert_false(traceback)
        assert_equal(self.task.get_from_database('Test_point_number'), 11)

    def test_check_iterable_interface2(self):
        # Test handling a wrong iterable formula.
        interface = IterableLoopInterface()
        interface.iterable = '*range(11)'
        self.task.interface = interface

        test, traceback = self.task.check()
        assert_false(test)
        assert_equal(len(traceback), 1)
        assert_in('root/Test', traceback)

    def test_check_iterable_interface3(self):
        # Test handling a wrong iterable type.
        interface = IterableLoopInterface()
        interface.iterable = '1.0'
        self.task.interface = interface

        test, traceback = self.task.check()
        assert_false(test)
        assert_equal(len(traceback), 1)
        assert_in('root/Test', traceback)

    def test_perform1(self):
        # Test performing a simple loop no timing. Iterable interface.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_value'), 10)

    def test_perform2(self):
        # Test performing a simple loop no timing. Linspace interface.
        interface = LinspaceLoopInterface()
        interface.start = '1.0'
        interface.stop = '2.0'
        interface.step = '0.1'
        self.task.interface = interface

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_value'), 2.0)

    def test_perform3(self):
        # Test performing a simple loop no timing. Break.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.children_task.append(BreakTask(task_name='break',
                                                 condition='{Test_value} == 5')
                                       )

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_value'), 5)

    def test_perform4(self):
        # Test performing a simple loop no timing. Continue
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.children_task.append(ContinueTask(task_name='break',
                                                    condition='True')
                                       )
        self.task.children_task.append(CheckTask(task_name='check'))

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_false(self.task.children_task[1].perform_called)

    def test_perform_task1(self):
        # Test performing a loop with an embedded task no timing.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.task = CheckTask(task_name='check')

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_index'), 11)
        assert_true(self.task.task.perform_called)
        assert_equal(self.task.task.perform_value, 10)

    def test_perform_task2(self):
        # Test performing a loop with an embedded task no timing. Break.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.task = CheckTask(task_name='check')
        self.task.children_task.append(BreakTask(task_name='break',
                                                 condition='{Test_index} == 6')
                                       )

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_index'), 6)
        assert_true(self.task.task.perform_called)
        assert_equal(self.task.task.perform_value, 5)

    def test_perform_task3(self):
        # Test performing a loop with an embedded task no timing. Continue.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.task = CheckTask(task_name='check')
        self.task.children_task.append(ContinueTask(task_name='break',
                                                    condition='True')
                                       )
        self.task.children_task.append(CheckTask(task_name='check'))

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_index'), 11)
        assert_true(self.task.task.perform_called)
        assert_equal(self.task.task.perform_value, 10)
        assert_false(self.task.children_task[1].perform_called)

    def test_perform_timing1(self):
        # Test performing a simple loop timing.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.timing = True

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_value'), 10)
        assert_not_equal(self.root.get_from_database('Test_elapsed_time'), 1.0)

    def test_perform_timing2(self):
        # Test performing a simple loop timing. Break
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.timing = True
        self.task.children_task.append(BreakTask(task_name='break',
                                                 condition='{Test_value} == 0')
                                       )

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_value'), 0)
        assert_not_equal(self.root.get_from_database('Test_elapsed_time'), 1.0)

    def test_perform_timing3(self):
        # Test performing a simple loop timing. Continue
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.timing = True
        self.task.children_task.append(ContinueTask(task_name='break',
                                                    condition='True')
                                       )
        self.task.children_task.append(CheckTask(task_name='check'))

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_false(self.task.children_task[1].perform_called)
        assert_not_equal(self.root.get_from_database('Test_elapsed_time'), 1.0)

    def test_perform_timing_task1(self):
        # Test performing a loop with an embedded task no timing.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.timing = True
        self.task.task = CheckTask(task_name='check')

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_index'), 11)
        assert_true(self.task.task.perform_called)
        assert_equal(self.task.task.perform_value, 10)
        assert_not_equal(self.root.get_from_database('Test_elapsed_time'), 1.0)

    def test_perform_timing_task2(self):
        # Test performing a loop with an embedded task no timing. Break.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.timing = True
        self.task.task = CheckTask(task_name='check')
        self.task.children_task.append(BreakTask(task_name='break',
                                                 condition='{Test_index} == 1')
                                       )

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_index'), 1)
        assert_true(self.task.task.perform_called)
        assert_equal(self.task.task.perform_value, 0)
        assert_not_equal(self.root.get_from_database('Test_elapsed_time'), 1.0)

    def test_perform_timing_task3(self):
        # Test performing a loop with an embedded task no timing. Continue.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.timing = True
        self.task.task = CheckTask(task_name='check')
        self.task.children_task.append(ContinueTask(task_name='break',
                                                    condition='True')
                                       )
        self.task.children_task.append(CheckTask(task_name='check'))

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_index'), 11)
        assert_true(self.task.task.perform_called)
        assert_equal(self.task.task.perform_value, 10)
        assert_false(self.task.children_task[1].perform_called)
        assert_not_equal(self.root.get_from_database('Test_elapsed_time'), 1.0)
Exemplo n.º 7
0
 def setup(self):
     self.root = RootTask(should_stop=Event(), should_pause=Event())
     self.task = LoopTask(task_name='Test')
     self.root.children_task.append(self.task)
Exemplo n.º 8
0
class TestLoopTask(object):

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

    def test_task_handling(self):
        # Test adding removing a task.
        aux = CheckTask()
        self.task.task = aux

        # Check value is not written in database if a task is present.
        assert_not_in('value', self.task.task_database_entries)
        # Confirm the child was added (_child_added called)
        assert_is(aux.root_task, self.root)

        del self.task.task

        # Check value is written in database if no task is present.
        assert_in('value', self.task.task_database_entries)
        # Confirm the child was added (_child_removed called)
        assert_is(aux.root_task, None)

    def test_timing_handling(self):
        # Test enabling/disabling the timing.
        assert_not_in('elapsed_time', self.task.task_database_entries)

        self.task.timing = True

        assert_in('elapsed_time', self.task.task_database_entries)

        self.task.timing = False

        assert_not_in('elapsed_time', self.task.task_database_entries)

    def test_check_linspace_interface1(self):
        # Simply test that everything is ok when all formulas are true.
        interface = LinspaceLoopInterface()
        interface.start = '1.0'
        interface.stop = '2.0'
        interface.step = '0.1'
        self.task.interface = interface

        test, traceback = self.task.check()
        assert_true(test)
        assert_false(traceback)
        assert_equal(self.task.get_from_database('Test_point_number'), 11)

    def test_check_linspace_interface2(self):
        # Test handling a wrong start.
        interface = LinspaceLoopInterface()
        interface.start = '1.0*'
        interface.stop = '2.0'
        interface.step = '0.1'
        self.task.interface = interface

        test, traceback = self.task.check(test_instr=True)
        assert_false(test)
        assert_equal(len(traceback), 1)
        assert_in('root/Test-start', traceback)

    def test_check_linspace_interface3(self):
        # Test handling a wrong stop.
        interface = LinspaceLoopInterface()
        interface.start = '1.0'
        interface.stop = '2.0*'
        interface.step = '0.1'
        self.task.interface = interface

        test, traceback = self.task.check(test_instr=True)
        assert_false(test)
        assert_equal(len(traceback), 1)
        assert_in('root/Test-stop', traceback)

    def test_check_linspace_interface4(self):
        # Test handling a wrong step.
        interface = LinspaceLoopInterface()
        interface.start = '1.0'
        interface.stop = '2.0'
        interface.step = '0.1*'
        self.task.interface = interface

        test, traceback = self.task.check(test_instr=True)
        assert_false(test)
        assert_equal(len(traceback), 1)
        assert_in('root/Test-step', traceback)

    def test_check_linspace_interface5(self):
        # Test handling a wrong number of point.
        interface = LinspaceLoopInterface()
        interface.start = '1.0'
        interface.stop = '2.0'
        interface.step = '0.0'
        self.task.interface = interface

        test, traceback = self.task.check(test_instr=True)
        assert_false(test)
        assert_equal(len(traceback), 2)
        assert_in('root/Test-points', traceback)
        assert_in('root/Test-linspace', traceback)

    def test_check_iterable_interface1(self):
        # Simply test that everything is ok when all formulas are true.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface

        test, traceback = self.task.check()
        assert_true(test)
        assert_false(traceback)
        assert_equal(self.task.get_from_database('Test_point_number'), 11)

        interface.iterable = 'dict(a=1)'
        test, traceback = self.task.check()
        assert_true(test)
        assert_false(traceback)
        assert_equal(self.task.get_from_database('Test_point_number'), 1)
        assert_equal(self.task.get_from_database('Test_value'), 'a')

    def test_check_iterable_interface2(self):
        # Test handling a wrong iterable formula.
        interface = IterableLoopInterface()
        interface.iterable = '*range(11)'
        self.task.interface = interface

        test, traceback = self.task.check()
        assert_false(test)
        assert_equal(len(traceback), 1)
        assert_in('root/Test', traceback)

    def test_check_iterable_interface3(self):
        # Test handling a wrong iterable type.
        interface = IterableLoopInterface()
        interface.iterable = '1.0'
        self.task.interface = interface

        test, traceback = self.task.check()
        assert_false(test)
        assert_equal(len(traceback), 1)
        assert_in('root/Test', traceback)

    def test_check_execution_order(self):
        # Test that the interface checks are run before the children checks.
        interface = IterableLoopInterface()
        interface.iterable = '[(1, 0)]'
        self.task.interface = interface

        subiter = IterableLoopInterface(iterable='{Test_value}')
        self.task.children_task = [LoopTask(interface=subiter)]

        test, traceback = self.task.check()
        assert_true(test)

    def test_perform1(self):
        # Test performing a simple loop no timing. Iterable interface.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_value'), 10)

    def test_perform2(self):
        # Test performing a simple loop no timing. Linspace interface.
        interface = LinspaceLoopInterface()
        interface.start = '1.0'
        interface.stop = '2.0'
        interface.step = '0.1'
        self.task.interface = interface

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_value'), 2.0)

    def test_perform3(self):
        # Test performing a simple loop no timing. Break.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.children_task.append(BreakTask(task_name='break',
                                                 condition='{Test_value} == 5')
                                       )

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_value'), 5)

    def test_perform4(self):
        # Test performing a simple loop no timing. Continue
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.children_task.append(ContinueTask(task_name='break',
                                                    condition='True')
                                       )
        self.task.children_task.append(CheckTask(task_name='check'))

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_false(self.task.children_task[1].perform_called)

    def test_perform_task1(self):
        # Test performing a loop with an embedded task no timing.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.task = CheckTask(task_name='check')

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_index'), 11)
        assert_true(self.task.task.perform_called)
        assert_equal(self.task.task.perform_value, 10)

    def test_perform_task2(self):
        # Test performing a loop with an embedded task no timing. Break.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.task = CheckTask(task_name='check')
        self.task.children_task.append(BreakTask(task_name='break',
                                                 condition='{Test_index} == 6')
                                       )

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_index'), 6)
        assert_true(self.task.task.perform_called)
        assert_equal(self.task.task.perform_value, 5)

    def test_perform_task3(self):
        # Test performing a loop with an embedded task no timing. Continue.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.task = CheckTask(task_name='check')
        self.task.children_task.append(ContinueTask(task_name='break',
                                                    condition='True')
                                       )
        self.task.children_task.append(CheckTask(task_name='check'))

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_index'), 11)
        assert_true(self.task.task.perform_called)
        assert_equal(self.task.task.perform_value, 10)
        assert_false(self.task.children_task[1].perform_called)

    def test_perform_timing1(self):
        # Test performing a simple loop timing.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.timing = True

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_value'), 10)
        assert_not_equal(self.root.get_from_database('Test_elapsed_time'), 1.0)

    def test_perform_timing2(self):
        # Test performing a simple loop timing. Break
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.timing = True
        self.task.children_task.append(BreakTask(task_name='break',
                                                 condition='{Test_value} == 0')
                                       )

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_value'), 0)
        assert_not_equal(self.root.get_from_database('Test_elapsed_time'), 1.0)

    def test_perform_timing3(self):
        # Test performing a simple loop timing. Continue
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.timing = True
        self.task.children_task.append(ContinueTask(task_name='break',
                                                    condition='True')
                                       )
        self.task.children_task.append(CheckTask(task_name='check'))

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_false(self.task.children_task[1].perform_called)
        assert_not_equal(self.root.get_from_database('Test_elapsed_time'), 1.0)

    def test_perform_timing_task1(self):
        # Test performing a loop with an embedded task no timing.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.timing = True
        self.task.task = CheckTask(task_name='check')

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_index'), 11)
        assert_true(self.task.task.perform_called)
        assert_equal(self.task.task.perform_value, 10)
        assert_not_equal(self.root.get_from_database('Test_elapsed_time'), 1.0)

    def test_perform_timing_task2(self):
        # Test performing a loop with an embedded task no timing. Break.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.timing = True
        self.task.task = CheckTask(task_name='check')
        self.task.children_task.append(BreakTask(task_name='break',
                                                 condition='{Test_index} == 1')
                                       )

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_index'), 1)
        assert_true(self.task.task.perform_called)
        assert_equal(self.task.task.perform_value, 0)
        assert_not_equal(self.root.get_from_database('Test_elapsed_time'), 1.0)

    def test_perform_timing_task3(self):
        # Test performing a loop with an embedded task no timing. Continue.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.timing = True
        self.task.task = CheckTask(task_name='check')
        self.task.children_task.append(ContinueTask(task_name='break',
                                                    condition='True')
                                       )
        self.task.children_task.append(CheckTask(task_name='check'))

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_index'), 11)
        assert_true(self.task.task.perform_called)
        assert_equal(self.task.task.perform_value, 10)
        assert_false(self.task.children_task[1].perform_called)
        assert_not_equal(self.root.get_from_database('Test_elapsed_time'), 1.0)