示例#1
0
def test_custom_warn():

    run_start_uid = str(uuid.uuid4())

    warnings.simplefilter('always', UserWarning)
    with warnings.catch_warnings(record=True) as w:
        run_start_uid = mdsc.insert_run_start(
            scan_id=30220, beamline_id='testbed',
            owner='Al the Aardvark', group='Orycteropus',
            project='Nikea', time=document_insertion_time,
            uid=run_start_uid, custom={'order': 'Tubulidentata'})
        assert len(w) == 1

    rs = next(mdsc.find_run_starts(order='Tubulidentata'))
    assert rs['uid'] == run_start_uid

    with warnings.catch_warnings(record=True) as w:
        ev_desc_uid = mdsc.insert_descriptor(
            run_start_uid,
            {'a': {'source': 'zoo', 'shape': [], 'dtype': 'number'}},
            ttime.time(), str(uuid.uuid4()), custom={'food': 'ants'})

        assert len(w) == 1
    ed = mdsc.descriptor_given_uid(ev_desc_uid)
    assert ed['food'] == 'ants'

    with warnings.catch_warnings(record=True) as w:
        stop_uid = str(uuid.uuid4())
        mdsc.insert_run_stop(run_start_uid, ttime.time(),
                             stop_uid, custom={'navy': 'VF-114'})

        assert len(w) == 1

    run_stop = mdsc.run_stop_given_uid(stop_uid)
    assert run_stop['navy'] == 'VF-114'
示例#2
0
def test_double_run_stop():
    run_start_uid, e_desc_uid, data_keys = setup_syn()
    mdsc.insert_run_stop(run_start_uid, ttime.time(),
                         uid=str(uuid.uuid4()))
    with pytest.raises(RuntimeError):
        mdsc.insert_run_stop(run_start_uid, ttime.time(),
                             uid=str(uuid.uuid4()))
示例#3
0
def test_find_run_start():
    run_start_uid, e_desc_uid, data_keys = setup_syn()
    mdsc.insert_run_stop(run_start_uid, ttime.time(), uid=str(uuid.uuid4()))

    run_start = mdsc.run_start_given_uid(run_start_uid)

    run_start2, = list(mdsc.find_run_starts(uid=run_start_uid))

    assert_equal(run_start, run_start2)
示例#4
0
def test_find_run_start():
    run_start_uid, e_desc_uid, data_keys = setup_syn()
    mdsc.insert_run_stop(run_start_uid, ttime.time(), uid=str(uuid.uuid4()))

    run_start = mdsc.run_start_given_uid(run_start_uid)

    run_start2, = list(mdsc.find_run_starts(uid=run_start_uid))

    assert run_start == run_start2
示例#5
0
def test_bulk_table():
    num = 50
    rs, e_desc, data_keys = setup_syn()
    all_data = syn_data(data_keys, num)

    mdsc.bulk_insert_events(e_desc, all_data, validate=False)
    mdsc.insert_run_stop(rs, ttime.time(), uid=str(uuid.uuid4()))
    ret = mdsc.get_events_table(e_desc)
    descriptor, data_table, seq_nums, times, uids, timestamps_table = ret

    for vals in data_table.values():
        assert all(s == v for s, v in zip(seq_nums, vals))
示例#6
0
def test_bulk_table():
    num = 50
    rs, e_desc, data_keys = setup_syn()
    all_data = syn_data(data_keys, num)

    mdsc.bulk_insert_events(e_desc, all_data, validate=False)
    mdsc.insert_run_stop(rs, ttime.time(), uid=str(uuid.uuid4()))
    ret = mdsc.get_events_table(e_desc)
    descriptor, data_table, seq_nums, times, uids, timestamps_table = ret

    for vals in data_table.values():
        assert_true(all(s == v for s, v in zip(seq_nums, vals)))
示例#7
0
def test_bulk_insert():
    num = 50
    rs, e_desc, data_keys = setup_syn()
    all_data = syn_data(data_keys, num)

    mdsc.bulk_insert_events(e_desc, all_data, validate=False)
    mdsc.insert_run_stop(rs, ttime.time(), uid=str(uuid.uuid4()))

    ev_gen = mdsc.get_events_generator(e_desc)

    for ret, expt in zip(ev_gen, all_data):
        assert_equal(ret['descriptor']['uid'], e_desc)
        for k in ['data', 'timestamps', 'time', 'uid', 'seq_num']:
            assert_equal(ret[k], expt[k])
示例#8
0
def test_bulk_insert():
    num = 50
    rs, e_desc, data_keys = setup_syn()
    all_data = syn_data(data_keys, num)

    mdsc.bulk_insert_events(e_desc, all_data, validate=False)
    mdsc.insert_run_stop(rs, ttime.time(), uid=str(uuid.uuid4()))

    ev_gen = mdsc.get_events_generator(e_desc)

    for ret, expt in zip(ev_gen, all_data):
        assert ret['descriptor']['uid'] == e_desc
        for k in ['data', 'timestamps', 'time', 'uid', 'seq_num']:
            assert ret[k] == expt[k]
