def exec_infos(measure_workbench, measure, tmpdir, process_engine, sync_server): tp = measure_workbench.get_plugin('ecpy.tasks') tp._tasks.contributions['tests.WaitingTask'] = TaskInfos(cls=WaitingTask) r = RootTask(default_path=text(tmpdir)) r.add_child_task(0, WaitingTask(name='test1', sock_id='test1', sync_port=sync_server.port)) r.add_child_task(1, WaitingTask(name='test2', sock_id='test2', sync_port=sync_server.port)) measure.root_task = r deps = measure.dependencies res, msg, errors = deps.collect_runtimes() assert res return ExecutionInfos( id='test', task=r, build_deps=deps.get_build_dependencies().dependencies, runtime_deps=deps.get_runtime_dependencies('main'), observed_entries=['test'], checks=not measure.forced_enqueued, )
def test_stopping_processing_in_hook(processor, measure_with_tools): """Test stopping processing while running a hook. """ plugin = processor.plugin.workbench.get_plugin('ecpy.measure') measure2 = Measure(plugin=plugin, root_task=RootTask(), name='Dummy', id='002') processor.plugin.enqueued_measures.add(measure2) measure = measure_with_tools processor.start_measure(measure) process_and_assert(getattr, (processor, 'active')) pre_hook = measure.pre_hooks['dummy'] process_and_assert(pre_hook.waiting.wait, (5, )) process_app_events() processor.stop_processing(no_post_exec=True) pre_hook.go_on.set() def wait(timeout): processor._thread.join(timeout) return not processor._thread.is_alive() wait_and_process(wait) assert measure.status == 'INTERRUPTED' m = processor.plugin.workbench.get_manifest('test.measure') assert not m.find('runtime_dummy1').collected assert not m.find('runtime_dummy2').collected assert measure2.status == 'READY'
def root_view(task_workbench): """Initialize a root view. """ c = task_workbench.get_plugin('enaml.workbench.core') task = RootTask() view = RootTaskView(task=task, core=c) w = ContainerTestingWindow(workbench=task_workbench) view.set_parent(w) return view
def task(): r = RootTask() r.add_child_task(0, SimpleTask(name='simp1', database_entries={'t': 1})) c = ComplexTask(name='comp1', database_entries={'t1': 2, 't2': 'r'}) c.add_child_task(0, SimpleTask(name='simp2', database_entries={'t': 1})) c2 = ComplexTask(name='comp2', database_entries={'t1': 2, 't2': 'r'}) c2.add_child_task(0, SimpleTask(name='simp3', database_entries={'t': 1})) c.add_child_task(1, c2) r.add_child_task(1, c) return r
def instr_view(instr_task_workbench): """Initialize a instr view. """ c = instr_task_workbench.get_plugin('enaml.workbench.core') task = RootTask() view = RootTaskView(task=task, core=c) i_view = InstrTaskView(task=InterInstrTask(root=task), root=view) i_view.set_parent(view) return i_view
def measure(measure_workbench): """Register the dummy testing tools and create an empty measure. """ try: measure_workbench.register(MeasureTestManifest()) except ValueError: pass plugin = measure_workbench.get_plugin('ecpy.measure') measure = Measure(plugin=plugin, root_task=RootTask(), name='Dummy', id='001') return measure
def test_editor_changing_root(task): """Setting a new root. """ ed = EditorModel(root=RootTask()) assert len(ed.nodes) == 1 ed.root = task assert len(ed.nodes) == 3 assert ('root' in ed.nodes and 'root/comp1' in ed.nodes and 'root/comp1/comp2' in ed.nodes) assert ed.nodes['root/comp1'] in ed.nodes['root'].children assert ed.nodes['root/comp1/comp2'] in ed.nodes['root/comp1'].children
def test_running_full_measure(app, processor, measure_with_tools, windows, dialog_sleep, tmpdir): """Test running a complete measure with pre/post-hooks and monitor. """ plugin = processor.plugin.workbench.get_plugin('ecpy.measure') measure2 = Measure(plugin=plugin, root_task=RootTask(), name='Dummy', id='002') processor.plugin.enqueued_measures.add(measure2) measure = measure_with_tools processor.continuous_processing = False processor.start_measure(measure) process_and_assert(getattr, (processor, 'active')) pre_hook = measure.pre_hooks['dummy'] process_and_assert(pre_hook.waiting.wait, (5, )) assert measure is processor.running_measure assert measure.status == 'RUNNING' assert tmpdir.listdir() pre_hook.go_on.set() wait_and_process(processor.engine.waiting.wait) assert processor.monitors_window assert processor.monitors_window.measure is measure assert measure.monitors['dummy'].running sleep(dialog_sleep) processor.engine.go_on.set() post_hook = measure.post_hooks['dummy'] wait_and_process(post_hook.waiting.wait) assert measure.task_execution_result assert not measure.monitors['dummy'].running assert measure.monitors['dummy'].received_news post_hook.go_on.set() process_and_join_thread(processor._thread) assert measure.status == 'COMPLETED' m = processor.plugin.workbench.get_manifest('test.measure') assert not m.find('runtime_dummy1').collected assert not m.find('runtime_dummy2').collected assert measure2.status == 'READY'
def task(): """Create a task to test the validators. """ class Tester(CheckTask): """Class for testing feval validators. """ feval = Unicode() root = RootTask(should_stop=Event(), should_pause=Event()) task = Tester(name='test', database_entries={'val': 1}) loop = LoopTask(name='Loop', task=task) root.add_child_task(0, loop) return task
def task(sequence, tmpdir): """Transfer sequence task for testing. """ root = RootTask() root.run_time = {d_id: {'d': (object, FalseStarter())}, p_id: {'p': {'connections': {'c': {}, 'c2': {}}, 'settings': {'s': {}}}}} path = os.path.join(str(tmpdir), 'test.pulse.ini') save_sequence_prefs(path, sequence.preferences_from_members()) task = TransferPulseSequenceTask(sequence=sequence, sequence_path=path, sequence_timestamp=os.path.getmtime(path), sequence_vars=OrderedDict({'a': '1.5'}), name='Test', selected_instrument=('p', 'd', 'c', 's')) root.add_child_task(0, task) return task
def test_linspace_handling_of_rounding(monkeypatch, linspace_interface): """Test that we properly round the values. """ monkeypatch.setattr(LoopTask, 'perform_loop', false_perform_loop) root = RootTask(should_stop=Event(), should_pause=Event()) lt = LoopTask(name='Test') root.add_child_task(0, lt) # Step use more digit lt.interface = linspace_interface linspace_interface.start = '0.1' linspace_interface.stop = '0.11' linspace_interface.step = '0.001' linspace_interface.perform() expected = np.array([ 0.1, 0.101, 0.102, 0.103, 0.104, 0.105, 0.106, 0.107, 0.108, 0.109, 0.11 ]) # Check that this does indeed cause a rounding issue with pytest.raises(AssertionError): np.testing.assert_array_equal(np.linspace(0.1, 0.11, 11), expected) np.testing.assert_array_equal(lt.database_entries['iterable'], expected) # Start use more digit lt.interface = linspace_interface linspace_interface.start = '1.01' linspace_interface.stop = '2.01' linspace_interface.step = '0.1' linspace_interface.perform() expected = np.array( [1.01, 1.11, 1.21, 1.31, 1.41, 1.51, 1.61, 1.71, 1.81, 1.91, 2.01]) np.testing.assert_array_equal(lt.database_entries['iterable'], expected) # Start use more digit and stop does not round properly lt.interface = linspace_interface linspace_interface.start = '0.501' linspace_interface.stop = '1' linspace_interface.step = '0.2' linspace_interface.perform() expected = np.array([0.501, 0.701, 0.901]) np.testing.assert_array_equal(lt.database_entries['iterable'], expected)
def test_linspace_handling_of_non_matching_stop(monkeypatch, linspace_interface): """Test that we respect the step even if stop does not match. """ monkeypatch.setattr(LoopTask, 'perform_loop', false_perform_loop) root = RootTask(should_stop=Event(), should_pause=Event()) lt = LoopTask(name='Test') root.add_child_task(0, lt) lt.interface = linspace_interface linspace_interface.start = '0.1' linspace_interface.stop = '0.1101' linspace_interface.step = '0.001' linspace_interface.perform() expected = np.array([ 0.1, 0.101, 0.102, 0.103, 0.104, 0.105, 0.106, 0.107, 0.108, 0.109, 0.11 ]) np.testing.assert_array_equal(lt.database_entries['iterable'], expected)
def test_stopping_processing_while_in_pause(processor, measure_with_tools): """Test stopping processing while in pause before starting main. """ plugin = processor.plugin.workbench.get_plugin('ecpy.measure') measure2 = Measure(plugin=plugin, root_task=RootTask(), name='Dummy', id='002') processor.plugin.enqueued_measures.add(measure2) def wait_on_state_paused(timeout): return processor._state.wait(timeout, 'paused') measure = measure_with_tools processor.start_measure(measure) pre_hook = measure.pre_hooks['dummy'] assert pre_hook.waiting.wait(5) process_app_events() processor.pause_measure() pre_hook.accept_pause = False pre_hook.go_on.set() wait_and_process(wait_on_state_paused) processor.stop_processing(no_post_exec=True) sleep(0.2) def wait(timeout): processor._thread.join(timeout) return not processor._thread.is_alive() wait_and_process(wait) assert measure.status == 'INTERRUPTED' m = processor.plugin.workbench.get_manifest('test.measure') assert not m.find('runtime_dummy1').collected assert not m.find('runtime_dummy2').collected assert measure2.status == 'READY'
def test_linspace_handling_of_step_sign(monkeypatch, linspace_interface): """Test that no matter the sign of step we generate the proper array. """ monkeypatch.setattr(LoopTask, 'perform_loop', false_perform_loop) root = RootTask(should_stop=Event(), should_pause=Event()) lt = LoopTask(name='Test') root.add_child_task(0, lt) lt.interface = linspace_interface linspace_interface.step = '-0.1' linspace_interface.perform() expected = np.array( [1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0]) np.testing.assert_array_equal(lt.database_entries['iterable'], expected) linspace_interface.start = '3.0' linspace_interface.perform() expected = np.array( [3.0, 2.9, 2.8, 2.7, 2.6, 2.5, 2.4, 2.3, 2.2, 2.1, 2.0]) np.testing.assert_array_equal(lt.database_entries['iterable'], expected)
def task(): """Create a basic task hierarchy for testing. """ root = RootTask() root.add_child_task(0, SimpleTask(name='simp1')) comp = ComplexTask(name='comp1', wait={ 'activated': True, 'no_wait': ['test'] }) comp.add_child_task( 0, SimpleTask(name='simp2', parallel={ 'activated': True, 'pool': 'test' })) root.add_child_task(1, comp) return root
def task(): root = RootTask() root.add_child_task(0, ComplexTask(name='Dummy')) return root
def setup(self): self.root = RootTask(should_stop=Event(), should_pause=Event()) self.task = SleepTask(name='Test') self.root.add_child_task(0, self.task)
def setup(self): self.root = RootTask(should_stop=Event(), should_pause=Event()) self.task = WhileTask(name='Test') self.root.add_child_task(0, self.task) self.check = CheckTask(name='check') self.task.add_child_task(0, self.check)
def setup(self): self.root = RootTask(should_stop=Event(), should_pause=Event())