Exemple #1
0
def test_deleting_child():
    """Test deleting a child.

    """
    root = RootTask()
    task1 = ComplexTask(name='task1', database_entries={'val1': 2.0})
    task2 = SimpleTask(name='task2',
                       database_entries={'val2': 1},
                       access_exs={'val2': 2})
    task3 = ComplexTask(name='task3')
    task4 = ComplexTask(name='task4')

    task1.add_child_task(0, task2)
    task1.add_child_task(1, task4)
    root.add_child_task(0, task1)
    root.add_child_task(1, task3)

    listener = SignalListener()
    task1.observe('children_changed', listener.listen)

    task1.remove_child_task(0)

    assert listener.counter == 1
    assert listener.signals[0].removed

    assert task1.preferences['children_0']['name'] == 'task4'
    assert 'task2_val2' not in task3.list_accessible_database_entries()

    root.remove_child_task(0)

    assert len(root.children) == 1
    with pytest.raises(KeyError):
        root.get_from_database('task1_val1')
Exemple #2
0
def test_deleting_child():
    """Test deleting a child.

    """
    root = RootTask()
    task1 = ComplexTask(name='task1',
                        database_entries={'val1': 2.0})
    task2 = SimpleTask(name='task2',
                       database_entries={'val2': 1},
                       access_exs={'val2': 2})
    task3 = ComplexTask(name='task3')
    task4 = ComplexTask(name='task4')

    task1.add_child_task(0, task2)
    task1.add_child_task(1, task4)
    root.add_child_task(0, task1)
    root.add_child_task(1, task3)

    listener = SignalListener()
    task1.observe('children_changed', listener.listen)

    task1.remove_child_task(0)

    assert task2.parent is None
    assert task2.root is None
    assert task2.database is None
    assert listener.counter == 1
    assert listener.signals[0].removed

    assert task1.preferences['children_0']['name'] == 'task4'
    assert 'task2_val2' not in task3.list_accessible_database_entries()

    root.remove_child_task(0)

    assert task1.parent is None
    assert task1.root is None
    assert task1.database is None
    assert task4.root is None
    assert task4.database is None
    assert len(root.children) == 1
    with pytest.raises(KeyError):
        root.get_from_database('task1_val1')
Exemple #3
0
def test_root_view(exopy_qtbot, task_workbench, dialog_sleep):
    """Test the behavior of the root task view.

    """
    task = RootTask()
    view = RootTaskView(task=task,
                        core=task_workbench.get_plugin('enaml.workbench.core'))
    editor = view.children[-1]

    win = show_widget(exopy_qtbot, view)
    exopy_qtbot.wait(dialog_sleep)
    assert editor.task is task
    assert editor.root is view

    TASK_NAME = 'Foo'

    def answer_dialog(bot, dial):
        selector = dial.selector
        selector.selected_task = 'exopy.ComplexTask'
        dial.config.task_name = TASK_NAME

    with handle_dialog(exopy_qtbot, 'accept', answer_dialog, cls=BuilderView):
        editor._empty_button.clicked = True

    def assert_task_children():
        assert task.children

    exopy_qtbot.wait_until(assert_task_children)
    assert type(task.children[0]) is ComplexTask
    assert len(editor._children_buttons) == 1
    exopy_qtbot.wait(dialog_sleep)

    TASK_NAME = 'Bar'
    with handle_dialog(exopy_qtbot, 'accept', answer_dialog, cls=BuilderView):
        editor.operations['add'](0, 'after')
    exopy_qtbot.wait(10)
    exopy_qtbot.wait(dialog_sleep)

    task.children[0].add_child_task(0, ComplexTask(name='Test'))
    get_window(exopy_qtbot).maximize()
    exopy_qtbot.wait(10)
    exopy_qtbot.wait(dialog_sleep)

    editor.operations['move'](0, 1)
    exopy_qtbot.wait(10)
    exopy_qtbot.wait(dialog_sleep)

    task.remove_child_task(1)
    exopy_qtbot.wait(10)
    exopy_qtbot.wait(dialog_sleep)
    assert len(view._cache) == 2

    # Test removing the last child and removing a view for an already removed
    # task
    child_task = task.children[0]
    editor.operations['remove'](0)
    exopy_qtbot.wait(10)
    exopy_qtbot.wait(dialog_sleep)
    assert len(view._cache) == 1

    view.discard_view(child_task)

    win.close()
