本文整理匯總了Python中ecpy.tasks.base_tasks.RootTask.get_from_database方法的典型用法代碼示例。如果您正苦於以下問題:Python RootTask.get_from_database方法的具體用法?Python RootTask.get_from_database怎麽用?Python RootTask.get_from_database使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ecpy.tasks.base_tasks.RootTask
的用法示例。
在下文中一共展示了RootTask.get_from_database方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_deleting_child
# 需要導入模塊: from ecpy.tasks.base_tasks import RootTask [as 別名]
# 或者: from ecpy.tasks.base_tasks.RootTask import get_from_database [as 別名]
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')
示例2: test_database_operation
# 需要導入模塊: from ecpy.tasks.base_tasks import RootTask [as 別名]
# 或者: from ecpy.tasks.base_tasks.RootTask import get_from_database [as 別名]
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')
示例3: test_database_update
# 需要導入模塊: from ecpy.tasks.base_tasks import RootTask [as 別名]
# 或者: from ecpy.tasks.base_tasks.RootTask import get_from_database [as 別名]
def test_database_update():
"""Test that replacing the database_entries members refreshes the database.
"""
root = RootTask()
entries = root.database_entries.copy()
del entries['meas_name']
entries['name'] = 'Test'
root.database_entries = entries
assert root.get_from_database('name') == 'Test'
with pytest.raises(KeyError):
root.get_from_database('meas_name')
示例4: test_root_registering
# 需要導入模塊: from ecpy.tasks.base_tasks import RootTask [as 別名]
# 或者: from ecpy.tasks.base_tasks.RootTask import get_from_database [as 別名]
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
示例5: test_task_renaming
# 需要導入模塊: from ecpy.tasks.base_tasks import RootTask [as 別名]
# 或者: from ecpy.tasks.base_tasks.RootTask import get_from_database [as 別名]
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
示例6: test_adding_child
# 需要導入模塊: from ecpy.tasks.base_tasks import RootTask [as 別名]
# 或者: from ecpy.tasks.base_tasks.RootTask import get_from_database [as 別名]
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])
示例7: TestInterfaceableInterfaceMixin
# 需要導入模塊: from ecpy.tasks.base_tasks import RootTask [as 別名]
# 或者: from ecpy.tasks.base_tasks.RootTask import get_from_database [as 別名]
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
#.........這裏部分代碼省略.........
示例8: TestInterfaceableTaskMixin
# 需要導入模塊: from ecpy.tasks.base_tasks import RootTask [as 別名]
# 或者: from ecpy.tasks.base_tasks.RootTask import get_from_database [as 別名]
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.
#.........這裏部分代碼省略.........
示例9: TestLoopTask
# 需要導入模塊: from ecpy.tasks.base_tasks import RootTask [as 別名]
# 或者: from ecpy.tasks.base_tasks.RootTask import get_from_database [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
#.........這裏部分代碼省略.........