コード例 #1
0
ファイル: test_base_tasks.py プロジェクト: Qcircuits/ecpy
def test_moving_child():
    """Test moving 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)

    assert task1.preferences['children_0']['name'] == 'task2'
    assert task1.preferences['children_1']['name'] == 'task4'

    task1.move_child_task(0, 1)

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

    assert task1.preferences['children_0']['name'] == 'task4'
    assert task1.preferences['children_1']['name'] == 'task2'
    assert task3.get_from_database('task2_val2') == 1
コード例 #2
0
ファイル: test_base_tasks.py プロジェクト: PhilipVinc/ecpy
def test_moving_child():
    """Test moving 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)

    assert task1.preferences['children_0']['name'] == 'task2'
    assert task1.preferences['children_1']['name'] == 'task4'

    task1.move_child_task(0, 1)

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

    assert task1.preferences['children_0']['name'] == 'task4'
    assert task1.preferences['children_1']['name'] == 'task2'
    assert task3.get_from_database('task2_val2') == 1
コード例 #3
0
ファイル: test_base_tasks.py プロジェクト: PhilipVinc/ecpy
def test_database_update_with_exception():
    """Test that replacing the database_entries members refreshes the database.

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

    assert task3.get_from_database('task2_val2')

    entries = task2.database_entries.copy()
    del entries['val2']
    task2.database_entries = entries

    with pytest.raises(KeyError):
        task1.get_from_database('task2_val2')

    with pytest.raises(KeyError):
        task3.get_from_database('task2_val2')
コード例 #4
0
ファイル: test_log_task.py プロジェクト: PhilipVinc/ecpy
class TestLogTask(object):
    """Test LogTask.

    """

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

    def test_check1(self):
        """Test checking that a message that cannot be formatted will result in a fail

        """
        self.task.message = 'TestMessage {aa}'

        test, traceback = self.task.check()

        assert not test
        assert len(traceback) == 1
        assert 'root/Test-message' in traceback
        assert not self.task.get_from_database('Test_message')

    def test_perform1(self):
        """Test checking that the message value gets written to the database

        """
        self.task.write_in_database('val', 'World')
        self.task.message = 'Hello {Test_val}'
        self.root.prepare()

        self.task.perform()
        assert self.task.get_from_database('Test_message') == 'Hello World'
コード例 #5
0
ファイル: test_string_ops.py プロジェクト: Qcircuits/ecpy
 def setup(self):
     self.root = RootTask()
     database = self.root.database
     database.set_value('root', 'val1', 1)
     database.create_node('root', 'node1')
     database.set_value('root/node1', 'val2', 10.0)
     database.add_access_exception('root', 'root/node1', 'val2')
コード例 #6
0
ファイル: test_base_tasks.py プロジェクト: Qcircuits/ecpy
def test_task_renaming():
    """Test renaming simple and complex task.

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

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

    task3.name = 'worker3'
    with pytest.raises(KeyError):
        root.get_from_database('task3_val2')
    assert root.get_from_database('worker3_val2') == 1

    task1.name = 'worker1'
    with pytest.raises(KeyError):
        root.get_from_database('task1_val1')
    assert root.get_from_database('worker1_val1') == 2.0
    assert root.get_from_database('worker3_val2') == 1
コード例 #7
0
    def setup(self):
        r = RootTask()
        r.run_time = {
            d_id: {
                'd': (object, FalseStarter())
            },
            p_id: {
                'p': {
                    'connections': {
                        'c': {},
                        'c2': {}
                    },
                    'settings': {
                        's': {}
                    }
                }
            }
        }

        class InTask(InstrumentTask):
            feval = Unicode('1').tag(feval=Feval())

        self.task = InTask(name='Dummy',
                           selected_instrument=('p', 'd', 'c', 's'))
        r.add_child_task(0, self.task)
        self.err_path = 'root/Dummy-instrument'
コード例 #8
0
ファイル: test_base_tasks.py プロジェクト: Qcircuits/ecpy
def test_database_update_with_exception():
    """Test that replacing the database_entries members refreshes the database.

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

    assert task3.get_from_database('task2_val2')

    entries = task2.database_entries.copy()
    del entries['val2']
    task2.database_entries = entries

    with pytest.raises(KeyError):
        task1.get_from_database('task2_val2')

    with pytest.raises(KeyError):
        task3.get_from_database('task2_val2')
コード例 #9
0
class TestLogTask(object):
    """Test LogTask.

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

    def test_check1(self):
        """Test checking that a message that cannot be formatted will result in a fail

        """
        self.task.message = 'TestMessage {aa}'

        test, traceback = self.task.check()

        assert not test
        assert len(traceback) == 1
        assert 'root/Test-message' in traceback
        assert not self.task.get_from_database('Test_message')

    def test_perform1(self):
        """Test checking that the message value gets written to the database

        """
        self.task.write_in_database('val', 'World')
        self.task.message = 'Hello {Test_val}'
        self.root.prepare()

        self.task.perform()
        assert self.task.get_from_database('Test_message') == 'Hello World'
コード例 #10
0
ファイル: test_instr_task.py プロジェクト: PhilipVinc/ecpy
 def setup(self):
     r = RootTask()
     r.run_time = {d_id: {'d': (object, FalseStarter())},
                   p_id: {'p': {'connections': {'c': {}, 'c2': {}},
                                'settings': {'s': {}}}}}
     self.task = InstrumentTask(name='Dummy',
                                selected_instrument=('p', 'd', 'c', 's'))
     r.add_child_task(0, self.task)
     self.err_path = 'root/Dummy-instrument'
