def test_connect_combine_latest(): a = Stream() b = Stream() c = Stream() x = a.combine_latest(b, emit_on=a) L = x.sink_to_list() c.connect(x) b.emit(1) c.emit(1) a.emit(1) assert L == [(1, 1, 1)]
def test_connect_zip(): a = Stream() b = Stream() c = Stream() x = a.zip(b) L = x.sink_to_list() c.connect(x) a.emit(1) b.emit(1) assert not L c.emit(1) assert L == [(1, 1, 1)]
def test_disconnect(): source = Stream() upstream = Stream() L = upstream.sink_to_list() source.emit(1) assert L == [] source.connect(upstream) source.emit(2) source.emit(3) assert L == [2, 3] source.disconnect(upstream) source.emit(4) assert L == [2, 3]
def test_connect(): source_downstream = Stream() # connect assumes this default behaviour # of stream initialization assert not source_downstream.downstreams assert source_downstream.upstreams == [None] # initialize the second stream to connect to source_upstream = Stream() sout = source_downstream.map(lambda x : x + 1) L = list() sout = sout.map(L.append) source_upstream.connect(source_downstream) source_upstream.emit(2) source_upstream.emit(4) assert L == [3, 5]