Beispiel #1
0
def test_all(RE, hw):
    c = CallbackCounter()
    RE(stepscan(hw.det, hw.motor), {'all': c})
    assert c.value == 10 + 1 + 2  # events, descriptor, start and stop

    c = CallbackCounter()
    token = RE.subscribe(c)
    RE(stepscan(hw.det, hw.motor))
    RE.unsubscribe(token)
    assert c.value == 10 + 1 + 2
Beispiel #2
0
def test_all():
    c = CallbackCounter()
    RE(stepscan(det, motor), subs={'all': c})
    assert c.value == 10 + 1 + 2  # events, descriptor, start and stop

    c = CallbackCounter()
    token = RE.subscribe('all', c)
    RE(stepscan(det, motor))
    RE.unsubscribe(token)
    assert c.value == 10 + 1 + 2
Beispiel #3
0
def test_all():
    c = CallbackCounter()
    RE(stepscan(det, motor), subs={'all': c})
    assert c.value == 10 + 1 + 2  # events, descriptor, start and stop

    c = CallbackCounter()
    token = RE.subscribe('all', c)
    RE(stepscan(det, motor))
    RE.unsubscribe(token)
    assert c.value == 10 + 1 + 2
Beispiel #4
0
def test_all(RE, hw):
    c = CallbackCounter()
    RE(stepscan(hw.det, hw.motor), {"all": c})
    assert c.value == 10 + 1 + 2  # events, descriptor, start and stop

    c = CallbackCounter()
    token = RE.subscribe(c)
    RE(stepscan(hw.det, hw.motor))
    RE.unsubscribe(token)
    assert c.value == 10 + 1 + 2
Beispiel #5
0
def test_raising_ignored_or_not(RE, hw):
    RE.ignore_callback_exceptions = True
    assert RE.ignore_callback_exceptions

    def cb(name, doc):
        raise Exception

    # by default (with ignore... = True) it warns
    with pytest.warns(UserWarning):
        RE(stepscan(hw.det, hw.motor), cb)

    RE.ignore_callback_exceptions = False
    with pytest.raises(Exception):
        RE(stepscan(hw.det, hw.motor), cb)
Beispiel #6
0
def test_raising_ignored_or_not(RE, hw):
    RE.ignore_callback_exceptions = True
    assert RE.ignore_callback_exceptions

    def cb(name, doc):
        raise Exception

    # by default (with ignore... = True) it warns
    with pytest.warns(UserWarning):
        RE(stepscan(hw.det, hw.motor), cb)

    RE.ignore_callback_exceptions = False
    with pytest.raises(Exception):
        RE(stepscan(hw.det, hw.motor), cb)
Beispiel #7
0
def test_raising_ignored_or_not(fresh_RE):
    RE = fresh_RE
    RE.ignore_callback_exceptions = True
    assert RE.ignore_callback_exceptions

    def cb(name, doc):
        raise Exception
    # by default (with ignore... = True) it warns
    with pytest.warns(UserWarning):
        RE(stepscan(det, motor), subs=cb)

    RE.ignore_callback_exceptions = False
    with pytest.raises(Exception):
        RE(stepscan(det, motor), subs={'all': cb})
def test_scan_and_get_data(RE, hw, db):
    RE.subscribe(db.insert)
    uid, = RE(stepscan(hw.det, hw.motor), group='foo', beamline_id='testing',
              config={})

    hdr = db[uid]
    list(hdr.events())
Beispiel #9
0
def test_live_plotter():
    if skip_mpl:
        raise nose.SkipTest("matplotlib is not available")
    my_plotter = LivePlot('det', 'motor')
    assert_equal(RE.state, 'idle')
    RE(stepscan(det, motor), subs={'all': my_plotter})
    assert_equal(RE.state, 'idle')
Beispiel #10
0
def test_post_run():
    try:
        import dataportal
    except ImportError:
        raise SkipTest('requires dataportal')
    from bluesky.broker_callbacks import post_run
    RE(stepscan(det, motor), subs=post_run(LiveTable()))
Beispiel #11
0
def test_raising_ignored_or_not():
    assert_true(RE.ignore_callback_exceptions)
    def cb(name, doc):
        raise Exception
    RE(stepscan(det, motor), subs=cb)
    RE.ignore_callback_exceptions = False
    _raising_callbacks_helper('all', cb)
