def test_sample_md_dict_requirement(fresh_RE): RE = fresh_RE # We avoid a json ValidationError and make a user-friendly ValueError. with pytest.raises(ValueError): RE(simple_scan(motor), sample=1) RE(simple_scan(motor), sample={'number': 1}) # should not raise RE(simple_scan(motor), sample='label') # should not raise
def _md(md, RE): RE.ignore_callback_exceptions = False # Check persistence. scan = simple_scan(motor) RE(scan, project='sitting') # 'project' should not persist scan = simple_scan(motor) RE(scan, subs={'start': [validate_dict_cb_opposite('project')]}) # ...unless we add it to RE.md RE.md['project'] = 'sitting' scan = simple_scan(motor) RE(scan, subs={'start': [validate_dict_cb('project', 'sitting')]}) # new values to 'project' passed in the call override the value in md scan = simple_scan(motor) RE(scan, project='standing', subs={'start': [validate_dict_cb('project', 'standing')]}) # ...but they do not update the value in md assert RE.md['project'] == 'sitting'
def _md(md, RE, hw): RE.ignore_callback_exceptions = False # Check persistence. scan = simple_scan(hw.motor) RE(scan, project='sitting') # 'project' should not persist scan = simple_scan(hw.motor) RE(scan, {'start': [validate_dict_cb_opposite('project')]}) # ...unless we add it to RE.md RE.md['project'] = 'sitting' scan = simple_scan(hw.motor) RE(scan, {'start': [validate_dict_cb('project', 'sitting')]}) # new values to 'project' passed in the call override the value in md scan = simple_scan(hw.motor) RE(scan, {'start': [validate_dict_cb('project', 'standing')]}, project='standing') # ...but they do not update the value in md assert RE.md['project'] == 'sitting'
def _md(md): RE = RunEngine(md) scan = simple_scan(motor) assert_raises(KeyError, RE, scan) # missing owner, beamline_id scan = simple_scan(motor) assert_raises(KeyError, RE, scan, owner='dan') RE(scan, owner='dan', beamline_id='his desk', group='some group', config={}) # this should work RE(scan) # and now this should work, reusing metadata RE.md.clear() scan = simple_scan(motor) assert_raises(KeyError, RE, scan) # We can prime the md directly. RE.md['owner'] = 'dan' RE.md['group'] = 'some group' RE.md['config'] = {} RE.md['beamline_id'] = 'his desk' RE(scan) # Do optional values persist? RE(scan, project='sitting') RE(scan, subs={'start': validate_dict_cb('project', 'sitting')}) # Persistent values are white-listed, so this should not persist. RE(scan, mood='excited') RE(scan, subs={'start': validate_dict_cb_opposite('mood')}) # Add 'mood' to the whitelist and check that it persists. RE.persistent_fields.append('mood') assert_in('mood', RE.persistent_fields) RE(scan, mood='excited') RE(scan, subs={'start': validate_dict_cb('mood', 'excited')}) # Remove 'project' from the whitelist and check that is stops persisting. RE.persistent_fields.remove('project') assert_not_in('project', RE.persistent_fields) RE(scan, project='standing') RE(scan) RE(scan, subs={'start': validate_dict_cb_opposite('project')}) # Removing a field required by our Document spec is not allowed. assert_raises(ValueError, RE.persistent_fields.remove, 'beamline_id')
def _md(md): RE = RunEngine(md) RE.ignore_callback_exceptions = False scan = simple_scan(motor) assert_raises(KeyError, RE, scan) # missing owner, beamline_id scan = simple_scan(motor) assert_raises(KeyError, RE, scan, owner='dan') scan = simple_scan(motor) RE(scan, owner='dan', beamline_id='his desk', group='some group', config={}) # this should work scan = simple_scan(motor) assert_raises(KeyError, RE, scan) # this should fail; none was persisted RE.md['owner'] = 'dan' RE.md['group'] = 'some group' RE.md['config'] = {} RE.md['beamline_id'] = 'his desk' scan = simple_scan(motor) RE(scan) # this should work RE.md.clear() scan = simple_scan(motor) assert_raises(KeyError, RE, scan) # We can prime the md directly. RE.md['owner'] = 'dan' RE.md['group'] = 'some group' RE.md['config'] = {} RE.md['beamline_id'] = 'his desk' scan = simple_scan(motor) RE(scan) # Check persistence. scan = simple_scan(motor) RE(scan, project='sitting') # 'project' should not persist scan = simple_scan(motor) RE(scan, subs={'start': [validate_dict_cb_opposite('project')]}) # ...unless we add it to RE.md RE.md['project'] = 'sitting' scan = simple_scan(motor) RE(scan, subs={'start': [validate_dict_cb('project', 'sitting')]}) # new values to 'project' passed in the call override the value in md scan = simple_scan(motor) RE(scan, project='standing', subs={'start': [validate_dict_cb('project', 'standing')]}) # ...but they do not update the value in md assert_equal(RE.md['project'], 'sitting')
def test_sample_md_dict_requirement(): scan = simple_scan(motor) # We avoid a json ValidationError and make a user-friendly ValueError. assert_raises(ValueError, RE, scan, sample=1) RE(scan, sample={'number': 1}) # should not raise
def test_custom_metadata(): def assert_lion(name, doc): assert_in('animal', doc) assert_equal(doc['animal'], 'lion') RE(simple_scan(motor), animal='lion', subs={'start': assert_lion})
def test_custom_metadata(): def assert_lion(name, doc): assert 'animal' in doc assert doc['animal'] == 'lion' RE(simple_scan(motor), animal='lion', subs={'start': assert_lion})
def test_custom_metadata(RE, hw): def assert_lion(name, doc): assert 'animal' in doc assert doc['animal'] == 'lion' RE(simple_scan(hw.motor), {'start': assert_lion}, animal='lion')
def test_custom_metadata(): def assert_lion(doc): assert_in('animal', doc) assert_equal(doc['animal'], 'lion') RE(simple_scan(motor), animal='lion', subs={'start': assert_lion})