Exemple #4
0
class TestInterfaceableTaskMixin(object):
    """Test the capabilities of task interfaces.

    """

    def setup(self):
        self.root = RootTask()
        self.mixin = Mixin(name='Simple')
        self.root.add_child_task(0, self.mixin)

    def test_interface_observer(self):
        """Test changing the interface.

        """
        i1 = InterfaceTest()
        i2 = InterfaceTest2()

        self.mixin.interface = i1
        assert i1.task is self.mixin
        assert self.mixin.database_entries == {'test': 2.0, 'itest': 1.0}
        assert i1.interface_id == (self.mixin.task_id +
                                   ':tasks.' + i1.__class__.__name__)

        self.mixin.interface = i2
        assert i2.task is self.mixin
        assert i1.task is None
        assert self.mixin.database_entries == {'test': 2.0, 'itest': 2.0,
                                               'fmt': '', 'feval': 0}

    def test_check1(self):
        """Test running checks when the interface is present.

        """
        self.mixin.interface = InterfaceTest(answer=True)

        res, traceback = self.mixin.check()
        assert res
        assert not traceback
        assert self.mixin.interface.called

    def test_check2(self):
        """Test running checks when no interface exist but i_perform is
        implemented.

        """
        res, traceback = IMixin().check()
        assert res
        assert not traceback

    def test_check3(self):
        """Test handling missing interface.

        """
        res, traceback = self.mixin.check()
        assert not res
        assert traceback
        assert len(traceback) == 1
        assert 'root/Simple-interface' in traceback

    def test_check4(self):
        """Test handling a non-passing test from the interface.

        """
        self.mixin.interface = InterfaceTest()

        res, traceback = self.mixin.check()
        assert not res
        assert len(traceback) == 1
        assert self.mixin.interface.called

    def test_check5(self):
        """Check that auto-check of fmt and feval tagged members works.

        """
        self.mixin.interface = InterfaceTest2(fmt='{Simple_test}',
                                              feval='2*{Simple_test}')

        res, traceback = self.mixin.check()
        assert res
        assert not traceback
        assert self.root.get_from_database('Simple_fmt') == '2.0'
        assert self.root.get_from_database('Simple_feval') == 4.0

        self.mixin.interface = InterfaceTest2bis(fmt='{Simple_test}',
                                                 feval='2*{Simple_test}')

        res, traceback = self.mixin.check()
        assert not res
        assert 'root/Simple-feval' in traceback

    def test_check6(self):
        """Check that auto-check of fmt and feavl handle errors.

        """
        self.mixin.interface = InterfaceTest2(fmt='{Simple_test*}',
                                              feval='2*{Simple_test}*')

        res, traceback = self.mixin.check()
        assert not res
        assert self.root.get_from_database('Simple_fmt') == ''
        assert self.root.get_from_database('Simple_feval') == 0
        assert len(traceback) == 2
        assert 'root/Simple-fmt' in traceback
        assert 'root/Simple-feval' in traceback

    def test_prepare(self):
        """Test that the prepare method does prepare the interface.

        """
        self.mixin.interface = InterfaceTest()

        self.mixin.prepare()
        assert self.mixin.interface.called

    def test_perform1(self):
        """Test perform does call interface if present.

        """
        self.mixin.interface = InterfaceTest()
        self.root.database.prepare_to_run()

        self.mixin.perform()
        assert self.mixin.get_from_database('Simple_itest') == 2.0

    def test_perform2(self):
        """Test perform use i_perform when no interface exists.

        """
        self.root.remove_child_task(0)
        self.mixin = IMixin(name='Simple')
        self.root.add_child_task(0, self.mixin)
        self.root.database.prepare_to_run()

        self.mixin.perform()
        assert self.root.get_from_database('Simple_test') == 3.0

    def test_build_from_config1(self):
        """Test building a interfaceable task with no interface from a config.

        """
        aux = RootTask()
        aux.add_child_task(0, IMixin())

        bis = RootTask.build_from_config(aux.preferences,
                                         {'exopy.task':
                                             {'tasks.IMixin': IMixin,
                                              'exopy.RootTask': RootTask}})
        assert type(bis.children[0]).__name__ == 'IMixin'

    def test_build_from_config2(self):
        """Test building a interfaceable task with an interface from a config.

        """
        self.mixin.interface = InterfaceTest(answer=True)
        self.root.update_preferences_from_members()
        deps = {'exopy.task': {'tasks.Mixin': Mixin,
                               'exopy.RootTask': RootTask},
                'exopy.tasks.interface':
                    {'tasks.Mixin:tasks.InterfaceTest': InterfaceTest}}
        bis = RootTask.build_from_config(self.root.preferences, deps)

        assert type(bis.children[0].interface).__name__ == 'InterfaceTest'

    def test_traverse(self):
        """Test traversing a task with interface.

        """
        self.mixin.interface = InterfaceTest2()

        w = list(self.mixin.traverse())
        assert w == [self.mixin, self.mixin.interface]