Beispiel #12
0
def test_average_stream(RE, hw):
    # Create callback chain
    avg = AverageStream(10)
    c = CallbackCounter()
    d = DocCollector()
    avg.subscribe(c)
    avg.subscribe(d.insert)
    # Run a basic plan
    RE(stepscan(hw.det, hw.motor), {'all': avg})
    assert c.value == 1 + 1 + 2  # events, descriptor, start and stop
    # See that we made sensible descriptor
    start_uid = d.start[0]['uid']
    assert start_uid in d.descriptor
    desc_uid = d.descriptor[start_uid][0]['uid']
    assert desc_uid in d.event
    evt = d.event[desc_uid][0]
    assert evt['seq_num'] == 1
    assert all([
        key in d.descriptor[start_uid][0]['data_keys']
        for key in evt['data'].keys()
    ])
    # See that we returned the correct average
    assert evt['data']['motor'] == -0.5  # mean of range(-5, 5)
    assert evt['data']['motor_setpoint'] == -0.5  # mean of range(-5, 5)
    assert start_uid in d.stop
    assert d.stop[start_uid]['num_events'] == {'primary': 1}
Beispiel #13
0
def test_live_plotter():
    if skip_mpl:
        raise nose.SkipTest("matplotlib is not available")
    my_plotter = LivePlot('det', 'motor')
    assert_equal(RE.state, 'idle')
    RE(stepscan(det, motor), subs={'all': my_plotter})
    assert_equal(RE.state, 'idle')
Beispiel #14
0
def test_main_thread_callback_exceptions():

    RE(stepscan(det, motor), subs={'start': exception_raiser,
                                   'stop': exception_raiser,
                                   'event': exception_raiser,
                                   'descriptor': exception_raiser,
                                   'all': exception_raiser},
       beamline_id='testing', owner='tester')
def test_scan_and_get_data(fresh_RE, db):
    RE = fresh_RE
    RE.subscribe('all', db.mds.insert)
    uid, = RE(stepscan(det, motor), group='foo', beamline_id='testing',
              config={})

    hdr = db[uid]
    db.fetch_events(hdr)
Beispiel #16
0
def test_scan_and_get_data(RE, hw, db):
    RE.subscribe(db.insert)
    uid, = RE(stepscan(hw.det, hw.motor),
              group='foo',
              beamline_id='testing',
              config={})

    hdr = db[uid]
    list(hdr.events())
Beispiel #17
0
def test_raising_ignored_or_not():
    assert_true(RE.ignore_callback_exceptions)

    def cb(name, doc):
        raise Exception

    RE(stepscan(det, motor), subs=cb)
    RE.ignore_callback_exceptions = False
    _raising_callbacks_helper('all', cb)
def test_scan_and_get_data(fresh_RE, db):
    RE = fresh_RE
    RE.subscribe('all', db.mds.insert)
    uid, = RE(stepscan(det, motor),
              group='foo',
              beamline_id='testing',
              config={})

    hdr = db[uid]
    db.fetch_events(hdr)
Beispiel #19
0
def test_main_thread_callback_exceptions():

    RE(stepscan(det, motor),
       subs={
           'start': exception_raiser,
           'stop': exception_raiser,
           'event': exception_raiser,
           'descriptor': exception_raiser,
           'all': exception_raiser
       },
       beamline_id='testing',
       owner='tester')
Beispiel #20
0
def test_raising_ignored_or_not():
    RE.ignore_callback_exceptions = True
    assert RE.ignore_callback_exceptions

    def cb(name, doc):
        raise Exception
    # by default (with ignore... = True) it warns
    with pytest.warns(UserWarning):
        RE(stepscan(det, motor), subs=cb)

    RE.ignore_callback_exceptions = False
    _raising_callbacks_helper('all', cb)
Beispiel #21
0
def test_raising_ignored_or_not():
    RE.ignore_callback_exceptions = True
    assert RE.ignore_callback_exceptions

    def cb(name, doc):
        raise Exception
    # by default (with ignore... = True) it warns
    with pytest.warns(UserWarning):
        RE(stepscan(det, motor), subs=cb)

    RE.ignore_callback_exceptions = False
    _raising_callbacks_helper('all', cb)
def test_scan_and_get_data(RE, hw, db):

    RE.subscribe(db.insert)
    rs = RE(stepscan(hw.det, hw.motor),
            group='foo',
            beamline_id='testing',
            config={})
    if RE.call_returns_result:
        uid = rs.run_start_uids[0]
    else:
        uid = rs[0]
    hdr = db[uid]
    list(hdr.events())
