def test_zip_same(): a = Stream() b = a.zip(a) L = b.sink_to_list() a.emit(1) a.emit(2) assert L == [(1, 1), (2, 2)]
def test_disconnect_zip(): a = Stream() b = Stream() c = Stream() x = a.zip(b, c) L = x.sink_to_list() b.disconnect(x) a.emit(1) b.emit(1) assert not L c.emit(1) assert L == [(1, 1)]
def test_zip_metadata(): a = Stream() b = Stream() L = metadata(a.zip(b)).sink_to_list() a.emit(1, metadata=[{'v': 1}]) b.emit(2, metadata=[{'v': 2}]) a.emit(3) b.emit(4, metadata=[{'v': 4}]) assert L == [ [{ 'v': 1 }, { 'v': 2 }], # first emit when 2 is introduced [{ 'v': 4 }] # second emit when 4 is introduced, and 3 has no metadata ]
def test_zip_ref_counts(): a = Stream() b = Stream() _ = a.zip(b) # The first value in a becomes buffered ref1 = RefCounter() a.emit(1, metadata=[{'ref': ref1}]) assert ref1.count == 1 # The second value in a also becomes buffered ref2 = RefCounter() a.emit(2, metadata=[{'ref': ref2}]) assert ref1.count == 1 assert ref2.count == 1 # All emitted values are removed from the buffer ref3 = RefCounter() b.emit(3, metadata=[{'ref': ref3}]) assert ref1.count == 0 assert ref2.count == 1 # still in the buffer assert ref3.count == 0
def test_zip(): a = Stream() b = Stream() c = sz.zip(a, b) L = c.sink_to_list() a.emit(1) b.emit('a') a.emit(2) b.emit('b') assert L == [(1, 'a'), (2, 'b')] d = Stream() # test zip from the object itself # zip 3 streams together e = a.zip(b, d) L2 = e.sink_to_list() a.emit(1) b.emit(2) d.emit(3) assert L2 == [(1, 2, 3)]