Exemple #5
0
class TestInterfaceableTaskMixin(object):
    """Test the capabilities of task interfaces.

    """

    def setup(self):
        self.root = RootTask()
        self.mixin = Mixin(name='Simple')
        self.root.add_child_task(0, self.mixin)

    def test_interface_observer(self):
        """Test changing the interface.

        """
        i1 = InterfaceTest()
        i2 = InterfaceTest2()

        self.mixin.interface = i1
        assert i1.task is self.mixin
        assert self.mixin.database_entries == {'test': 2.0, 'itest': 1.0}
        assert i1.interface_id == (self.mixin.task_id +
                                   ':tasks.' + i1.__class__.__name__)

        self.mixin.interface = i2
        assert i2.task is self.mixin
        assert i1.task is None
        assert self.mixin.database_entries == {'test': 2.0, 'itest': 2.0,
                                               'fmt': '', 'feval': 0}

    def test_check1(self):
        """Test running checks when the interface is present.

        """
        self.mixin.interface = InterfaceTest(answer=True)

        res, traceback = self.mixin.check()
        assert res
        assert not traceback
        assert self.mixin.interface.called

    def test_check2(self):
        """Test running checks when no interface exist but i_perform is
        implemented.

        """
        res, traceback = IMixin().check()
        assert res
        assert not traceback

    def test_check3(self):
        """Test handling missing interface.

        """
        res, traceback = self.mixin.check()
        assert not res
        assert traceback
        assert len(traceback) == 1
        assert 'root/Simple-interface' in traceback

    def test_check4(self):
        """Test handling a non-passing test from the interface.

        """
        self.mixin.interface = InterfaceTest()

        res, traceback = self.mixin.check()
        assert not res
        assert len(traceback) == 1
        assert self.mixin.interface.called

    def test_check5(self):
        """Check that auto-check of fmt and feval tagged members works.

        """
        self.mixin.interface = InterfaceTest2(fmt='{Simple_test}',
                                              feval='2*{Simple_test}')

        res, traceback = self.mixin.check()
        assert res
        assert not traceback
        assert self.root.get_from_database('Simple_fmt') == '2.0'
        assert self.root.get_from_database('Simple_feval') == 4.0

        self.mixin.interface = InterfaceTest2bis(fmt='{Simple_test}',
                                                 feval='2*{Simple_test}')

        res, traceback = self.mixin.check()
        assert not res
        assert 'root/Simple-feval' in traceback

    def test_check6(self):
        """Check that auto-check of fmt and feavl handle errors.

        """
        self.mixin.interface = InterfaceTest2(fmt='{Simple_test*}',
                                              feval='2*{Simple_test}*')

        res, traceback = self.mixin.check()
        assert not res
        assert self.root.get_from_database('Simple_fmt') == ''
        assert self.root.get_from_database('Simple_feval') == 0
        assert len(traceback) == 2
        assert 'root/Simple-fmt' in traceback
        assert 'root/Simple-feval' in traceback

    def test_prepare(self):
        """Test that the prepare method does prepare the interface.

        """
        self.mixin.interface = InterfaceTest()

        self.mixin.prepare()
        assert self.mixin.interface.called

    def test_perform1(self):
        """Test perform does call interface if present.

        """
        self.mixin.interface = InterfaceTest()
        self.root.database.prepare_to_run()

        self.mixin.perform()
        assert self.mixin.get_from_database('Simple_itest') == 2.0

    def test_perform2(self):
        """Test perform use i_perform when no interface exists.

        """
        self.root.remove_child_task(0)
        self.mixin = IMixin(name='Simple')
        self.root.add_child_task(0, self.mixin)
        self.root.database.prepare_to_run()

        self.mixin.perform()
        assert self.root.get_from_database('Simple_test') == 3.0

    def test_build_from_config1(self):
        """Test building a interfaceable task with no interface from a config.

        """
        aux = RootTask()
        aux.add_child_task(0, IMixin())

        bis = RootTask.build_from_config(aux.preferences,
                                         {'exopy.task':
                                             {'tasks.IMixin': IMixin,
                                              'exopy.RootTask': RootTask}})
        assert type(bis.children[0]).__name__ == 'IMixin'

    def test_build_from_config2(self):
        """Test building a interfaceable task with an interface from a config.

        """
        self.mixin.interface = InterfaceTest(answer=True)
        self.root.update_preferences_from_members()
        deps = {'exopy.task': {'tasks.Mixin': Mixin,
                               'exopy.RootTask': RootTask},
                'exopy.tasks.interface':
                    {'tasks.Mixin:tasks.InterfaceTest': InterfaceTest}}
        bis = RootTask.build_from_config(self.root.preferences, deps)

        assert type(bis.children[0].interface).__name__ == 'InterfaceTest'

    def test_traverse(self):
        """Test traversing a task with interface.

        """
        self.mixin.interface = InterfaceTest2()

        w = list(self.mixin.traverse())
        assert w == [self.mixin, self.mixin.interface]
