コード例 #1
0
def test_chunk_size():
    assert (DistributedQuery(range(100), processes=2,
                             chunk_size=23).select(square).count() == 100)
    assert (DistributedQuery(range(10000), processes=2,
                             chunk_size=70).select(square).count() == 10000)
    assert (DistributedQuery(range(100), processes=2,
                             chunk_size=1000).select(square).count() == 100)
コード例 #2
0
def test_first_or_none():
    assert DistributedQuery(range(100),
                            processes=2).first_or_none(greater_than_0) > 0

    assert (DistributedQuery(
        range(100),
        processes=2).select(negative_square).first_or_none(greater_than_0) is
            None)
コード例 #3
0
def test_distributed_query_multiple_processes():
    assert DistributedQuery(range(100), processes=2).select(square).min() == 0
コード例 #4
0
def test_flatten():
    y = (DistributedQuery([[1, 2, 3], [4, 5, 6], [7, 8, 9]],
                          processes=2).flatten().to_list())
    for x in range(1, 10):
        assert x in y
コード例 #5
0
def test_contains_2():
    assert not DistributedQuery(range(100), processes=2).contains(-1)
コード例 #6
0
def test_where():
    assert (DistributedQuery(range(100),
                             processes=2).where(smaller_than_10).count() == 10)
コード例 #7
0
def test_any_2():
    assert (not DistributedQuery(range(
        10, 100), processes=2).select(add_1).any(smaller_than_10))
コード例 #8
0
def test_all_2():
    assert not DistributedQuery(range(100), processes=2).all(smaller_than_10)
コード例 #9
0
def test_context_manager():
    with DistributedQuery(range(100), processes=2) as q:
        next(iter(q))
コード例 #10
0
def test_last():
    with pytest.raises(errors.NoSuchElementError):
        DistributedQuery(
            range(100),
            processes=2).select(negative_square).last(greater_than_0)
コード例 #11
0
def test_take_one_and_close():
    q = DistributedQuery(range(100), processes=4)
    iterator = iter(q)
    next(iterator)
    q.close()
コード例 #12
0
def test_argmin():
    assert DistributedQuery(range(-4, 5)).argmin(square) == 0
コード例 #13
0
def test_argmax():
    assert DistributedQuery(range(-4, 5)).argmax(negative_square) == 0
コード例 #14
0
def test_long_query():
    assert (DistributedQuery(range(100), processes=2).select(square).where(
        smaller_than_10).select(square).where(greater_than_0).count() == 3)
コード例 #15
0
def test_sum():
    assert DistributedQuery(range(100), processes=2).sum() == 4950
コード例 #16
0
def test_all_1():
    assert DistributedQuery(range(100),
                            processes=2).select(add_1).all(greater_than_0)
コード例 #17
0
def test_mean():
    assert DistributedQuery(range(100),
                            processes=2).select(square).mean() == 3283.5
コード例 #18
0
def test_any_1():
    assert DistributedQuery(range(100),
                            processes=2).select(square).any(greater_than_0)
コード例 #19
0
def test_to_dict():
    dict_ = DistributedQuery(range(100), processes=2).to_dict(str, square)
    assert set(dict_.keys()) == {str(x) for x in range(100)}
    assert set(dict_.values()) == {x**2 for x in range(100)}
コード例 #20
0
def test_count():
    assert DistributedQuery(range(100), processes=2).count() == 100
コード例 #21
0
def test_sleep():
    assert DistributedQuery(range(9), processes=3).select(wait).count() == 9
コード例 #22
0
def test_contains_1():
    assert DistributedQuery(range(100), processes=2).contains(50)
コード例 #23
0
def test_distributed_query_single_process():
    assert DistributedQuery(range(100),
                            processes=1).select(square).max() == 99**2
コード例 #24
0
def test_contains_3():
    assert 50 in DistributedQuery(range(100), processes=2)
コード例 #25
0
def test_contains_4():
    assert -1 not in DistributedQuery(range(100), processes=2)