当前位置: 首页>>代码示例>>Python>>正文


Python RootTask.update_preferences_from_members方法代码示例

本文整理汇总了Python中ecpy.tasks.base_tasks.RootTask.update_preferences_from_members方法的典型用法代码示例。如果您正苦于以下问题:Python RootTask.update_preferences_from_members方法的具体用法?Python RootTask.update_preferences_from_members怎么用?Python RootTask.update_preferences_from_members使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ecpy.tasks.base_tasks.RootTask的用法示例。


在下文中一共展示了RootTask.update_preferences_from_members方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_update_preferences_from_members

# 需要导入模块: from ecpy.tasks.base_tasks import RootTask [as 别名]
# 或者: from ecpy.tasks.base_tasks.RootTask import update_preferences_from_members [as 别名]
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'
开发者ID:pombredanne,项目名称:ecpy,代码行数:21,代码来源:test_base_tasks.py

示例2: TestInterfaceableInterfaceMixin

# 需要导入模块: from ecpy.tasks.base_tasks import RootTask [as 别名]
# 或者: from ecpy.tasks.base_tasks.RootTask import update_preferences_from_members [as 别名]

#.........这里部分代码省略.........

        """
        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]
开发者ID:MatthieuDartiailh,项目名称:ecpy,代码行数:104,代码来源:test_task_interfaces.py

示例3: TestInterfaceableTaskMixin

# 需要导入模块: from ecpy.tasks.base_tasks import RootTask [as 别名]
# 或者: from ecpy.tasks.base_tasks.RootTask import update_preferences_from_members [as 别名]

#.........这里部分代码省略.........
        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]
开发者ID:MatthieuDartiailh,项目名称:ecpy,代码行数:104,代码来源:test_task_interfaces.py

示例4: TestLoopTask

# 需要导入模块: from ecpy.tasks.base_tasks import RootTask [as 别名]
# 或者: from ecpy.tasks.base_tasks.RootTask import update_preferences_from_members [as 别名]
class TestLoopTask(object):
    """Test Loop task with and without included child.

    """

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

    def test_subtask_handling(self):
        """Test adding, changing, removing the subtask.

        """
        subtask1 = CheckTask(name='check', database_entries={'val': 1})
        self.task.task = subtask1

        assert subtask1.root is self.root
        assert subtask1.database is self.root.database
        assert subtask1.parent is self.task
        assert subtask1.path and subtask1.depth
        assert 'value' not in self.task.database_entries
        assert subtask1.get_from_database('check_val')
        assert self.task.preferences['task']['name'] == 'check'

        subtask2 = CheckTask(name='rep', database_entries={'new': 1})
        self.task.task = subtask2

        assert not subtask1.root
        assert not subtask1.parent
        with pytest.raises(KeyError):
            assert subtask1.get_from_database('check_val')

        assert subtask2.root is self.root
        assert subtask2.database is self.root.database
        assert subtask2.parent is self.task
        assert subtask2.path and subtask1.depth
        assert 'value' not in self.task.database_entries
        assert subtask2.get_from_database('rep_new')
        assert self.task.preferences['task']['name'] == 'rep'

        self.task.task = None

        assert not subtask2.root
        assert not subtask2.parent
        with pytest.raises(KeyError):
            assert subtask2.get_from_database('rep_new')
        assert 'value' in self.task.database_entries

    def test_traverse(self, linspace_interface):
        """Test traversing a with interfaces ComplexTask.

        """
        self.task.interface = linspace_interface
        self.task.add_child_task(0, CheckTask(name='check'))
        assert len(list(self.task.traverse())) == 3

    def test_saving_building_from_config(self):
        """Done here as the LoopTask is a viable case of a member tagged with
        child.

        """
        subtask1 = CheckTask(name='check', database_entries={'val': 1})
        self.task.task = subtask1

        self.root.update_preferences_from_members()

        new = RootTask.build_from_config(self.root.preferences,
                                         {'ecpy.task': {'RootTask': RootTask,
                                                        'LoopTask': LoopTask,
                                                        'CheckTask': CheckTask}
                                          })

        assert new.children[0].task.name == 'check'

        self.root.update_preferences_from_members()
        prefs = self.root.preferences
        del prefs['children_0']['task']
        new = RootTask.build_from_config(prefs,
                                         {'ecpy.task': {'RootTask': RootTask,
                                                        'LoopTask': LoopTask,
                                                        'CheckTask': CheckTask}
                                          })

        assert not new.children[0].task

    def test_timing_handling(self):
        """Test enabling/disabling the timing.

        """
        assert 'elapsed_time' not in self.task.database_entries

        self.task.timing = True

        assert 'elapsed_time' in self.task.database_entries

        self.task.timing = False

        assert 'elapsed_time' not in self.task.database_entries

#.........这里部分代码省略.........
开发者ID:pombredanne,项目名称:ecpy,代码行数:103,代码来源:test_loop_task.py


注:本文中的ecpy.tasks.base_tasks.RootTask.update_preferences_from_members方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。