예제 #1
0
def test_creates_json_with_empty_list(tmpdir):
    target = join(tmpdir, 'list.json')

    _empty_pype().to_json(target, as_dict=False)

    with open(target) as file:
        assert json.load(file) == []
예제 #2
0
def test_creates_json_with_empty_object(tmpdir):
    target = join(tmpdir, 'object.json')

    _empty_pype().to_json(target)

    with open(target) as file:
        assert json.load(file) == {}
예제 #3
0
def test_creates_file_but_does_not_write_anything_to_it(tmpdir):
    target = join(tmpdir, 'strings.txt')

    _empty_pype().to_file(target)

    with open(target) as file:
        assert file.readlines() == []
예제 #4
0
def test_interleaving_with_an_iterable_with_skipping_returns_back_the_iterable_as_a_pipe(
):
    pipe = _empty_pype()
    other_pipe = _a_fun_day_pype()

    assert tuple(pipe.interleave(other_pipe,
                                 trunc=False)) == ('a', 'fun', 'day')
예제 #5
0
def test_teeing_returns_a_pipe_with_n_empty_pipes():
    assert tuple(map(tuple, _empty_pype().tee(3))) == ((), (), ())
예제 #6
0
def test_interleaving_with_an_empty_iterable_with_truncation_returns_an_empty_pipe(
):
    assert tuple(_123_pype().interleave(_empty_pype(), trunc=True)) == ()
예제 #7
0
def test_dropping_last_n_items_returns_an_empty_pipe():
    assert tuple(_empty_pype().drop(-1)) == ()
예제 #8
0
def test_produces_no_side_effect_when_immediate():
    side_effect = create_autospec(lambda n: n)

    assert tuple(_empty_pype().do(side_effect, now=True)) == ()

    side_effect.assert_not_called()
예제 #9
0
def test_dividing_pipe_returns_a_pipe_with_n_empty_pipes():
    assert tuple(map(tuple, tuple(_empty_pype().divide(3)))) == ((), (), ())
예제 #10
0
def test_infinite_cycling_returns_empty_pipe():
    assert tuple(_empty_pype().cycle()) == ()
예제 #11
0
def test_chunking_with_multiple_sizes_returns_as_many_empty_pipes_as_there_are_sizes(
):
    assert tuple(map(tuple, _empty_pype().chunk([2, 3]))) == ((), ())
예제 #12
0
def test_asking_for_top_items_returns_empty_pipe():
    assert tuple(_empty_pype().top(2)) == ()
예제 #13
0
def test_broadcasting_returns_empty_pype():
    assert tuple(_empty_pype().broadcast(range)) == ()
예제 #14
0
def test_applies_functions_to_itself():
    assert _empty_pype().to(list, sorted) == []
예제 #15
0
def test_applies_function_to_itself():
    assert _empty_pype().to(Pype.size) == 0
예제 #16
0
def test_zipping_with_a_function_returns_an_empty_pipe():
    assert tuple(_empty_pype().zip_with(lambda n: n * 2)) == ()
예제 #17
0
def test_chunking_returns_empty_pipe():
    assert tuple(_empty_pype().chunk(2)) == ()
예제 #18
0
def test_asking_for_the_unique_items_returns_an_empty_pipe():
    assert tuple(_empty_pype().uniq()) == ()
예제 #19
0
def test_cloning_returns_empty_pipe():
    assert tuple(_empty_pype().clone()) == ()
예제 #20
0
def test_unzipping_returns_an_empty_pipe():
    assert tuple(map(tuple, _empty_pype().unzip())) == ()
예제 #21
0
def test_distributing_items_returns_pipe_with_n_empty_pipes():
    assert tuple(map(tuple, tuple(_empty_pype().dist(3)))) == ((), (), ())
예제 #22
0
def test_sliding_a_window_of_size_0_over_items_returns_a_pipe_with_empty_window(
):
    assert tuple(map(tuple, _empty_pype().window(0))) == ((), )
예제 #23
0
def test_produces_no_side_effect():
    side_effect = create_autospec(lambda n: n)

    assert tuple(_empty_pype().do(side_effect)) == ()

    side_effect.assert_not_called()
예제 #24
0
def test_sliding_a_window_of_size_greater_than_0_over_items_returns_a_pipe_with_a_None_filled_window(
):
    assert tuple(map(tuple, _empty_pype().window(2))) == ((None, None), )
예제 #25
0
def test_produces_no_side_effect_when_run_in_parallel():
    side_effect = create_autospec(lambda n: n)

    assert tuple(_empty_pype().do(side_effect, now=True, workers=2)) == ()

    side_effect.assert_not_called()
예제 #26
0
def test_zipping_with_a_non_empty_iterable_returns_an_empty_iterable():
    assert tuple(_empty_pype().zip(_123_pype())) == ()
예제 #27
0
def test_interleaving_with_an_empty_iterable_skipping_items_returns_this_pipe(
):
    assert tuple(_123_pype().interleave(_empty_pype(), trunc=False)) == _123
예제 #28
0
def test_non_truncating_zipping_with_a_non_empty_iterable_returns_that_iterable_paired_with_the_pad_value(
):
    assert tuple(_empty_pype().zip(_123_pype(), trunc=False,
                                   pad=-1)) == ((-1, 1), (-1, 2), (-1, 3))
예제 #29
0
def test_concatenation_with_an_empty_iterable_returns_this_pipe():
    assert tuple(_123_pype().cat(_empty_pype())) == _123
예제 #30
0
def test_zipping_with_itself_returns_an_empty_pipe():
    assert tuple(_empty_pype().zip()) == ()