def test_post_run(RE, hw, db):
    RE.subscribe(db.insert)
    output = defaultdict(list)

    def do_nothing(doctype, doc):
        output[doctype].append(doc)

    RE(stepscan(hw.det, hw.motor), {'stop': [post_run(do_nothing, db=db)]})
    assert len(output)
    assert len(output['start']) == 1
    assert len(output['stop']) == 1
    assert len(output['descriptor']) == 1
    assert len(output['event']) == 10
Beispiel #24
0
def test_post_run(RE, hw, db):
    RE.subscribe(db.insert)
    output = defaultdict(list)

    def do_nothing(doctype, doc):
        output[doctype].append(doc)

    RE(stepscan(hw.det, hw.motor), {'stop': [post_run(do_nothing, db=db)]})
    assert len(output)
    assert len(output['start']) == 1
    assert len(output['stop']) == 1
    assert len(output['descriptor']) == 1
    assert len(output['event']) == 10
Beispiel #25
0
def test_subscribe_msg(RE, hw):
    assert RE.state == 'idle'
    c = CallbackCounter()

    def counting_stepscan(det, motor):
        yield Msg('subscribe', None, c, 'start')
        yield from stepscan(det, motor)

    RE(counting_stepscan(hw.det, hw.motor))  # should advance c
    assert c.value == 1
    RE(counting_stepscan(hw.det, hw.motor))  # should advance c
    assert c.value == 2
    RE(stepscan(hw.det, hw.motor))  # should not
    assert c.value == 2
Beispiel #26
0
def test_subscribe_msg():
    assert RE.state == 'idle'
    c = CallbackCounter()

    def counting_stepscan(det, motor):
        yield Msg('subscribe', None, 'start', c)
        yield from stepscan(det, motor)

    RE(counting_stepscan(det, motor))  # should advance c
    assert c.value == 1
    RE(counting_stepscan(det, motor))  # should advance c
    assert c.value == 2
    RE(stepscan(det, motor))  # should not
    assert c.value == 2
Beispiel #27
0
def test_subscribe_msg():
    assert RE.state == 'idle'
    c = CallbackCounter()

    def counting_stepscan(det, motor):
        yield Msg('subscribe', None, 'start', c)
        yield from stepscan(det, motor)

    RE(counting_stepscan(det, motor))  # should advance c
    assert_equal(c.value, 1)
    RE(counting_stepscan(det, motor))  # should advance c
    assert_equal(c.value, 2)
    RE(stepscan(det, motor))  # should not
    assert_equal(c.value, 2)
Beispiel #28
0
def test_subscribe_msg(RE, hw):
    assert RE.state == "idle"
    c = CallbackCounter()

    def counting_stepscan(det, motor):
        yield Msg("subscribe", None, c, "start")
        yield from stepscan(det, motor)

    RE(counting_stepscan(hw.det, hw.motor))  # should advance c
    assert c.value == 1
    RE(counting_stepscan(hw.det, hw.motor))  # should advance c
    assert c.value == 2
    RE(stepscan(hw.det, hw.motor))  # should not
    assert c.value == 2
def test_scan_and_get_data():
    try:
        import metadatastore
    except ImportError:
        raise SkipTest
    try:
        from dataportal import DataBroker as db
    except ImportError:
        raise SkipTest
    from bluesky.standard_config import gs
    uid = gs.RE(stepscan(det, motor), group='foo', beamline_id='testing',
             config={})

    hdr = db[uid]
    db.fetch_events(hdr)
def test_post_run(fresh_RE, db):
    RE = fresh_RE
    RE.subscribe('all', db.mds.insert)
    output = defaultdict(list)

    def do_nothing(doctype, doc):
        output[doctype].append(doc)

    RE.ignore_callback_exceptions = False

    RE(stepscan(det, motor), subs={'stop': [post_run(do_nothing, db=db)]})
    assert len(output)
    assert len(output['start']) == 1
    assert len(output['stop']) == 1
    assert len(output['descriptor']) == 1
    assert len(output['event']) == 10
