Ejemplo n.º 1
0
def test_template_equality():
    t = some_template(streaming(booleans()))
    t2 = StreamTemplate(t.seed, t.parameter_seed, Stream(t.stream))

    while True:
        t3 = some_template(streaming(booleans()))
        if t3.seed != t.seed:
            break
    assert t == t2
    assert t != t3
    assert t != 1

    v = t.stream[11]
    t4 = t2.with_value(11, not v)
    assert t4 != t

    t5 = StreamTemplate(t.seed, t.parameter_seed + 1, Stream(t.stream))
    assert t2 != t5

    assert len(set((t, t2, t3, t4, t5))) == 4
Ejemplo n.º 2
0
def test_can_replace_value():
    x = Stream(loop(11))
    y = x.with_value(1, 2)
    assert list(x[:3]) == [11] * 3
    assert list(y[:3]) == [11, 2, 11]
Ejemplo n.º 3
0
def test_can_map():
    x = Stream([1, 2, 3]).map(lambda i: i * 2)
    assert isinstance(x, Stream)
    assert list(x) == [2, 4, 6]
Ejemplo n.º 4
0
def test_can_index_into_unindexed():
    x = Stream(loop(1))
    assert x[100] == 1
Ejemplo n.º 5
0
def test_wrong_index_raises_type_error():
    with pytest.raises(InvalidArgument):
        Stream([])[u'kittens']
Ejemplo n.º 6
0
def test_thunking_map_evaluates_source():
    x = Stream(loop(False))
    y = x.map(lambda t: True)
    y[100]
    assert y._thunked() == 101
    assert x._thunked() == 101
Ejemplo n.º 7
0
def test_thunking_evaluates_initial_list():
    x = Stream([1, 2, 3])
    x._thunk_to(1)
    assert len(x.fetched) == 1
Ejemplo n.º 8
0
def test_cannot_thunk_past_end_of_list():
    with pytest.raises(IndexError):
        Stream([1])._thunk_to(5)
Ejemplo n.º 9
0
def test_can_stream_infinite():
    s = Stream(loop(False))
    assert list(islice(s, 100)) == [False] * 100
Ejemplo n.º 10
0
def test_can_zip_streams_with_self(xs):
    s = Stream(iter(xs))
    assert list(zip(s, s)) == list(zip(xs, xs))
Ejemplo n.º 11
0
def test_stream_give_lists(xs):
    s = Stream(iter(xs))
    assert list(s) == xs
    assert list(s) == xs
Ejemplo n.º 12
0
def test_default_stream_is_empty():
    assert list(Stream()) == []
Ejemplo n.º 13
0
def test_can_slice_streams():
    assert list(Stream([1, 2, 3])[:2]) == [1, 2]
Ejemplo n.º 14
0
def test_thunking_map_evaluates_source():
    x = Stream(loop(False))
    y = x.map(lambda t: True)
    y[100]
    assert y._thunked() == 101
    assert x._thunked() == 101
Ejemplo n.º 15
0
def test_thunking_evaluates_initial_list():
    x = Stream([1, 2, 3])
    x._thunk_to(1)
    assert len(x.fetched) == 1
Ejemplo n.º 16
0
def test_can_replace_value():
    x = Stream(loop(11))
    y = x.with_value(1, 2)
    assert list(x[:3]) == [11] * 3
    assert list(y[:3]) == [11, 2, 11]