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'
def test_event_descriptor_insertion(): # format some data keys for insertion data_keys = {'some_value': {'source': 'PV:pv1', 'shape': [1, 2], 'dtype': 'array'}, 'some_other_val': {'source': 'PV:pv2', 'shape': [], 'dtype': 'number'}, 'data_key3': {'source': 'PV:pv1', 'shape': [], 'dtype': 'number', 'external': 'FS:foobar'}} time = ttime.time() # test insert ev_desc_uid = mdsc.insert_descriptor(run_start_uid, data_keys, time, str(uuid.uuid4())) ev_desc_mds, = mdsc.find_descriptors(uid=ev_desc_uid) # make sure the sanitized event descriptor has no uid check_for_id(ev_desc_mds) # make sure the event descriptor is pointing to the correct run start referenced_run_start = ev_desc_mds['run_start'] assert referenced_run_start.uid == run_start_uid assert ev_desc_mds['time'] == time for k in data_keys: for ik in data_keys[k]: assert ev_desc_mds.data_keys[k][ik] == data_keys[k][ik]
def test_event_descriptor_insertion(): # format some data keys for insertion data_keys = {'some_value': {'source': 'PV:pv1', 'shape': [1, 2], 'dtype': 'array'}, 'some_other_val': {'source': 'PV:pv2', 'shape': [], 'dtype': 'number'}, 'data_key3': {'source': 'PV:pv1', 'shape': [], 'dtype': 'number', 'external': 'FS:foobar'}} time = ttime.time() # test insert ev_desc_uid = mdsc.insert_descriptor(run_start_uid, data_keys, time, str(uuid.uuid4())) ev_desc_mds, = mdsc.find_descriptors(uid=ev_desc_uid) # make sure the sanitized event descriptor has no uid check_for_id(ev_desc_mds) # make sure the event descriptor is pointing to the correct run start referenced_run_start = ev_desc_mds['run_start'] assert_equal(referenced_run_start.uid, run_start_uid) assert_equal(ev_desc_mds['time'], time) for k in data_keys: for ik in data_keys[k]: assert_equal(ev_desc_mds.data_keys[k][ik], data_keys[k][ik])
def test_bad_event_desc(): data_keys = {k: {'source': k, 'dtype': 'number', 'shape': None} for k in ['foo', 'foo.bar'] } scan_id = 1 # Create a BeginRunEvent that serves as entry point for a run rs = mdsc.insert_run_start(scan_id=scan_id, beamline_id='testing', time=ttime.time(), uid=str(uuid.uuid4())) # Create an EventDescriptor that indicates the data # keys and serves as header for set of Event(s) mdsc.insert_descriptor(data_keys=data_keys, time=ttime.time(), run_start=rs, uid=str(uuid.uuid4()))
def setup_syn(custom=None): if custom is None: custom = {} data_keys = {k: {'source': k, 'dtype': 'number', 'shape': None} for k in 'ABCEDEFGHIJKL' } scan_id = 1 # Create a BeginRunEvent that serves as entry point for a run rs = mdsc.insert_run_start(scan_id=scan_id, beamline_id='testing', time=ttime.time(), custom=custom, uid=str(uuid.uuid4())) # Create an EventDescriptor that indicates the data # keys and serves as header for set of Event(s) e_desc = mdsc.insert_descriptor(data_keys=data_keys, time=ttime.time(), run_start=rs, uid=str(uuid.uuid4())) return rs, e_desc, data_keys