示例#9
0
def test_run_stop_insertion():
    """Test, uh, the insertion of run stop documents
    """
    run_start_uid = mdsc.insert_run_start(
        time=ttime.time(), beamline_id='sample_beamline', scan_id=42,
        uid=str(uuid.uuid4()))
    time = ttime.time()
    exit_status = 'success'
    reason = 'uh, because this is testing and it better be a success?'
    # insert the document
    run_stop_uid = mdsc.insert_run_stop(run_start_uid, time,
                                        exit_status=exit_status,
                                        reason=reason, uid=str(uuid.uuid4()))

    # get the sanitized run_stop document from metadatastore
    run_stop, = mdsc.find_run_stops(uid=run_stop_uid)

    # make sure it does not have an 'id' field
    check_for_id(run_stop)
    # make sure the run stop is pointing to the correct run start
    referenced_run_start = run_stop['run_start']
    assert referenced_run_start.uid == run_start_uid

    # check the remaining fields
    comparisons = {'time': time,
                   'exit_status': exit_status,
                   'reason': reason,
                   'uid': run_stop_uid}
    for attr, known_value in comparisons.items():
        assert known_value == getattr(run_stop, attr)
示例#10
0
def test_run_stop_insertion():
    """Test, uh, the insertion of run stop documents
    """
    run_start_uid = mdsc.insert_run_start(
        time=ttime.time(), beamline_id='sample_beamline', scan_id=42,
        uid=str(uuid.uuid4()))
    time = ttime.time()
    exit_status = 'success'
    reason = 'uh, because this is testing and it better be a success?'
    # insert the document
    run_stop_uid = mdsc.insert_run_stop(run_start_uid, time,
                                       exit_status=exit_status,
                                       reason=reason, uid=str(uuid.uuid4()))

    # get the sanitized run_stop document from metadatastore
    run_stop, = mdsc.find_run_stops(uid=run_stop_uid)

    # make sure it does not have an 'id' field
    check_for_id(run_stop)
    # make sure the run stop is pointing to the correct run start
    referenced_run_start = run_stop['run_start']
    assert_equal(referenced_run_start.uid, run_start_uid)

    # check the remaining fields
    comparisons = {'time': time,
                   'exit_status': exit_status,
                   'reason': reason,
                   'uid': run_stop_uid}
    for attr, known_value in comparisons.items():
        assert_equal(known_value, getattr(run_stop, attr))
示例#11
0
def test_find_events_smoke():

    num = 50
    rs, e_desc, data_keys = setup_syn()
    all_data = syn_data(data_keys, num)

    mdsc.bulk_insert_events(e_desc, all_data, validate=False)
    mdsc.insert_run_stop(rs, ttime.time(), uid=str(uuid.uuid4()))
    mdsc.clear_process_cache()

    # make sure the uid works
    next(mdsc.find_events(descriptor=e_desc))

    mdsc.clear_process_cache()
    descriptor, = mdsc.find_descriptors(uid=e_desc)

    mdsc.clear_process_cache()
    # make sure that searching by descriptor document works
    next(mdsc.find_events(descriptor=descriptor))
示例#12
0
def test_find_events_smoke():

    num = 50
    rs, e_desc, data_keys = setup_syn()
    all_data = syn_data(data_keys, num)

    mdsc.bulk_insert_events(e_desc, all_data, validate=False)
    mdsc.insert_run_stop(rs, ttime.time(), uid=str(uuid.uuid4()))
    mdsc.clear_process_cache()
    
    # make sure the uid works
    next(mdsc.find_events(descriptor=e_desc))
    
    mdsc.clear_process_cache()
    descriptor, = mdsc.find_descriptors(uid=e_desc)
    
    mdsc.clear_process_cache()
    # make sure that searching by descriptor document works
    next(mdsc.find_events(descriptor=descriptor))
示例#13
0
def test_find_run_stop():
    run_start_uid, e_desc_uid, data_keys = setup_syn()
    run_stop_uid = mdsc.insert_run_stop(run_start_uid, ttime.time(),
                                       uid=str(uuid.uuid4()))

    run_start = mdsc.run_start_given_uid(run_start_uid)
    run_stop = mdsc.run_stop_given_uid(run_stop_uid)

    run_stop2, = list(mdsc.find_run_stops(run_start=run_start_uid))
    run_stop3, = list(mdsc.find_run_stops(run_start=run_start))
    assert_equal(run_stop, run_stop2)
    assert_equal(run_stop, run_stop3)
示例#14
0
def setup():
    mds_setup()
    global blc_uid, run_start_uid, document_insertion_time, run_stop_uid
    global descriptor_uid
    document_insertion_time = ttime.time()
    temperature_ramp.run()
    blc_uid = mdsc.insert_beamline_config({}, time=document_insertion_time)
    run_start_uid = mdsc.insert_run_start(scan_id=3022013,
                                          beamline_id='testbed',
                                          beamline_config=blc_uid,
                                          owner='tester',
                                          group='awesome-devs',
                                          project='Nikea',
                                          time=document_insertion_time)
    run_stop_uid = mdsc.insert_run_stop(run_start=run_start_uid,
                                        time=ttime.time())
