Ejemplo n.º 1
0
def test_spec_to_document(sf, db_all, scan_ids):
    map = {
        'start': db_all.mds.insert_run_start,
        'stop': db_all.mds.insert_run_stop,
        'descriptor': db_all.mds.insert_descriptor,
        'event': db_all.mds.insert_event
    }
    start_uids = list()

    for document_name, document in spec.spec_to_document(sf,
                                                         scan_ids=scan_ids,
                                                         validate=True,
                                                         db=db_all):
        document = dict(document)
        del document['_name']
        if not isinstance(document_name, str):
            document_name = document_name.name
        # insert the documents
        if document_name == 'start':
            document['beamline_id'] = 'test'
            start_uids.append(document['uid'])
        map[document_name](**document)

    # make sure we are not trying to add duplicates
    assert len(start_uids) == len(set(start_uids))

    # smoketest the retrieval
    hdrs = []
    for uid in start_uids:
        hdr = db_all[uid]
        # make sure we only get one back
        assert isinstance(hdr, Header)
        hdrs.append(hdr)

    # make sure we are not getting duplicates back out
    hdr_uids = [hdr.start.uid for hdr in hdrs]
    assert len(hdr_uids) == len(set(hdr_uids))
    if isinstance(sf, spec.Specscan):
        sf = [sf]
    if isinstance(sf, str):
        sf = spec.Specfile(sf)
    for hdr, specscan in zip(hdrs, sf):
        for descriptor in hdr.descriptors:
            ev = list(db_all.mds.get_events_generator(descriptor))
            if descriptor.get('name') == 'baseline':
                # we better only have one baseline event
                assert len(ev) == 1
            else:
                assert len(specscan.scan_data) == len(ev)
Ejemplo n.º 2
0
def test_spec_to_document(sf, mds_all, scan_ids):
    map = {
        'start': mds_all.insert_run_start,
        'stop': mds_all.insert_run_stop,
        'descriptor': mds_all.insert_descriptor,
        'event': mds_all.insert_event
    }
    start_uids = list()

    db = Broker(mds_all, fs=None)

    for document_name, document in spec.spec_to_document(
            sf, mds_all, scan_ids=scan_ids, validate=True):
        document = dict(document)
        del document['_name']
        if not isinstance(document_name, str):
            document_name = document_name.name
        # insert the documents
        if document_name == 'start':
            document['beamline_id'] = 'test'
            start_uids.append(document['uid'])
        map[document_name](**document)

    # make sure we are not trying to add duplicates
    assert len(start_uids) == len(set(start_uids))

    # smoketest the retrieval
    hdrs = []
    for uid in start_uids:
        hdr = db[uid]
        # make sure we only get one back
        assert isinstance(hdr, Header)
        hdrs.append(hdr)

    # make sure we are not getting duplicates back out
    hdr_uids = [hdr.start.uid for hdr in hdrs]
    assert len(hdr_uids) == len(set(hdr_uids))
    if isinstance(sf, spec.Specscan):
        sf = [sf]
    if isinstance(sf, str):
        sf = spec.Specfile(sf)
    for hdr, specscan in zip(hdrs, sf):
        for descriptor in hdr.descriptors:
            ev = list(mds_all.get_events_generator(descriptor))
            if descriptor.get('name') == 'baseline':
                # we better only have one baseline event
                assert len(ev) == 1
            else:
                assert len(specscan.scan_data) == len(ev)
Ejemplo n.º 3
0
def _round_trip(specfile_object, new_specfile_name=None):
    if new_specfile_name is None:
        new_specfile_name = tempfile.NamedTemporaryFile().name

    document_stream = spec_to_document(specfile_object)
    cb = DocumentToSpec(new_specfile_name)
    for doc_name, doc in document_stream:
        # RunEngine.subscribe does the translation of 'start' <->
        # event_model.DocumentNames.start under the hood. Since we do not have
        # this magic here, we have to do it by hand
        cb(doc_name.name, doc)

    sf1 = Specfile(new_specfile_name)

    return sf1
Ejemplo n.º 4
0
def _round_trip(specfile_object, mds_all, new_specfile_name=None):
    if new_specfile_name is None:
        new_specfile_name = tempfile.NamedTemporaryFile().name

    document_stream = spec.spec_to_document(specfile_object, mds_all)
    cb = spec.DocumentToSpec(new_specfile_name)
    for doc_name, doc in document_stream:
        # RunEngine.subscribe does the translation of 'start' <->
        # event_model.DocumentNames.start under the hood. Since we do not have
        # this magic here, we have to do it by hand
        cb(doc_name.name, doc)

    sf1 = spec.Specfile(new_specfile_name)

    return sf1
Ejemplo n.º 5
0
def test_spec_to_document_bad_input():
    list(spec.spec_to_document(2))
Ejemplo n.º 6
0
def test_spec_to_document_bad_input():
    list(spec_to_document(2))