def test_merger2(): a = 'aaa', b = 'aa', c = 'a' result = [] sink = to_list(result) merger = _merger({ 'A': sink, 'B': sink, 'C': sink, }) source_a = consume_iterable(_tagger(merger, 'A'), a) source_b = consume_iterable(_tagger(merger, 'B'), b) source_c = consume_iterable(_tagger(merger, 'C'), c) assert next(source_a) is None assert next(source_b) is None assert next(source_c) == ('a', ['C', 'B', 'A']) with pytest.raises(StopIteration): next(source_c) with pytest.raises(StopIteration): next(source_b) with pytest.raises(StopIteration): next(source_a) assert result == ['a', 'aa', 'aaa']
def test_merger2(): a = 'aaa', b = 'aa', c = 'a' result = [] sink = to_list(result) merger = _merger({'A': sink, 'B': sink, 'C': sink, }) source_a = consume_iterable(_tagger(merger, 'A'), a) source_b = consume_iterable(_tagger(merger, 'B'), b) source_c = consume_iterable(_tagger(merger, 'C'), c) assert next(source_a) is None assert next(source_b) is None assert next(source_c) == ('a', ['C', 'B', 'A']) with pytest.raises(StopIteration): next(source_c) with pytest.raises(StopIteration): next(source_b) with pytest.raises(StopIteration): next(source_a) assert result == ['a', 'aa', 'aaa']
def test_conductor2(a, b): result = [] sink = to_list(result) merger = _merger({'A': sink, 'B': sink, }) tagged_sources = {'A': consume_iterable(_tagger(merger, 'A'), a), 'B': consume_iterable(_tagger(merger, 'B'), b), } conductor = _conductor(merger, tagged_sources) for _ in conductor: pass assert result == ['a', 'aa', 'c', 'cc', 'd']
def test_conductor2(a, b): result = [] sink = to_list(result) merger = _merger({ 'A': sink, 'B': sink, }) tagged_sources = { 'A': consume_iterable(_tagger(merger, 'A'), a), 'B': consume_iterable(_tagger(merger, 'B'), b), } conductor = _conductor(merger, tagged_sources) for _ in conductor: pass assert result == ['a', 'aa', 'c', 'cc', 'd']
def test_conductor(a, b): result = [] sink = to_list(result) merger = _merger({ 'A': sink, 'B': sink, }) tagged_sources = { 'A': consume_iterable(_tagger(merger, 'A'), a), 'B': consume_iterable(_tagger(merger, 'B'), b), } conductor = _conductor(merger, tagged_sources) # This ends the first step, all sources are applied. item, priority = next(conductor) # B assert item == 'a' priority = ['A', 'B'] assert result == ['a'] item, priority = next(conductor) assert item == 'aa' assert priority == ['B', 'A'] assert result == ['a', 'aa'] item, priority = next(conductor) assert item == 'c' assert priority == ['B', 'A'] assert result == ['a', 'aa', 'c'] item, priority = next(conductor) assert item == 'd' assert priority == ['A'] assert result == ['a', 'aa', 'c', 'cc', 'd'] with pytest.raises(StopIteration): next(conductor) assert result == ['a', 'aa', 'c', 'cc', 'd']
def test_conductor_empty(): a = ['a'] b = [] result = [] sink = to_list(result) merger = _merger({'A': sink, 'B': sink, }) tagged_sources = {'A': consume_iterable(_tagger(merger, 'A'), a), 'B': consume_iterable(_tagger(merger, 'B'), b), } conductor = _conductor(merger, tagged_sources) next(conductor) with pytest.raises(StopIteration): next(conductor) assert result == ['a']
def test_conductor(a, b): result = [] sink = to_list(result) merger = _merger({'A': sink, 'B': sink, }) tagged_sources = {'A': consume_iterable(_tagger(merger, 'A'), a), 'B': consume_iterable(_tagger(merger, 'B'), b), } conductor = _conductor(merger, tagged_sources) # This ends the first step, all sources are applied. item, priority = next(conductor) # B assert item == 'a' priority = ['A', 'B'] assert result == ['a'] item, priority = next(conductor) assert item == 'aa' assert priority == ['B', 'A'] assert result == ['a', 'aa'] item, priority = next(conductor) assert item == 'c' assert priority == ['B', 'A'] assert result == ['a', 'aa', 'c'] item, priority = next(conductor) assert item == 'd' assert priority == ['A'] assert result == ['a', 'aa', 'c', 'cc', 'd'] with pytest.raises(StopIteration): next(conductor) assert result == ['a', 'aa', 'c', 'cc', 'd']
def test_conductor_empty(): a = ['a'] b = [] result = [] sink = to_list(result) merger = _merger({ 'A': sink, 'B': sink, }) tagged_sources = { 'A': consume_iterable(_tagger(merger, 'A'), a), 'B': consume_iterable(_tagger(merger, 'B'), b), } conductor = _conductor(merger, tagged_sources) next(conductor) with pytest.raises(StopIteration): next(conductor) assert result == ['a']
def test_merger(a, b): result_a = [] sink_a = to_list(result_a) result_b = [] sink_b = to_list(result_b) merger = _merger({'A': sink_a, 'B': sink_b}) source_a = consume_iterable(_tagger(merger, 'A'), a) source_b = consume_iterable(_tagger(merger, 'B'), b) assert next(source_a) is None # a | cc d # | aa c item, source_priority = next(source_b) # | cc d # aa | c assert source_priority == ['A', 'B'] assert result_a == ['a'] assert result_b == [] assert item == 'a' item, source_priority = next(source_a) # cc | d # | c assert source_priority == ['B', 'A'] assert result_a == ['a'] assert result_b == ['aa'] assert item == 'aa' item, source_priority = next(source_b) # cc | d # | assert source_priority == ['B', 'A'] assert result_a == ['a'] assert result_b == ['aa', 'c'] assert item == 'c' with pytest.raises(StopIteration): next(source_b) # | d # assert result_a == ['a', 'cc'] assert result_b == ['aa', 'c'] item, source_priority = next(source_a) # | # assert source_priority == ['A'] assert result_a == ['a', 'cc', 'd'] assert result_b == ['aa', 'c'] with pytest.raises(StopIteration): next(source_a) # # assert result_a == ['a', 'cc', 'd'] assert result_b == ['aa', 'c'] with pytest.raises(StopIteration): next(merger)