def test_flying_outside_a_run_is_illegal(RE, hw): flyer = hw.trivial_flyer # This is normal, legal usage. RE([ Msg('open_run'), Msg('kickoff', flyer, group='foo'), Msg('wait', group='foo'), Msg('complete', flyer, group='bar'), Msg('wait', group='bar'), Msg('collect', flyer), Msg('close_run') ]) # This is normal, legal usage (partial collection). RE([ Msg('open_run'), Msg('kickoff', flyer, group='foo'), Msg('wait', group='foo'), Msg('collect', flyer), Msg('collect', flyer), Msg('collect', flyer), Msg('complete', flyer, group='bar'), Msg('wait', group='bar'), Msg('collect', flyer), Msg('collect', flyer), Msg('collect', flyer), Msg('close_run') ]) # It is not legal to kickoff outside of a run. with pytest.raises(IllegalMessageSequence): RE([Msg('kickoff', flyer)])
def evil_plan(): assert RE.rewindable is False yield Msg('aardvark')
monitor_during_wrapper, lazily_stage_wrapper, relative_set_wrapper, subs_wrapper, suspend_wrapper, fly_during_decorator, subs_decorator, monitor_during_decorator, inject_md_wrapper, finalize_decorator, configure_count_time_wrapper) from bluesky.plans import count, scan, rel_scan, inner_product_scan import bluesky.plans as bp from bluesky.utils import all_safe_rewind import threading @pytest.mark.parametrize('plan,plan_args,plan_kwargs,msgs', [ (create, (), {}, [Msg('create', name='primary')]), (create, ('custom_name', ), {}, [Msg('create', name='custom_name')]), (save, (), {}, [Msg('save')]), (drop, (), {}, [Msg('drop')]), (read, ('det', ), {}, [Msg('read', 'det')]), (monitor, ('foo', ), {}, [Msg('monitor', 'foo', name=None)]), (monitor, ('foo', ), { 'name': 'c' }, [Msg('monitor', 'foo', name='c')]), (unmonitor, ('foo', ), {}, [Msg('unmonitor', 'foo')]), (null, (), {}, [Msg('null')]), (stop, ('foo', ), {}, [Msg('stop', 'foo')]), (abs_set, ('det', 5), {}, [Msg('set', 'det', 5, group=None)]), (abs_set, ('det', 5), { 'group': 'A' }, [Msg('set', 'det', 5, group='A')]),
def pre_suspend_plan(): yield Msg('set', motor, 5) raise GeneratorExit('this one')
def pre_plan(): yield Msg('null') raise RuntimeError()
def bad_msg(motor): for j in range(15): yield Msg('set', motor, j) yield Msg('aardvark')
def base_plan(motor): for j in range(5): yield Msg('set', motor, j * 2 + 1) yield Msg('pause')
def test_opening_a_bundle_without_a_run_is_illegal(fresh_RE): with pytest.raises(IllegalMessageSequence): fresh_RE([Msg('create')])
def test_checkpoint_inside_a_bundle_is_illegal(fresh_RE): with pytest.raises(IllegalMessageSequence): fresh_RE([Msg('open_run'), Msg('create'), Msg('checkpoint')])
def test_open_run_twice_is_illegal(fresh_RE): with pytest.raises(IllegalMessageSequence): fresh_RE([Msg('open_run'), Msg('open_run')])
def test_saving_without_an_open_bundle_is_illegal(fresh_RE): with pytest.raises(IllegalMessageSequence): fresh_RE([Msg('open_run'), Msg('save')])
def custom_cleanup(plan): yield from plan yield Msg('null', 'cleanup') # just a sentinel
def accum(msg): msg_lst.append(msg) susp = SuspendBoolHigh(sig) RE.install_suspender(susp) RE._loop.call_later(1, sig.put, 0) RE.msg_hook = accum RE(scan) assert len(msg_lst) == 2 assert ['wait_for', 'checkpoint'] == [m[0] for m in msg_lst] @pytest.mark.parametrize('pre_plan,post_plan,expected_list', [([Msg('null')], None, [ 'checkpoint', 'sleep', 'rewindable', 'null', 'wait_for', 'rewindable', 'sleep' ]), (None, [Msg('null')], [ 'checkpoint', 'sleep', 'rewindable', 'wait_for', 'null', 'rewindable', 'sleep' ]), ([Msg('null')], [Msg('null')], [ 'checkpoint', 'sleep', 'rewindable', 'null', 'wait_for', 'null', 'rewindable', 'sleep' ]), (lambda: [Msg('null')], lambda: [Msg('null')], [ 'checkpoint', 'sleep', 'rewindable', 'null', 'wait_for', 'null', 'rewindable', 'sleep' ])])
def test_reset(RE): with pytest.raises(RunEngineInterrupted): RE([Msg('open_run'), Msg('pause')]) assert RE._run_start_uid is not None RE.reset() assert RE._run_start_uid is None
def pausing_raiser(motor): for j in range(15): yield Msg('set', motor, j) yield Msg('pause') raise RuntimeError()
def test_reset(fresh_RE): fresh_RE([Msg('open_run'), Msg('pause')]) assert fresh_RE._run_start_uid is not None fresh_RE.reset() assert fresh_RE._run_start_uid is None
def bad_set(motor): for j in range(15): yield Msg('set', motor, j) yield Msg('set', None, j)
def test_plan(motor, det): yield Msg('set', motor, 0) yield Msg('trigger', det) yield Msg('pause') yield Msg('set', motor, 1) yield Msg('trigger', det)
def cannot_pauser(motor): yield Msg('clear_checkpoint') for j in range(15): yield Msg('set', motor, j) yield Msg('pause')
def test_plan(motor, det): yield Msg('set', motor, 0) yield Msg('trigger', det) yield Msg('sleep', None, 1) yield Msg('set', motor, 0) yield Msg('trigger', det)
def post_plan(motor): yield Msg('set', motor, 5)
def simple_plan(motor): for j in range(15): yield Msg('set', motor, j) yield Msg('pause') for j in range(15): yield Msg('set', motor, -j)
def pre_plan(): yield Msg('aardvark')
def hanging_plan(): "a plan that blocks the RunEngine's normal Ctrl+C handing with a sleep" ttime.sleep(10) yield Msg('null')
def post_plan(): for j in range(5): yield Msg('null')
def infinite_plan(): while True: yield Msg('null')
def plan(): yield Msg('custom-command')
def raiser(motor): for j in range(15): yield Msg('set', motor, j) raise RuntimeError()
def plan(): yield from [Msg('read', det1), Msg('read', det1), Msg('read', det2)]
def test_dropping_without_an_open_bundle_is_illegal(RE): with pytest.raises(IllegalMessageSequence): RE([Msg('open_run'), Msg('drop')])