Exemple #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) == []
Exemple #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) == {}
Exemple #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() == []
Exemple #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')
Exemple #5
0
def test_teeing_returns_a_pipe_with_n_empty_pipes():
    assert tuple(map(tuple, _empty_pype().tee(3))) == ((), (), ())
def test_interleaving_with_an_empty_iterable_with_truncation_returns_an_empty_pipe(
):
    assert tuple(_123_pype().interleave(_empty_pype(), trunc=True)) == ()
Exemple #7
0
def test_dropping_last_n_items_returns_an_empty_pipe():
    assert tuple(_empty_pype().drop(-1)) == ()
Exemple #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()
Exemple #9
0
def test_dividing_pipe_returns_a_pipe_with_n_empty_pipes():
    assert tuple(map(tuple, tuple(_empty_pype().divide(3)))) == ((), (), ())
Exemple #10
0
def test_infinite_cycling_returns_empty_pipe():
    assert tuple(_empty_pype().cycle()) == ()
Exemple #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]))) == ((), ())
Exemple #12
0
def test_asking_for_top_items_returns_empty_pipe():
    assert tuple(_empty_pype().top(2)) == ()
Exemple #13
0
def test_broadcasting_returns_empty_pype():
    assert tuple(_empty_pype().broadcast(range)) == ()
Exemple #14
0
def test_applies_functions_to_itself():
    assert _empty_pype().to(list, sorted) == []
Exemple #15
0
def test_applies_function_to_itself():
    assert _empty_pype().to(Pype.size) == 0
Exemple #16
0
def test_zipping_with_a_function_returns_an_empty_pipe():
    assert tuple(_empty_pype().zip_with(lambda n: n * 2)) == ()
Exemple #17
0
def test_chunking_returns_empty_pipe():
    assert tuple(_empty_pype().chunk(2)) == ()
Exemple #18
0
def test_asking_for_the_unique_items_returns_an_empty_pipe():
    assert tuple(_empty_pype().uniq()) == ()
Exemple #19
0
def test_cloning_returns_empty_pipe():
    assert tuple(_empty_pype().clone()) == ()
Exemple #20
0
def test_unzipping_returns_an_empty_pipe():
    assert tuple(map(tuple, _empty_pype().unzip())) == ()
Exemple #21
0
def test_distributing_items_returns_pipe_with_n_empty_pipes():
    assert tuple(map(tuple, tuple(_empty_pype().dist(3)))) == ((), (), ())
Exemple #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))) == ((), )
Exemple #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()
Exemple #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), )
Exemple #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()
Exemple #26
0
def test_zipping_with_a_non_empty_iterable_returns_an_empty_iterable():
    assert tuple(_empty_pype().zip(_123_pype())) == ()
def test_interleaving_with_an_empty_iterable_skipping_items_returns_this_pipe(
):
    assert tuple(_123_pype().interleave(_empty_pype(), trunc=False)) == _123
Exemple #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))
def test_concatenation_with_an_empty_iterable_returns_this_pipe():
    assert tuple(_123_pype().cat(_empty_pype())) == _123
Exemple #30
0
def test_zipping_with_itself_returns_an_empty_pipe():
    assert tuple(_empty_pype().zip()) == ()