Beispiel #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
Beispiel #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]
Beispiel #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]
Beispiel #4
0
def test_can_index_into_unindexed():
    x = Stream(loop(1))
    assert x[100] == 1
Beispiel #5
0
def test_wrong_index_raises_type_error():
    with pytest.raises(InvalidArgument):
        Stream([])[u'kittens']
Beispiel #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
Beispiel #7
0
def test_thunking_evaluates_initial_list():
    x = Stream([1, 2, 3])
    x._thunk_to(1)
    assert len(x.fetched) == 1
Beispiel #8
0
def test_cannot_thunk_past_end_of_list():
    with pytest.raises(IndexError):
        Stream([1])._thunk_to(5)
Beispiel #9
0
def test_can_stream_infinite():
    s = Stream(loop(False))
    assert list(islice(s, 100)) == [False] * 100
Beispiel #10
0
def test_can_zip_streams_with_self(xs):
    s = Stream(iter(xs))
    assert list(zip(s, s)) == list(zip(xs, xs))
Beispiel #11
0
def test_stream_give_lists(xs):
    s = Stream(iter(xs))
    assert list(s) == xs
    assert list(s) == xs
Beispiel #12
0
def test_default_stream_is_empty():
    assert list(Stream()) == []
def test_can_slice_streams():
    assert list(Stream([1, 2, 3])[:2]) == [1, 2]
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
def test_thunking_evaluates_initial_list():
    x = Stream([1, 2, 3])
    x._thunk_to(1)
    assert len(x.fetched) == 1
Beispiel #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]