コード例 #11
0
def test_root_view(windows, 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(view)
    sleep(dialog_sleep)
    assert editor.task is task
    assert editor.root is view

    TASK_NAME = 'Foo'

    def answer_dialog(dial):
        selector = dial.selector
        selector.selected_task = 'ecpy.ComplexTask'
        dial.config.task_name = TASK_NAME
        process_app_events()

    with handle_dialog('accept', answer_dialog, cls=BuilderView):
        editor._empty_button.clicked = True
    process_app_events()
    assert task.children
    assert type(task.children[0]) is ComplexTask
    assert len(editor._children_buttons) == 1
    sleep(dialog_sleep)

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

    task.children[0].add_child_task(0, ComplexTask(name='Test'))
    get_window().maximize()
    process_app_events()
    sleep(dialog_sleep)

    editor.operations['move'](0, 1)
    process_app_events()
    sleep(dialog_sleep)

    task.remove_child_task(1)
    process_app_events()
    sleep(dialog_sleep)
    assert len(view._cache) == 2

    editor.operations['remove'](0)
    process_app_events()
    sleep(dialog_sleep)
    assert len(view._cache) == 1

    win.close()
コード例 #12
0
ファイル: test_base_tasks.py プロジェクト: PhilipVinc/ecpy
def test_task_renaming():
    """Test renaming simple and complex task.

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

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

    task3.name = 'worker3'
    with pytest.raises(KeyError):
        root.get_from_database('task3_val2')
    assert root.get_from_database('worker3_val2') == 1

    task1.name = 'worker1'
    with pytest.raises(KeyError):
        root.get_from_database('task1_val1')
    assert root.get_from_database('worker1_val1') == 2.0
    assert root.get_from_database('worker3_val2') == 1
コード例 #13
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,
                                         {'ecpy.task': {'tests.IMixin': IMixin,
                                                        'ecpy.RootTask':
                                                            RootTask}})
        assert type(bis.children[0]).__name__ == 'IMixin'
コード例 #14
0
ファイル: test_base_tasks.py プロジェクト: PhilipVinc/ecpy
def test_database_update():
    """Test that replacing the database_entries members refreshes the database.

    """
    root = RootTask()
    entries = root.database_entries.copy()
    del entries['default_path']
    entries['name'] = 'Test'
    root.database_entries = entries

    assert root.get_from_database('name') == 'Test'
    with pytest.raises(KeyError):
        root.get_from_database('default_path')
コード例 #15
0
ファイル: test_base_tasks.py プロジェクト: Qcircuits/ecpy
def test_database_operation():
    """Test setting, getting, deleting a value from the database.

    """
    root = RootTask()
    root.write_in_database('test', 1)
    assert root.get_from_database('test') == 1
    root.remove_from_database('test')
    with pytest.raises(KeyError):
        root.get_from_database('test')
コード例 #16
0
ファイル: test_execution.py プロジェクト: Qcircuits/ecpy
 def setup(self):
     root = RootTask()
     root.should_pause = Event()
     root.should_stop = Event()
     root.paused = Event()
     root.resumed = Event()
     root.default_path = 'toto'
     root.write_in_database('meas_name', 'M')
     root.write_in_database('meas_id', '001')
     self.root = root
コード例 #17
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,
            {'ecpy.task': {
                'tests.IMixin': IMixin,
                'ecpy.RootTask': RootTask
            }})
        assert type(bis.children[0]).__name__ == 'IMixin'
コード例 #18
0
    def test_build_from_config1(self):
        """Test building a interfaceable interface with no interface from a
        config.

        """
        aux = RootTask()
        mixin = Mixin()
        mixin.interface = InterfaceTest3()
        aux.add_child_task(0, mixin)
        deps = {'ecpy.task': {'tests.Mixin': Mixin, 'ecpy.RootTask': RootTask},
                'ecpy.tasks.interface':
                    {('InterfaceTest3', ('tests.Mixin',)): InterfaceTest3}}
        bis = RootTask.build_from_config(aux.preferences, deps)
        assert type(bis.children[0].interface).__name__ == 'InterfaceTest3'
コード例 #19
0
ファイル: test_base_tasks.py プロジェクト: Qcircuits/ecpy
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')
コード例 #20
0
ファイル: test_base_tasks.py プロジェクト: Qcircuits/ecpy
def test_build_root_from_config():
    """Test building a RootTask from config.

    """
    class DummyTask(SimpleTask):

        database_entries = {'test': 1}

    config = {
        'name': 'test',
        'children_0': {
            'name': 'test_child',
            'task_id': 'DummyTask'
        }
    }
    task = RootTask.build_from_config(config,
                                      {'ecpy.task': {
                                          'DummyTask': DummyTask
                                      }})
    assert task.name == 'Root'
    assert len(task.children) == 1
    assert task.children[0].name == 'test_child'
    assert task.children[0].root
    assert isinstance(task.children[0], DummyTask)
    assert task.get_from_database('test_child_test')
コード例 #21
0
    def test_build_from_config2(self):
        """Test building a interfaceable interface with an interface from a
        config.

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

        interface = bis.children[0].interface.interface
        assert type(interface).__name__ == 'IIinterfaceTest1'
        assert self.root.children[0].database_entries ==\
            {'test': 2.0, 'itest': 1.0}
コード例 #22
0
ファイル: test_string_ops.py プロジェクト: PhilipVinc/ecpy
 def setup(self):
     self.root = RootTask()
     database = self.root.database
     database.set_value('root', 'val1', 1)
     database.create_node('root', 'node1')
     database.set_value('root/node1', 'val2', 10.0)
     database.add_access_exception('root', 'root/node1', 'val2')
コード例 #23
0
ファイル: test_base_tasks.py プロジェクト: PhilipVinc/ecpy
def test_database_operation():
    """Test setting, getting, deleting a value from the database.

    """
    root = RootTask()
    root.write_in_database('test', 1)
    assert root.get_from_database('test') == 1
    root.remove_from_database('test')
    with pytest.raises(KeyError):
        root.get_from_database('test')
コード例 #24
0
ファイル: test_base_tasks.py プロジェクト: PhilipVinc/ecpy
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')
コード例 #25
0
ファイル: test_base_tasks.py プロジェクト: PhilipVinc/ecpy
def test_update_preferences_from_members():
    """Test updating the preferences.

    Only operation on the children cause re-registering to ensure the children
    ordering.

    """
    root = RootTask()
    task1 = SimpleTask(name='task1')

    root.add_child_task(0, task1)

    assert root.preferences['children_0']['name'] == 'task1'

    task1.name = 'worker1'
    assert root.preferences['children_0']['name'] == 'task1'

    root.update_preferences_from_members()
    assert root.preferences['children_0']['name'] == 'worker1'
コード例 #26
0
ファイル: test_base_tasks.py プロジェクト: PhilipVinc/ecpy
def test_traverse():
    """Test traversing a task hierarchy to collect infos.

    """
    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')
    task1.add_child_task(0, task2)
    root.add_child_task(0, task1)
    root.add_child_task(1, task3)

    flat = list(root.traverse())
    assert flat == [root, task1, task2, task3]

    flat = list(root.traverse(0))
    assert flat == [root, task1, task3]
コード例 #27
0
    def test_build_from_config1(self):
        """Test building a interfaceable interface with no interface from a
        config.

        """
        aux = RootTask()
        mixin = Mixin()
        mixin.interface = InterfaceTest3()
        aux.add_child_task(0, mixin)
        deps = {
            'ecpy.task': {
                'tests.Mixin': Mixin,
                'ecpy.RootTask': RootTask
            },
            'ecpy.tasks.interface': {
                'tests.Mixin:tests.InterfaceTest3': InterfaceTest3
            }
        }
        bis = RootTask.build_from_config(aux.preferences, deps)
        assert type(bis.children[0].interface).__name__ == 'InterfaceTest3'
コード例 #28
0
    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 = {'ecpy.task': {'tests.Mixin': Mixin, 'ecpy.RootTask': RootTask},
                'ecpy.tasks.interface':
                    {('InterfaceTest', ('tests.Mixin',)): InterfaceTest}}
        bis = RootTask.build_from_config(self.root.preferences, deps)

        assert type(bis.children[0].interface).__name__ == 'InterfaceTest'
コード例 #29
0
ファイル: test_execution.py プロジェクト: PhilipVinc/ecpy
 def setup(self):
     root = RootTask()
     root.should_pause = Event()
     root.should_stop = Event()
     root.paused = Event()
     root.resumed = Event()
     root.default_path = 'toto'
     self.root = root
コード例 #30
0
ファイル: test_base_tasks.py プロジェクト: PhilipVinc/ecpy
def test_access_exceptions():
    """Test adding, modifying and removing an access exception after creation.

    """
    root = RootTask()
    listener = SignalListener()
    root.observe('children_changed', listener.listen)
    task1 = ComplexTask(name='task1',
                        database_entries={'val1': 2.0})
    task2 = ComplexTask(name='task2')
    task3 = SimpleTask(name='task3',
                       database_entries={'val2': 1, 'val3': 2},
                       )

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

    with pytest.raises(KeyError):
        task2.get_from_database('task3_val2')

    task3.add_access_exception('val2', 1)
    task3.add_access_exception('val3', 1)

    assert task2.get_from_database('task3_val2') == 1
    assert task2.get_from_database('task3_val2') == 1
    with pytest.raises(KeyError):
        task1.get_from_database('task3_val2')

    task3.modify_access_exception('val2', 2)
    task3.modify_access_exception('val3', -1)
    assert task1.get_from_database('task3_val2') == 1
    with pytest.raises(KeyError):
        task2.get_from_database('task3_val3')

    task3.remove_access_exception('val2')
    with pytest.raises(KeyError):
        task2.get_from_database('task3_val2')
コード例 #31
0
def test_swapping(windows, task_workbench, dialog_sleep):
    """Test moving a view between containers.

    """
    task = RootTask()
    view = RootTaskView(task=task,
                        core=task_workbench.get_plugin('enaml.workbench.core'))

    subtask = ComplexTask(name='Test')
    subview = view.view_for(subtask)

    task.add_child_task(0, subtask)

    cont = Container()

    show_widget(cont)
    view.set_parent(cont)
    view.refresh()
    process_app_events()
    assert cont.children == [view]
    sleep(dialog_sleep)

    view.set_parent(None)
    subview.set_parent(cont)
    subview.refresh()
    process_app_events()
    assert cont.children == [subview]
    sleep(dialog_sleep)

    subview.set_parent(None)
    view.set_parent(cont)
    view.refresh()
    process_app_events()
    assert cont.children == [view]
    assert subview.visible
    sleep(dialog_sleep)
コード例 #32
0
ファイル: test_base_views.py プロジェクト: PhilipVinc/ecpy
def test_swapping(windows, task_workbench, dialog_sleep):
    """Test moving a view between containers.

    """
    task = RootTask()
    view = RootTaskView(task=task,
                        core=task_workbench.get_plugin('enaml.workbench.core'))

    subtask = ComplexTask(name='Test')
    subview = view.view_for(subtask)

    task.add_child_task(0, subtask)

    cont = Container()

    show_widget(cont)
    view.set_parent(cont)
    view.refresh()
    process_app_events()
    assert cont.children == [view]
    sleep(dialog_sleep)

    view.set_parent(None)
    subview.set_parent(cont)
    subview.refresh()
    process_app_events()
    assert cont.children == [subview]
    sleep(dialog_sleep)

    subview.set_parent(None)
    view.set_parent(cont)
    view.refresh()
    process_app_events()
    assert cont.children == [view]
    assert subview.visible
    sleep(dialog_sleep)
コード例 #33
0
class TestDefinitionTask(object):
    """Test DefinitionTask.

    """

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

    def test_perform1(self):
        """Test checking that the formatted definition gets written to the
        database

        """
        self.task.write_in_database('it', 'World')
        self.task.definitions = OrderedDict([('key1', "2.0+3.0"),
                                             ('key2', 'Hello')])
        self.root.prepare()

        self.task.check()
        assert self.task.get_from_database('Test_key1') == safe_eval(
            "1.0+4.0", {})
        assert self.task.get_from_database('Test_key2') == "Hello"

    def test_check_after_load(self):
        """Test checking for correct loading from pref and that we can still
        recall values from the database

        """
        self.task.write_in_database('it', 'World')

        pref = "[(u'key1', u'1.0+3.0'), (u'key2', u'Hello')]"
        self.task.definitions = ordered_dict_from_pref(self,
                                                       self.task.definitions,
                                                       pref)

        self.root.prepare()

        self.task.check()
        assert self.task.get_from_database('Test_key1') == safe_eval(
            "1.0+3.0", {})
        assert self.task.get_from_database('Test_key2') == "Hello"

    def test_check(self):
        """Test checking that an unformattable definition gives an error

        """
        self.task.definitions = OrderedDict([('key1', "1.0+3.0"),
                                             ('key2', '3.0+4.0 + {Test_pi}')])

        test, traceback = self.task.check()
        assert not test
        assert len(traceback) == 1
        assert 'root/Test-key2' in traceback
コード例 #34
0
ファイル: test_base_tasks.py プロジェクト: Qcircuits/ecpy
def test_root_registering():
    """Check that the root task does write its default entries in the database
    when instantiated.

    """
    root = RootTask()
    assert root.get_from_database('default_path') == ''
    root.children = [
        SimpleTask(name='task2',
                   database_entries={'val2': 1},
                   root=root,
                   parent=root,
                   database=root.database)
    ]
    root.register_in_database()
    assert root.get_from_database('task2_val2') == 1
コード例 #35
0
    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 = {
            'ecpy.task': {
                'tests.Mixin': Mixin,
                'ecpy.RootTask': RootTask
            },
            'ecpy.tasks.interface': {
                'tests.Mixin:tests.InterfaceTest': InterfaceTest
            }
        }
        bis = RootTask.build_from_config(self.root.preferences, deps)

        assert type(bis.children[0].interface).__name__ == 'InterfaceTest'
コード例 #36
0
ファイル: test_base_tasks.py プロジェクト: Qcircuits/ecpy
def test_database_update():
    """Test that replacing the database_entries members refreshes the database.

    """
    root = RootTask()
    entries = root.database_entries.copy()
    del entries['default_path']
    entries['name'] = 'Test'
    root.database_entries = entries

    assert root.get_from_database('name') == 'Test'
    with pytest.raises(KeyError):
        root.get_from_database('default_path')
コード例 #37
0
ファイル: test_base_tasks.py プロジェクト: PhilipVinc/ecpy
def test_root_registering():
    """Check that the root task does write its default entries in the database
    when instantiated.

    """
    root = RootTask()
    assert root.get_from_database('default_path') == ''
    root.children = [SimpleTask(name='task2',
                                database_entries={'val2': 1},
                                root=root, parent=root,
                                database=root.database)]
    root.register_in_database()
    assert root.get_from_database('task2_val2') == 1
コード例 #38
0
ファイル: test_base_tasks.py プロジェクト: PhilipVinc/ecpy
def test_build_root_from_config():
    """Test building a RootTask from config.

    """
    class DummyTask(SimpleTask):

        database_entries = {'test': 1}

    config = {'name': 'test',
              'children_0': {'name': 'test_child',
                             'task_id': 'DummyTask'}}
    task = RootTask.build_from_config(config,
                                      {'ecpy.task':
                                          {'DummyTask': DummyTask}})
    assert task.name == 'Root'
    assert len(task.children) == 1
    assert task.children[0].name == 'test_child'
    assert task.children[0].root
    assert isinstance(task.children[0], DummyTask)
    assert task.get_from_database('test_child_test')
コード例 #39
0
    def test_build_from_config2(self):
        """Test building a interfaceable interface with an interface from a
        config.

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

        interface = bis.children[0].interface.interface
        assert type(interface).__name__ == 'IIinterfaceTest1'
        assert self.root.children[0].database_entries ==\
            {'test': 2.0, 'itest': 1.0}
コード例 #40
0
class TestFormulaTask(object):
    """Test FormulaTask.

    """

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

    def test_perform1(self):
        """Test checking that the evaluated formula gets written to the
        database

        """
        self.task.formulas = OrderedDict([('key1', "1.0+3.0"),
                                          ('key2', '3.0+4.0')])
        self.root.prepare()

        self.task.perform()
        assert (self.task.get_from_database('Test_key1') == 4.0 and
                self.task.get_from_database('Test_key2') == 7.0)

    def test_perform_from_load(self):
        """Test checking for correct loading from pref and that we can still
        recall values from the database

        """
        self.task.write_in_database('pi', 3.1)
        self.task.formulas = ordered_dict_from_pref(self, self.task.formulas,
            "[(u'key1', '1.0+3.0'), (u'key2', '3.0 + {Test_pi}')]")
        self.root.prepare()

        self.task.perform()
        assert (self.task.get_from_database('Test_key1') == 4.0 and
                self.task.get_from_database('Test_key2') == 6.1)

    def test_check(self):
        """Test checking that an unformattable formula gives an error

        """
        self.task.formulas = OrderedDict([('key1', "1.0+3.0"),
                                          ('key2', '3.0+4.0 + {Test_pi}')])

        test, traceback = self.task.check()
        assert not test
        assert len(traceback) == 1
        assert 'root/Test-key2' in traceback
コード例 #41
0
def test_root_path_edition(windows, task_workbench, dialog_sleep,
                           monkeypatch):
    """Test the behavior of the root task view.

    """
    task = RootTask()
    view = RootTaskView(task=task,
                        core=task_workbench.get_plugin('enaml.workbench.core'))

    butt = view.widgets()[2]

    @classmethod
    def choose_path(cls, **kwargs):
        return 'test/path'
    with enaml.imports():
        from ecpy.tasks.tasks.base_views import FileDialogEx
    monkeypatch.setattr(FileDialogEx, 'get_existing_directory',
                        choose_path)

    butt.clicked = True
    assert task.default_path == 'test/path'

    @classmethod
    def choose_path(cls, **kwargs):
        return ''
    monkeypatch.setattr(FileDialogEx, 'get_existing_directory',
                        choose_path)

    butt.clicked = True
    assert task.default_path == 'test/path'

    @classmethod
    def choose_path(cls, **kwargs):
        return ''
    monkeypatch.setattr(FileDialogEx, 'get_existing_directory',
                        choose_path)
コード例 #42
0
ファイル: test_base_tasks.py プロジェクト: Qcircuits/ecpy
def test_adding_child():
    """Test adding children.

    This test adding a child with and without access_exs to a task which is not
    root and then to the root. This makes sure that giving the root afterwards
    does trigger the right updates.

    """
    root = RootTask()
    listener = SignalListener()
    root.observe('children_changed', listener.listen)
    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')
    task1.add_child_task(0, task2)
    root.add_child_task(0, task1)
    root.add_child_task(1, task3)

    assert task1.depth == 1
    assert task1.path == 'root'
    assert task1.database is root.database
    assert task1.root is root
    assert task1.parent is root

    assert task2.depth == 2
    assert task2.path == 'root/task1'
    assert task2.database is root.database
    assert task2.root is root
    assert task2.parent is task1

    assert task1.get_from_database('task1_val1') == 2.0
    assert root.get_from_database('task1_val1') == 2.0
    assert task3.get_from_database('task2_val2') == 1

    assert listener.counter == 2
    assert all([bool(c.added) for c in listener.signals])
コード例 #43
0
ファイル: test_base_tasks.py プロジェクト: Qcircuits/ecpy
def test_traverse():
    """Test traversing a task hierarchy to collect infos.

    """
    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')
    task1.add_child_task(0, task2)
    root.add_child_task(0, task1)
    root.add_child_task(1, task3)

    flat = list(root.traverse())
    assert flat == [root, task1, task2, task3]

    flat = list(root.traverse(0))
    assert flat == [root, task1, task3]
コード例 #44
0
ファイル: test_base_tasks.py プロジェクト: Qcircuits/ecpy
def test_update_preferences_from_members():
    """Test updating the preferences.

    Only operation on the children cause re-registering to ensure the children
    ordering.

    """
    root = RootTask()
    task1 = SimpleTask(name='task1')

    root.add_child_task(0, task1)

    assert root.preferences['children_0']['name'] == 'task1'

    task1.name = 'worker1'
    assert root.preferences['children_0']['name'] == 'task1'

    root.update_preferences_from_members()
    assert root.preferences['children_0']['name'] == 'worker1'
コード例 #45
0
ファイル: test_base_tasks.py プロジェクト: Qcircuits/ecpy
def test_access_exceptions():
    """Test adding, modifying and removing an access exception after creation.

    """
    root = RootTask()
    listener = SignalListener()
    root.observe('children_changed', listener.listen)
    task1 = ComplexTask(name='task1', database_entries={'val1': 2.0})
    task2 = ComplexTask(name='task2')
    task3 = SimpleTask(
        name='task3',
        database_entries={
            'val2': 1,
            'val3': 2
        },
    )

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

    with pytest.raises(KeyError):
        task2.get_from_database('task3_val2')

    task3.add_access_exception('val2', 1)
    task3.add_access_exception('val3', 1)

    assert task2.get_from_database('task3_val2') == 1
    assert task2.get_from_database('task3_val2') == 1
    with pytest.raises(KeyError):
        task1.get_from_database('task3_val2')

    task3.modify_access_exception('val2', 2)
    task3.modify_access_exception('val3', -1)
    assert task1.get_from_database('task3_val2') == 1
    with pytest.raises(KeyError):
        task2.get_from_database('task3_val3')

    task3.remove_access_exception('val2')
    with pytest.raises(KeyError):
        task2.get_from_database('task3_val2')
コード例 #46
0
ファイル: test_base_tasks.py プロジェクト: PhilipVinc/ecpy
def test_adding_child():
    """Test adding children.

    This test adding a child with and without access_exs to a task which is not
    root and then to the root. This makes sure that giving the root afterwards
    does trigger the right updates.

    """
    root = RootTask()
    listener = SignalListener()
    root.observe('children_changed', listener.listen)
    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')
    task1.add_child_task(0, task2)
    root.add_child_task(0, task1)
    root.add_child_task(1, task3)

    assert task1.depth == 1
    assert task1.path == 'root'
    assert task1.database is root.database
    assert task1.root is root
    assert task1.parent is root

    assert task2.depth == 2
    assert task2.path == 'root/task1'
    assert task2.database is root.database
    assert task2.root is root
    assert task2.parent is task1

    assert task1.get_from_database('task1_val1') == 2.0
    assert root.get_from_database('task1_val1') == 2.0
    assert task3.get_from_database('task2_val2') == 1

    assert listener.counter == 2
    assert all([bool(c.added) for c in listener.signals])
コード例 #47
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[1] == (self.mixin.task_id,)

        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 feavl 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

    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_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,
                                         {'ecpy.task': {'tests.IMixin': IMixin,
                                                        'ecpy.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 = {'ecpy.task': {'tests.Mixin': Mixin, 'ecpy.RootTask': RootTask},
                'ecpy.tasks.interface':
                    {('InterfaceTest', ('tests.Mixin',)): 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]
コード例 #48
0
 def setup(self):
     self.root = RootTask()
     self.mixin = InterfaceTest3()
     self.root.add_child_task(0, Mixin(name='Simple', interface=self.mixin))
コード例 #49
0
class TestInterfaceableInterfaceMixin(object):
    """Test the capabilities of task interfaces.

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

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

        """
        i1 = IIinterfaceTest1()
        i2 = IIinterfaceTest2()

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

        self.mixin.interface = i2
        assert i2.task is self.mixin.task
        assert i1.parent is None
        with pytest.raises(AttributeError):
            i1.task
        assert self.mixin.task.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 = IIinterfaceTest1(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.

        """
        interface = InterfaceTest4()
        self.root.children[0].interface = interface
        res, traceback = interface.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/InterfaceTest3-interface' in traceback

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

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

        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 feavl tagged members works.

        """
        self.mixin.interface = IIinterfaceTest2(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

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

        """
        self.mixin.interface = IIinterfaceTest2(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_perform1(self):
        """Test perform does call interface if present.

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

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

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

        """
        self.mixin = InterfaceTest4()
        self.root.children[0].interface = 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 interface with no interface from a
        config.

        """
        aux = RootTask()
        mixin = Mixin()
        mixin.interface = InterfaceTest3()
        aux.add_child_task(0, mixin)
        deps = {
            'ecpy.task': {
                'tests.Mixin': Mixin,
                'ecpy.RootTask': RootTask
            },
            'ecpy.tasks.interface': {
                'tests.Mixin:tests.InterfaceTest3': InterfaceTest3
            }
        }
        bis = RootTask.build_from_config(aux.preferences, deps)
        assert type(bis.children[0].interface).__name__ == 'InterfaceTest3'

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

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

        interface = bis.children[0].interface.interface
        assert type(interface).__name__ == 'IIinterfaceTest1'
        assert self.root.children[0].database_entries ==\
            {'test': 2.0, 'itest': 1.0}

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

        """
        class Test(InterfaceableInterfaceMixin, IIinterfaceTest2):
            pass

        iaux = IIinterfaceTest1()
        self.mixin.interface = Test()
        self.mixin.interface.interface = iaux

        task = self.root.children[0]
        w = list(task.traverse())
        assert w == [task, self.mixin, self.mixin.interface, iaux]

        w = list(task.traverse(1))
        assert w == [task, self.mixin, self.mixin.interface]
コード例 #50
0
 def setup(self):
     self.root = RootTask()
     self.mixin = Mixin(name='Simple')
     self.root.add_child_task(0, self.mixin)
コード例 #51
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 + ':tests.' +
                                   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,
            {'ecpy.task': {
                'tests.IMixin': IMixin,
                'ecpy.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 = {
            'ecpy.task': {
                'tests.Mixin': Mixin,
                'ecpy.RootTask': RootTask
            },
            'ecpy.tasks.interface': {
                'tests.Mixin:tests.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]
コード例 #52
0
class TestInterfaceableInterfaceMixin(object):
    """Test the capabilities of task interfaces.

    """

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

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

        """
        i1 = IIinterfaceTest1()
        i2 = IIinterfaceTest2()

        self.mixin.interface = i1
        assert i1.parent is self.mixin
        assert i1.task is self.mixin.task
        assert i1.interface_id[1] ==\
            (self.mixin.interface_id[1] + (self.mixin.interface_id[0],))
        assert self.mixin.task.database_entries == {'test': 2.0, 'itest': 1.0}

        self.mixin.interface = i2
        assert i2.task is self.mixin.task
        assert i1.parent is None
        with pytest.raises(AttributeError):
            i1.task
        assert self.mixin.task.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 = IIinterfaceTest1(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.

        """
        interface = InterfaceTest4()
        self.root.children[0].interface = interface
        res, traceback = interface.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/InterfaceTest3-interface' in traceback

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

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

        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 feavl tagged members works.

        """
        self.mixin.interface = IIinterfaceTest2(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

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

        """
        self.mixin.interface = IIinterfaceTest2(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_perform1(self):
        """Test perform does call interface if present.

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

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

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

        """
        self.mixin = InterfaceTest4()
        self.root.children[0].interface = 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 interface with no interface from a
        config.

        """
        aux = RootTask()
        mixin = Mixin()
        mixin.interface = InterfaceTest3()
        aux.add_child_task(0, mixin)
        deps = {'ecpy.task': {'tests.Mixin': Mixin, 'ecpy.RootTask': RootTask},
                'ecpy.tasks.interface':
                    {('InterfaceTest3', ('tests.Mixin',)): InterfaceTest3}}
        bis = RootTask.build_from_config(aux.preferences, deps)
        assert type(bis.children[0].interface).__name__ == 'InterfaceTest3'

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

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

        interface = bis.children[0].interface.interface
        assert type(interface).__name__ == 'IIinterfaceTest1'
        assert self.root.children[0].database_entries ==\
            {'test': 2.0, 'itest': 1.0}

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

        """
        class Test(InterfaceableInterfaceMixin, IIinterfaceTest2):
            pass

        iaux = IIinterfaceTest1()
        self.mixin.interface = Test()
        self.mixin.interface.interface = iaux

        task = self.root.children[0]
        w = list(task.traverse())
        assert w == [task, self.mixin, self.mixin.interface, iaux]

        w = list(task.traverse(1))
        assert w == [task, self.mixin, self.mixin.interface]
コード例 #53
0
 def setup(self):
     self.root = RootTask()
     self.mixin = InterfaceTest3()
     self.root.add_child_task(0, Mixin(name='Simple', interface=self.mixin))
コード例 #54
0
 def setup(self):
     self.root = RootTask(should_stop=Event(), should_pause=Event())
     self.task = FormulaTask(name='Test')
     self.root.add_child_task(0, self.task)
コード例 #55
0
 def setup(self):
     self.root = RootTask()
     self.mixin = Mixin(name='Simple')
     self.root.add_child_task(0, self.mixin)
コード例 #56
0
ファイル: test_string_ops.py プロジェクト: PhilipVinc/ecpy
class TestFormatting(object):
    """Test formatting strings and caching in running mode.

    """

    def setup(self):
        self.root = RootTask()
        database = self.root.database
        database.set_value('root', 'val1', 1)
        database.create_node('root', 'node1')
        database.set_value('root/node1', 'val2', 10.0)
        database.add_access_exception('root', 'root/node1', 'val2')

    def test_formatting_editing_mode1(self):
        """Test formatting values with text on both sides of expression.

        """
        test = 'progress is {val1}/{val2}, it is good.'
        formatted = self.root.format_string(test)
        assert formatted == 'progress is 1/10.0, it is good.'
        assert not self.root._format_cache

    def test_formatting_editing_mode2(self):
        """Test formatting values with text only on the left of expression.

        """
        test = 'progress is {val1}/{val2}'
        formatted = self.root.format_string(test)
        assert formatted == 'progress is 1/10.0'
        assert not self.root._format_cache

    def test_formatting_editing_mode3(self):
        """Test formatting values with text only on the right of expression.

        """
        test = '{val1}/{val2}, it is good.'
        formatted = self.root.format_string(test)
        assert formatted == '1/10.0, it is good.'
        assert not self.root._format_cache

    def test_formatting_editing_mode4(self):
        """Test formatting values with no other text.

        """
        test = '{val1}/{val2}'
        formatted = self.root.format_string(test)
        assert formatted == '1/10.0'
        assert not self.root._format_cache

    def test_formatting_editing_mode5(self):
        """Test formatting when there is only text.

        """
        test = 'test'
        formatted = self.root.format_string(test)
        assert formatted == 'test'
        assert not self.root._format_cache

    def test_formatting_running_mode1(self):
        """Test formatting values with text on both sides of expression.

        """
        self.root.database.prepare_to_run()
        test = 'progress is {val1}/{val2}, it is good.'
        formatted = self.root.format_string(test)
        assert formatted == 'progress is 1/10.0, it is good.'
        assert self.root._format_cache
        assert test in self.root._format_cache
        self.root.database.set_value('root', 'val1', 2)
        formatted = self.root.format_string(test)
        assert formatted == 'progress is 2/10.0, it is good.'

    def test_formatting_running_mode2(self):
        """Test formatting values with text only on the left of expression.

        """
        self.root. database.prepare_to_run()
        test = 'progress is {val1}/{val2}'
        formatted = self.root.format_string(test)
        assert formatted == 'progress is 1/10.0'
        assert self.root._format_cache
        assert test in self.root._format_cache
        self.root.database.set_value('root', 'val1', 2)
        formatted = self.root.format_string(test)
        assert formatted == 'progress is 2/10.0'

    def test_formatting_running_mode3(self):
        """Test formatting values with text only on the right of expression.

        """
        self.root.database.prepare_to_run()
        test = '{val1}/{val2}, it is good.'
        formatted = self.root.format_string(test)
        assert formatted == '1/10.0, it is good.'
        assert self.root._format_cache
        assert test in self.root._format_cache
        self.root.database.set_value('root', 'val1', 2)
        formatted = self.root.format_string(test)
        assert formatted == '2/10.0, it is good.'

    def test_formatting_running_mode4(self):
        """Test formatting values with no other text.

        """
        self.root.database.prepare_to_run()
        test = '{val1}/{val2}'
        formatted = self.root.format_string(test)
        assert formatted == '1/10.0'
        assert self.root._format_cache
        assert test in self.root._format_cache
        self.root.database.set_value('root', 'val1', 2)
        formatted = self.root.format_string(test)
        assert formatted == '2/10.0'

    def test_formatting_running_mode5(self):
        """Test formatting when there is only text.

        """
        self.root.database.prepare_to_run()
        test = 'test'
        formatted = self.root.format_string(test)
        assert formatted == 'test'
        assert self.root._format_cache
        assert test in self.root._format_cache
コード例 #57
0
ファイル: test_string_ops.py プロジェクト: PhilipVinc/ecpy
class TestEvaluation(object):
    """Test evaluating strings and caching in running mode.

    """

    def setup(self):
        self.root = RootTask()
        database = self.root.database
        database.set_value('root', 'val1', 1)
        database.create_node('root', 'node1')
        database.set_value('root/node1', 'val2', 10.0)
        database.add_access_exception('root', 'root/node1', 'val2')

    def test_eval_pure_string_editing_mode(self):
        """Test evaluating a word.

        """
        test = 'test'
        formatted = self.root.format_and_eval_string(test)
        assert formatted == 'test'

    def test_eval_editing_mode1(self):
        """Test eval expression with only standard operators.

        """
        test = '{val1}/{val2}'
        formatted = self.root.format_and_eval_string(test)
        assert formatted == 0.1
        assert not self.root._eval_cache

    def test_eval_editing_mode2(self):
        """Test eval expression containing a math function.

        """
        test = 'cos({val1}/{val2})'
        formatted = self.root.format_and_eval_string(test)
        assert formatted == cos(0.1)
        assert not self.root._eval_cache

    def test_eval_editing_mode3(self):
        """Test eval expression containing a cmath function.

        """
        self.root.database.set_value('root', 'val1', 10.0)
        test = 'cm.sqrt({val1}/{val2})'
        formatted = self.root.format_and_eval_string(test)
        assert formatted == 1+0j
        assert not self.root._eval_cache

    def test_eval_editing_mode4(self):
        """Test eval expression containing a numpy function.

        """
        self.root.database.set_value('root', 'val1', [1.0, -1.0])
        test = 'np.abs({val1})'
        formatted = self.root.format_and_eval_string(test)
        assert_array_equal(formatted, numpy.array((1.0, 1.0)))
        assert not self.root._eval_cache

    def test_eval_pure_string_running_mode(self):
        """Test evaluating a word.

        """
        self.root.database.prepare_to_run()
        test = 'test'
        formatted = self.root.format_and_eval_string(test)
        assert formatted == 'test'

    def test_eval_running_mode1(self):
        """Test eval expression with only standard operators.

        """
        self.root.database.prepare_to_run()
        test = '{val1}/{val2}'
        formatted = self.root.format_and_eval_string(test)
        assert formatted == 0.1
        assert self.root._eval_cache
        assert test in self.root._eval_cache
        self.root.database.set_value('root', 'val1', 2)
        formatted = self.root.format_and_eval_string(test)
        assert formatted == 0.2

    def test_eval_running_mode2(self):
        """Test eval expression containing a math function.

        """
        self.root.database.prepare_to_run()
        test = 'cos({val1}/{val2})'
        formatted = self.root.format_and_eval_string(test)
        assert formatted == cos(0.1)
        assert self.root._eval_cache
        assert test in self.root._eval_cache
        self.root.database.set_value('root', 'val1', 2)
        formatted = self.root.format_and_eval_string(test)
        assert formatted == cos(0.2)

    def test_eval_running_mode3(self):
        """Test eval expression containing a cmath function.

        """
        self.root.database.prepare_to_run()
        self.root.database.set_value('root', 'val1', 10.0)
        test = 'cm.sqrt({val1}/{val2})'
        formatted = self.root.format_and_eval_string(test)
        assert formatted == (1+0j)
        assert self.root._eval_cache
        assert test in self.root._eval_cache
        self.root.database.set_value('root', 'val1', 40.0)
        formatted = self.root.format_and_eval_string(test)
        assert formatted == (2+0j)

    def test_eval_running_mode4(self):
        """Test eval expression containing a numpy function.

        """
        self.root.database.prepare_to_run()
        self.root.database.set_value('root', 'val1', [1.0, -1.0])
        test = 'np.abs({val1})'
        formatted = self.root.format_and_eval_string(test)
        assert_array_equal(formatted, numpy.array((1.0, 1.0)))
        assert self.root._eval_cache
        assert test in self.root._eval_cache
        self.root.database.set_value('root', 'val1', [2.0, -1.0])
        self.root.database.set_value('root', 'val2', 0)
        test = 'np.abs({val1})[{val2}]'
        formatted = self.root.format_and_eval_string(test)
        assert formatted == 2.0