Exemplo n.º 1
0
def test_matches_init():
    generator_func = lambda: (item / 2.0 for item in range(1, 10, 2))

    init_stream = Stream(generator_func)
    validate_stream(init_stream, 5, float)

    from_stream = Stream.from_func(generator_func)
    validate_stream(init_stream, 5, float)

    for item1, item2 in zip(init_stream, from_stream):
        assert abs(item1 - item2) < 1.0e-4
Exemplo n.º 2
0
def test_many_short():
    stream = Stream.from_iterable(range(100))
    validate_stream(stream, 100, int)

    stream_repr = repr(stream)
    validate_header(stream_repr)
    assert ', ' in stream_repr
    assert stream_repr.endswith('...')
Exemplo n.º 3
0
def test_few_short():
    stream = Stream.from_iterable(range(3))
    validate_stream(stream, 3, int)

    stream_repr = repr(stream)
    validate_header(stream_repr)
    assert ', ' in stream_repr
    assert not stream_repr.endswith('...')
Exemplo n.º 4
0
def test_from_iterable_tuple():
    values = [
        [1, 2, 3],
        ['a', 'b', 'c'],
        ['x', 'y', 'z'],
    ]

    iter_stream = Stream.from_iterable(values)
    validate_stream(iter_stream, 3, list, 3)
Exemplo n.º 5
0
def test_many_long():
    long_string = string.ascii_letters * 2

    stream = Stream.from_iterable([long_string,] * 100)
    validate_stream(stream, 100, str, len(long_string))

    stream_repr = repr(stream)
    validate_header(stream_repr)
    assert ',\n' in stream_repr
    assert stream_repr.endswith('...')
Exemplo n.º 6
0
def test_chain(name_stream, number_stream):
    chain_stream = Stream.chain(name_stream, number_stream, name_stream)
    validate_stream(chain_stream, 4 + 256 + 4, str)

    chain_stream = name_stream.chain(number_stream, name_stream)
    validate_stream(chain_stream, 4 + 256 + 4, str)

    chain_stream = name_stream + number_stream + name_stream
    validate_stream(chain_stream, 4 + 256 + 4, str)

    list_stream = list(chain_stream)
    assert list_stream[0] == 'Elliott 38'
    assert list_stream[-1] == 'Alexa 3'
Exemplo n.º 7
0
def test_from_iterable():
    iter_stream = Stream.from_iterable([1, 2, 3])
    validate_stream(iter_stream, 3, int)
Exemplo n.º 8
0
def test_no_func():
    none_stream = Stream.from_iterable([1, 2, None, 3, 4, None, 5])
    validate_stream(none_stream, 7, (int, type(None)))

    filter_stream = none_stream.filter()
    validate_stream(filter_stream, 5, int)
Exemplo n.º 9
0
def test_no_args(empty_stream):
    validate_stream(empty_stream.chain(), 0, object)

    with pytest.raises(TypeError):
        Stream.chain()
Exemplo n.º 10
0
def test_empty_tuple_stream():
    empty_tuple_stream = Stream.from_iterable(())
    unbatched_stream = empty_tuple_stream.unbatch()
    validate_stream(unbatched_stream, 0, object)
Exemplo n.º 11
0
def test_from_empty():
    empty_stream = Stream.from_func(lambda: iter(()))
    validate_stream(empty_stream, 0, object)
Exemplo n.º 12
0
def test_from_txt(names_path):
    txt_stream = Stream.from_txt(names_path)
    validate_stream(txt_stream, 4, str)
Exemplo n.º 13
0
def test_from_empty_txt():
    # create a stream from an empty temp file and validate that its empty
    with tempfile.NamedTemporaryFile() as temp_file:
        txt_stream = Stream.from_txt(temp_file.name)
        validate_stream(txt_stream, 0, object)