def test_last_cache(RE, hw): source = Stream() t = FromEventStream("event", ("data", "motor"), source, principle=True) assert t.principle n = ToEventStream( t, ("ct",), data_key_md={"ct": {"units": "arb"}} ).LastCache() tt = t.sink_to_list() names = n.pluck(0).sink_to_list() docs = n.pluck(1).sink_to_list() RE.subscribe(unstar(source.emit)) RE.subscribe(print) RE(scan([hw.motor], hw.motor, 0, 9, 10)) assert len(docs) == 10 + 3 + 2 assert names[-3] == "descriptor" assert names[-2] == "event" assert tt assert set(names) == {"start", "stop", "event", "descriptor"} assert docs[1]["hints"] == {"analyzer": {"fields": ["ct"]}} assert docs[1]["data_keys"]["ct"]["units"] == "arb" assert docs[-1]["run_start"]
def test_to_event_model_new_api_multi_parent(RE, hw): source = Stream() t = FromEventStream("event", ("data", "motor"), source, principle=True) t2 = FromEventStream("event", ("data", "motor"), source, principle=True) assert t.principle n = simple_to_event_stream_new_api( { t.zip(t2).pluck(0): { "data_keys": {"ct": {"units": "arb", "precision": 2}} } } ) tt = t.sink_to_list() p = n.pluck(0).sink_to_list() d = n.pluck(1).sink_to_list() RE.subscribe(unstar(source.emit)) RE.subscribe(print) RE(scan([hw.motor], hw.motor, 0, 9, 10)) assert tt assert set(p) == {"start", "stop", "event", "descriptor"} assert d[1]["hints"] == {"analyzer": {"fields": ["ct"]}} assert d[1]["data_keys"]["ct"]["units"] == "arb" assert d[-1]["run_start"]
def test_to_event_model_new_api_multi(RE, hw): source = Stream() stop = FromEventStream("stop", (), source) t = FromEventStream( "event", ("data", "motor"), source, principle=True, stream_name="hi" ) assert t.principle tt = t.zip(stop) n = simple_to_event_stream_new_api( { t: {"data_keys": {"ct": {"units": "arb", "precision": 2}}}, tt: { "name": "final", "data_keys": {"ct": {"units": "arb", "precision": 2}}, }, }, hello="world", ) tt = t.sink_to_list() p = n.pluck(0).sink_to_list() d = n.pluck(1).sink_to_list() RE.subscribe(unstar(source.emit)) RE.subscribe(print) RE(scan([hw.motor], hw.motor, 0, 9, 10)) assert tt assert set(p) == {"start", "stop", "event", "descriptor"} assert d[0]["hello"] == "world" assert d[1]["hints"] == {"analyzer": {"fields": ["ct"]}} assert d[1]["data_keys"]["ct"]["units"] == "arb" assert d[-3]["name"] == "final" assert d[-1]["run_start"]
def test_dbfriendly(RE, hw): source = Stream() t = FromEventStream("event", ("data", "motor"), source, principle=True) z = t.map(op.add, 1) n = ToEventStream(z, "out").DBFriendly() d = n.pluck(1).sink_to_list() RE.subscribe(unstar(source.emit)) RE(scan([hw.motor], hw.motor, 0, 9, 10)) assert isinstance(d[0]["graph"], dict) h1 = d[0].get("graph_hash") assert h1 d.clear() RE(scan([hw.motor], hw.motor, 0, 9, 10)) h2 = d[0].get("graph_hash") assert h1 == h2 assert len(d) == 10 + 3 d.clear() z.args = (2,) RE(scan([hw.motor], hw.motor, 0, 9, 10)) h2 = d[0].get("graph_hash") assert h1 != h2 assert len(d) == 10 + 3
def test_from_event_model_all(RE, hw): source = Stream() t = FromEventStream("event", (), source, principle=True) L = t.sink_to_list() RE.subscribe(unstar(source.emit)) RE.subscribe(print) RE(scan([hw.motor], hw.motor, 0, 9, 10)) assert len(L) == 10 for i, ll in enumerate(L): assert i == ll["data"]["motor"]
def test_from_event_model_stream_syntax(RE, hw): source = Stream() t = source.simple_from_event_stream( "event", ("data", "motor"), principle=True ) L = t.sink_to_list() RE.subscribe(unstar(source.emit)) RE.subscribe(print) RE(scan([hw.motor], hw.motor, 0, 9, 10)) assert len(L) == 10 for i, ll in enumerate(L): assert i == ll
def test_no_stop(hw, RE): source = Stream().filter(lambda x: x[0] != "stop") t = FromEventStream("event", ("data",), source, principle=True) n = ToEventStream(t) p = n.pluck(0).sink_to_list() d = n.pluck(1).sink_to_list() RE.subscribe(unstar(source.emit)) RE.subscribe(print) RE(scan([hw.motor], hw.motor, 0, 9, 10)) RE(scan([hw.motor], hw.motor, 0, 9, 10)) assert set(p) == {"start", "stop", "event", "descriptor"} assert d[1]["hints"] == { "analyzer": {"fields": ["motor", "motor_setpoint"]} } assert d[2]["data"] == {"motor_setpoint": 0, "motor": 0}
def test_to_event_model(RE, hw): source = Stream() t = FromEventStream("event", ("data", "motor"), source, principle=True) assert t.principle n = ToEventStream(t, ("ct",)) tt = t.sink_to_list() p = n.pluck(0).sink_to_list() d = n.pluck(1).sink_to_list() RE.subscribe(unstar(source.emit)) RE.subscribe(print) RE(scan([hw.motor], hw.motor, 0, 9, 10)) assert tt assert set(p) == {"start", "stop", "event", "descriptor"} assert d[1]["hints"] == {"analyzer": {"fields": ["ct"]}} assert d[-1]["run_start"]
def test_to_event_model_new_api_clobber(RE, hw): source = Stream() t = FromEventStream("event", ("data", "motor"), source, principle=True) assert t.principle n = simple_to_event_stream_new_api( {t: {"data_keys": {"ct": {"units": "arb", "dtype": "array"}}}} ) tt = t.sink_to_list() p = n.pluck(0).sink_to_list() d = n.pluck(1).sink_to_list() RE.subscribe(unstar(source.emit)) RE.subscribe(print) RE(scan([hw.motor], hw.motor, 0, 9, 10)) assert tt assert set(p) == {"start", "stop", "event", "descriptor"} assert d[1]["data_keys"]["ct"]["dtype"] == "array" assert d[-1]["run_start"]
def test_to_event_model_new_api_no_data_keys(RE, hw): source = Stream() t = FromEventStream("event", ("data",), source, principle=True) assert t.principle n = simple_to_event_stream_new_api({t: {}}) tt = t.sink_to_list() p = n.pluck(0).sink_to_list() d = n.pluck(1).sink_to_list() RE.subscribe(unstar(source.emit)) RE.subscribe(print) RE(scan([hw.motor], hw.motor, 0, 9, 10)) assert tt assert set(p) == {"start", "stop", "event", "descriptor"} assert d[1]["hints"] == { "analyzer": {"fields": ["motor", "motor_setpoint"]} } assert d[1]["data_keys"]["motor"] assert d[-1]["run_start"]
def test_to_event_model_dict(RE, hw): source = Stream() t = FromEventStream("event", ("data",), source, principle=True) n = ToEventStream(t) p = n.pluck(0).sink_to_list() d = n.pluck(1).sink_to_list() n.sink(print) RE.subscribe(unstar(source.emit)) RE.subscribe(print) RE(scan([hw.motor], hw.motor, 0, 9, 10)) print(d[1]["hints"]) # AAA assert set(p) == {"start", "stop", "event", "descriptor"} assert d[1]["hints"] == { "analyzer": {"fields": ["motor", "motor_setpoint"]} } assert d[2]["data"] == {"motor_setpoint": 0, "motor": 0} assert d[-1]["run_start"]