def test_combine_latest(): a = Stream() b = Stream() c = a.combine_latest(b) d = a.combine_latest(b, emit_on=[a, b]) L = c.sink_to_list() L2 = d.sink_to_list() a.emit(1) a.emit(2) b.emit('a') a.emit(3) b.emit('b') assert L == [(2, 'a'), (3, 'a'), (3, 'b')] assert L2 == [(2, 'a'), (3, 'a'), (3, 'b')]
def test_connect_discombine_latest(): a = Stream() b = Stream() c = Stream() x = a.combine_latest(b, c, emit_on=a) L = x.sink_to_list() c.disconnect(x) b.emit(1) c.emit(1) a.emit(1) assert L == [(1, 1)]
def test_combine_latest_emit_on_stream(): a = Stream() b = Stream() c = a.combine_latest(b, emit_on=0) L = c.sink_to_list() a.emit(1) b.emit('a') a.emit(2) a.emit(3) b.emit('b') a.emit(4) assert L == [(2, 'a'), (3, 'a'), (4, 'b')]
def test_combine_latest_ref_counts(): a = Stream() b = Stream() _ = a.combine_latest(b) ref1 = RefCounter() a.emit(1, metadata=[{'ref': ref1}]) assert ref1.count == 1 # The new value kicks out the old value ref2 = RefCounter() a.emit(2, metadata=[{'ref': ref2}]) assert ref1.count == 0 assert ref2.count == 1 # The value on stream a is still retained and the value on stream b is new ref3 = RefCounter() b.emit(3, metadata=[{'ref': ref3}]) assert ref2.count == 1 assert ref3.count == 1
def test_combine_latest_metadata(): a = Stream() b = Stream() L = metadata(a.combine_latest(b)).sink_to_list() a.emit(1, metadata=[{'v': 1}]) b.emit(2, metadata=[{'v': 2}]) b.emit(3) b.emit(4, metadata=[{'v': 4}]) assert L == [ [{ 'v': 1 }, { 'v': 2 }], # first emit when 2 is introduced [{ 'v': 1 }], # 3 has no metadata but it replaces the value on 'b' [{ 'v': 1 }, { 'v': 4 }] # 4 replaces the value without metadata on 'b' ]