Ejemplo n.º 1
0
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)])
Ejemplo n.º 2
0
 def evil_plan():
     assert RE.rewindable is False
     yield Msg('aardvark')
Ejemplo n.º 3
0
    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')]),
Ejemplo n.º 4
0
 def pre_suspend_plan():
     yield Msg('set', motor, 5)
     raise GeneratorExit('this one')
Ejemplo n.º 5
0
 def pre_plan():
     yield Msg('null')
     raise RuntimeError()
Ejemplo n.º 6
0
 def bad_msg(motor):
     for j in range(15):
         yield Msg('set', motor, j)
     yield Msg('aardvark')
Ejemplo n.º 7
0
 def base_plan(motor):
     for j in range(5):
         yield Msg('set', motor, j * 2 + 1)
     yield Msg('pause')
Ejemplo n.º 8
0
def test_opening_a_bundle_without_a_run_is_illegal(fresh_RE):
    with pytest.raises(IllegalMessageSequence):
        fresh_RE([Msg('create')])
Ejemplo n.º 9
0
def test_checkpoint_inside_a_bundle_is_illegal(fresh_RE):
    with pytest.raises(IllegalMessageSequence):
        fresh_RE([Msg('open_run'), Msg('create'), Msg('checkpoint')])
Ejemplo n.º 10
0
def test_open_run_twice_is_illegal(fresh_RE):
    with pytest.raises(IllegalMessageSequence):
        fresh_RE([Msg('open_run'), Msg('open_run')])
Ejemplo n.º 11
0
def test_saving_without_an_open_bundle_is_illegal(fresh_RE):
    with pytest.raises(IllegalMessageSequence):
        fresh_RE([Msg('open_run'), Msg('save')])
Ejemplo n.º 12
0
 def custom_cleanup(plan):
     yield from plan
     yield Msg('null', 'cleanup')  # just a sentinel
Ejemplo n.º 13
0
    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'
                          ])])
Ejemplo n.º 14
0
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
Ejemplo n.º 15
0
 def pausing_raiser(motor):
     for j in range(15):
         yield Msg('set', motor, j)
     yield Msg('pause')
     raise RuntimeError()
Ejemplo n.º 16
0
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
Ejemplo n.º 17
0
 def bad_set(motor):
     for j in range(15):
         yield Msg('set', motor, j)
         yield Msg('set', None, j)
Ejemplo n.º 18
0
 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)
Ejemplo n.º 19
0
 def cannot_pauser(motor):
     yield Msg('clear_checkpoint')
     for j in range(15):
         yield Msg('set', motor, j)
     yield Msg('pause')
Ejemplo n.º 20
0
 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)
Ejemplo n.º 21
0
 def post_plan(motor):
     yield Msg('set', motor, 5)
Ejemplo n.º 22
0
 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)
Ejemplo n.º 23
0
 def pre_plan():
     yield Msg('aardvark')
Ejemplo n.º 24
0
 def hanging_plan():
     "a plan that blocks the RunEngine's normal Ctrl+C handing with a sleep"
     ttime.sleep(10)
     yield Msg('null')
Ejemplo n.º 25
0
 def post_plan():
     for j in range(5):
         yield Msg('null')
Ejemplo n.º 26
0
 def infinite_plan():
     while True:
         yield Msg('null')
Ejemplo n.º 27
0
 def plan():
     yield Msg('custom-command')
Ejemplo n.º 28
0
 def raiser(motor):
     for j in range(15):
         yield Msg('set', motor, j)
     raise RuntimeError()
Ejemplo n.º 29
0
 def plan():
     yield from [Msg('read', det1), Msg('read', det1), Msg('read', det2)]
Ejemplo n.º 30
0
def test_dropping_without_an_open_bundle_is_illegal(RE):
    with pytest.raises(IllegalMessageSequence):
        RE([Msg('open_run'), Msg('drop')])