示例#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()) == ()