示例#15
0
def setup():
    mds_setup()
    global blc_uid, run_start_uid, document_insertion_time, run_stop_uid
    global descriptor_uid
    document_insertion_time = ttime.time()
    temperature_ramp.run()
    blc_uid = mdsc.insert_beamline_config({}, time=document_insertion_time)
    run_start_uid = mdsc.insert_run_start(scan_id=3022013,
                                          beamline_id='testbed',
                                          beamline_config=blc_uid,
                                          owner='tester',
                                          group='awesome-devs',
                                          project='Nikea',
                                          time=document_insertion_time)
    run_stop_uid = mdsc.insert_run_stop(run_start=run_start_uid,
                                        time=ttime.time())
示例#16
0
def test_run_stop_by_run_start():
    run_start_uid, e_desc_uid, data_keys = setup_syn()
    run_stop_uid = mdsc.insert_run_stop(run_start_uid,
                                        ttime.time(), uid=str(uuid.uuid4()))
    run_start = mdsc.run_start_given_uid(run_start_uid)
    run_stop = mdsc.run_stop_given_uid(run_stop_uid)
    ev_desc = mdsc.descriptor_given_uid(e_desc_uid)

    run_stop2 = mdsc.stop_by_start(run_start)
    run_stop3 = mdsc.stop_by_start(run_start_uid)
    assert run_stop == run_stop2
    assert run_stop == run_stop3

    ev_desc2, = mdsc.descriptors_by_start(run_start)
    ev_desc3, = mdsc.descriptors_by_start(run_start_uid)
    assert ev_desc == ev_desc2
    assert ev_desc == ev_desc3
示例#17
0
def test_run_stop_by_run_start():
    run_start_uid, e_desc_uid, data_keys = setup_syn()
    run_stop_uid = mdsc.insert_run_stop(run_start_uid,
                                       ttime.time(), uid=str(uuid.uuid4()))
    run_start = mdsc.run_start_given_uid(run_start_uid)
    run_stop = mdsc.run_stop_given_uid(run_stop_uid)
    ev_desc = mdsc.descriptor_given_uid(e_desc_uid)

    run_stop2 = mdsc.stop_by_start(run_start)
    run_stop3 = mdsc.stop_by_start(run_start_uid)
    assert_equal(run_stop, run_stop2)
    assert_equal(run_stop, run_stop3)

    ev_desc2, = mdsc.descriptors_by_start(run_start)
    ev_desc3, = mdsc.descriptors_by_start(run_start_uid)
    assert_equal(ev_desc, ev_desc2)
    assert_equal(ev_desc, ev_desc3)
示例#18
0
def test_cache_clear_lookups():
    run_start_uid, e_desc_uid, data_keys = setup_syn()
    run_stop_uid = mdsc.insert_run_stop(run_start_uid,
                                       ttime.time(), uid=str(uuid.uuid4()))
    run_start = mdsc.run_start_given_uid(run_start_uid)
    run_stop = mdsc.run_stop_given_uid(run_stop_uid)
    ev_desc = mdsc.descriptor_given_uid(e_desc_uid)

    mdsc.clear_process_cache()

    run_start2 = mdsc.run_start_given_uid(run_start_uid)
    mdsc.clear_process_cache()

    run_stop2 = mdsc.run_stop_given_uid(run_stop_uid)
    mdsc.clear_process_cache()
    ev_desc2 = mdsc.descriptor_given_uid(e_desc_uid)
    ev_desc3 = mdsc.descriptor_given_uid(e_desc_uid)

    assert_equal(run_start, run_start2)
    assert_equal(run_stop, run_stop2)
    assert_equal(ev_desc, ev_desc2)
    assert_equal(ev_desc, ev_desc3)
示例#19
0
def test_cache_clear_lookups():
    run_start_uid, e_desc_uid, data_keys = setup_syn()
    run_stop_uid = mdsc.insert_run_stop(run_start_uid,
                                       ttime.time(), uid=str(uuid.uuid4()))
    run_start = mdsc.run_start_given_uid(run_start_uid)
    run_stop = mdsc.run_stop_given_uid(run_stop_uid)
    ev_desc = mdsc.descriptor_given_uid(e_desc_uid)

    mdsc.clear_process_cache()

    run_start2 = mdsc.run_start_given_uid(run_start_uid)
    mdsc.clear_process_cache()

    run_stop2 = mdsc.run_stop_given_uid(run_stop_uid)
    mdsc.clear_process_cache()
    ev_desc2 = mdsc.descriptor_given_uid(e_desc_uid)
    ev_desc3 = mdsc.descriptor_given_uid(e_desc_uid)

    assert run_start == run_start2
    assert run_stop == run_stop2
    assert ev_desc == ev_desc2
    assert ev_desc == ev_desc3
示例#20
0
def test_double_run_stop():
    run_start_uid, e_desc_uid, data_keys = setup_syn()
    mdsc.insert_run_stop(run_start_uid, ttime.time(), uid=str(uuid.uuid4()))
    mdsc.insert_run_stop(run_start_uid, ttime.time(), uid=str(uuid.uuid4()))