Exemple #6
0
def test_root_view(exopy_qtbot, task_workbench, dialog_sleep):
    """Test the behavior of the root task view.

    """
    task = RootTask()
    view = RootTaskView(task=task,
                        core=task_workbench.get_plugin('enaml.workbench.core'))
    editor = view.children[-1]

    win = show_widget(exopy_qtbot, view)
    exopy_qtbot.wait(dialog_sleep)
    assert editor.task is task
    assert editor.root is view

    TASK_NAME = 'Foo'

    def answer_dialog(bot, dial):
        selector = dial.selector
        selector.selected_task = 'exopy.ComplexTask'
        dial.config.task_name = TASK_NAME

    with handle_dialog(exopy_qtbot, 'accept', answer_dialog, cls=BuilderView):
        editor._empty_button.clicked = True

    def assert_task_children():
        assert task.children
    exopy_qtbot.wait_until(assert_task_children)
    assert type(task.children[0]) is ComplexTask
    assert len(editor._children_buttons) == 1
    exopy_qtbot.wait(dialog_sleep)

    TASK_NAME = 'Bar'
    with handle_dialog(exopy_qtbot, 'accept', answer_dialog, cls=BuilderView):
        editor.operations['add'](0, 'after')
    exopy_qtbot.wait(10)
    exopy_qtbot.wait(dialog_sleep)

    task.children[0].add_child_task(0, ComplexTask(name='Test'))
    get_window(exopy_qtbot).maximize()
    exopy_qtbot.wait(10)
    exopy_qtbot.wait(dialog_sleep)

    editor.operations['move'](0, 1)
    exopy_qtbot.wait(10)
    exopy_qtbot.wait(dialog_sleep)

    task.remove_child_task(1)
    exopy_qtbot.wait(10)
    exopy_qtbot.wait(dialog_sleep)
    assert len(view._cache) == 2

    # Test removing the last child and removing a view for an already removed
    # task
    child_task = task.children[0]
    editor.operations['remove'](0)
    exopy_qtbot.wait(10)
    exopy_qtbot.wait(dialog_sleep)
    assert len(view._cache) == 1

    view.discard_view(child_task)

    win.close()