def test_post_run(fresh_RE, db):
    RE = fresh_RE
    RE.subscribe('all', db.mds.insert)
    output = defaultdict(list)

    def do_nothing(doctype, doc):
        output[doctype].append(doc)

    RE.ignore_callback_exceptions = False

    RE(stepscan(det, motor), subs={'stop': [post_run(do_nothing, db=db)]})
    assert len(output)
    assert len(output['start']) == 1
    assert len(output['stop']) == 1
    assert len(output['descriptor']) == 1
    assert len(output['event']) == 10
Beispiel #32
0
def test_live_plotter(RE, hw):
    RE.ignore_callback_exceptions = False
    try:
        import matplotlib.pyplot as plt
        del plt
    except ImportError as ie:
        pytest.skip("Skipping live plot test because matplotlib is not installed."
                    "Error was: {}".format(ie))

    my_plotter = LivePlot('det', 'motor')
    assert RE.state == 'idle'
    RE(stepscan(hw.det, hw.motor), {'all': my_plotter})
    assert RE.state == 'idle'
    xlen = len(my_plotter.x_data)
    assert xlen > 0
    ylen = len(my_plotter.y_data)
    assert xlen == ylen
    RE.ignore_callback_exceptions = True
Beispiel #33
0
def test_live_plotter(RE, hw):
    RE.ignore_callback_exceptions = False
    try:
        import matplotlib.pyplot as plt
        del plt
    except ImportError as ie:
        pytest.skip("Skipping live plot test because matplotlib is not installed."
                    "Error was: {}".format(ie))

    my_plotter = LivePlot('det', 'motor')
    assert RE.state == 'idle'
    RE(stepscan(hw.det, hw.motor), {'all': my_plotter})
    assert RE.state == 'idle'
    xlen = len(my_plotter.x_data)
    assert xlen > 0
    ylen = len(my_plotter.y_data)
    assert xlen == ylen
    RE.ignore_callback_exceptions = True
def test_scan_and_get_data():
    try:
        import metadatastore
        del metadatastore
    except ImportError:
        raise SkipTest
    try:
        from databroker import DataBroker as db
    except ImportError:
        raise SkipTest
    from bluesky.standard_config import gs
    uid = gs.RE(stepscan(det, motor),
                group='foo',
                beamline_id='testing',
                config={})

    hdr = db[uid]
    db.fetch_events(hdr)
def test_post_run():
    try:
        import databroker
        del databroker
    except ImportError:
        raise SkipTest('requires databroker')
    from bluesky.standard_config import gs
    from bluesky.broker_callbacks import post_run
    output = defaultdict(list)
    def do_nothing(doctype, doc):
        output[doctype].append(doc)

    gs.RE.ignore_callback_exceptions = False

    gs.RE(stepscan(det, motor), subs={'stop': [post_run(do_nothing)]})
    assert len(output)
    assert_equal(len(output['start']), 1)
    assert_equal(len(output['stop']), 1)
    assert_equal(len(output['descriptor']), 1)
    assert_equal(len(output['event']), 10)
Beispiel #36
0
def test_straight_through_stream(RE, hw):
    # Just a stream that sinks the events it receives
    ss = NegativeStream()
    # Create callback chain
    c = CallbackCounter()
    d = DocCollector()
    ss.subscribe(c)
    ss.subscribe(d.insert)
    # Run a basic plan
    RE(stepscan(hw.det, hw.motor), {'all': ss})
    # Check that our metadata is there
    assert c.value == 10 + 1 + 2  # events, descriptor, start and stop
    assert d.start[0]['stream_level'] == 'boring'
    desc = d.descriptor[d.start[0]['uid']][0]
    events = d.event[desc['uid']]
    print(desc)
    print([evt['data'] for evt in events])
    assert all([
        evt['data'][key] <= 0 for evt in events for key in evt['data'].keys()
    ])
    assert all([key in desc['data_keys'] for key in events[0]['data'].keys()])
Beispiel #37
0
def test_straight_through_stream(RE, hw):
    # Just a stream that sinks the events it receives
    ss = NegativeStream()
    # Create callback chain
    c = CallbackCounter()
    d = DocCollector()
    ss.subscribe(c)
    ss.subscribe(d.insert)
    # Run a basic plan
    RE(stepscan(hw.det, hw.motor), {'all': ss})
    # Check that our metadata is there
    assert c.value == 10 + 1 + 2  # events, descriptor, start and stop
    assert d.start[0]['stream_level'] == 'boring'
    desc = d.descriptor[d.start[0]['uid']][0]
    events = d.event[desc['uid']]
    print(desc)
    print([evt['data'] for evt in events])
    assert all([evt['data'][key] <= 0
                for evt in events
                for key in evt['data'].keys()])
    assert all([key in desc['data_keys'] for key in events[0]['data'].keys()])
