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