def test_post_run():
    try:
        import databroker
        del databroker
    except ImportError:
        raise SkipTest('requires databroker')
    from bluesky.standard_config import gs
    from bluesky.broker_callbacks import post_run
    output = defaultdict(list)

    def do_nothing(doctype, doc):
        output[doctype].append(doc)

    gs.RE.ignore_callback_exceptions = False

    gs.RE(stepscan(det, motor), subs={'stop': [post_run(do_nothing)]})
    assert len(output)
    assert_equal(len(output['start']), 1)
    assert_equal(len(output['stop']), 1)
    assert_equal(len(output['descriptor']), 1)
    assert_equal(len(output['event']), 10)
Beispiel #39
0
def test_average_stream(RE, hw):
    # Create callback chain
    avg = AverageStream(10)
    c = CallbackCounter()
    d = DocCollector()
    avg.subscribe(c)
    avg.subscribe(d.insert)
    # Run a basic plan
    RE(stepscan(hw.det, hw.motor), {'all': avg})
    assert c.value == 1 + 1 + 2  # events, descriptor, start and stop
    # See that we made sensible descriptor
    start_uid = d.start[0]['uid']
    assert start_uid in d.descriptor
    desc_uid = d.descriptor[start_uid][0]['uid']
    assert desc_uid in d.event
    evt = d.event[desc_uid][0]
    assert evt['seq_num'] == 1
    assert all([key in d.descriptor[start_uid][0]['data_keys']
                for key in evt['data'].keys()])
    # See that we returned the correct average
    assert evt['data']['motor'] == -0.5  # mean of range(-5, 5)
    assert evt['data']['motor_setpoint'] == -0.5  # mean of range(-5, 5)
    assert start_uid in d.stop
    assert d.stop[start_uid]['num_events'] == {'primary': 1}
def test_verify_files_saved(fresh_RE, db):
    RE = fresh_RE
    RE.subscribe('all', db.mds.insert)

    vfs = partial(verify_files_saved, db=db)
    RE(stepscan(det, motor), subs={'stop': vfs})
def test_verify_files_saved(fresh_RE, db):
    RE = fresh_RE
    RE.subscribe(db.insert)

    vfs = partial(verify_files_saved, db=db)
    RE(stepscan(det, motor), subs={'stop': vfs})
def test_scan_and_get_data():
    uid = gs.RE(stepscan(det, motor), group='foo', beamline_id='testing',
             config={})

    hdr = db[uid]
    db.fetch_events(hdr)
Beispiel #43
0
 def counting_stepscan(det, motor):
     yield Msg('subscribe', None, c, 'start')
     yield from stepscan(det, motor)
Beispiel #44
0
 def counting_stepscan(det, motor):
     yield Msg("subscribe", None, c, "start")
     yield from stepscan(det, motor)
Beispiel #45
0
 def counting_stepscan(det, motor):
     yield Msg('subscribe', None, 'start', c)
     yield from stepscan(det, motor)
Beispiel #46
0
 def counting_stepscan(det, motor):
     yield Msg("subscribe", None, c, "start")
     yield from stepscan(det, motor)
Beispiel #47
0
def _raising_callbacks_helper(stream_name, callback):
    RE(stepscan(det, motor), subs={stream_name: callback})
Beispiel #48
0
def _raising_callbacks_helper(stream_name, callback):
    RE(stepscan(det, motor), subs={stream_name: callback})
Beispiel #49
0
def _raising_callbacks_helper(stream_name, callback):
    with pytest.raises(Exception):
        RE(stepscan(det, motor), subs={stream_name: callback})
Beispiel #50
0
def test_verify_files_saved(RE, hw, db):
    RE.subscribe(db.insert)

    vfs = partial(verify_files_saved, db=db)
    RE(stepscan(hw.det, hw.motor), {'stop': vfs})
def test_verify_files_saved(RE, hw, db):
    RE.subscribe(db.insert)

    vfs = partial(verify_files_saved, db=db)
    RE(stepscan(hw.det, hw.motor), {'stop': vfs})
Beispiel #52
0
def _raising_callbacks_helper(stream_name, callback):
    with pytest.raises(Exception):
        RE(stepscan(det, motor), subs={stream_name: callback})