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) == []
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) == {}
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() == []
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')
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)) == ()
def test_dropping_last_n_items_returns_an_empty_pipe(): assert tuple(_empty_pype().drop(-1)) == ()
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()
def test_dividing_pipe_returns_a_pipe_with_n_empty_pipes(): assert tuple(map(tuple, tuple(_empty_pype().divide(3)))) == ((), (), ())
def test_infinite_cycling_returns_empty_pipe(): assert tuple(_empty_pype().cycle()) == ()
def test_chunking_with_multiple_sizes_returns_as_many_empty_pipes_as_there_are_sizes( ): assert tuple(map(tuple, _empty_pype().chunk([2, 3]))) == ((), ())
def test_asking_for_top_items_returns_empty_pipe(): assert tuple(_empty_pype().top(2)) == ()
def test_broadcasting_returns_empty_pype(): assert tuple(_empty_pype().broadcast(range)) == ()
def test_applies_functions_to_itself(): assert _empty_pype().to(list, sorted) == []
def test_applies_function_to_itself(): assert _empty_pype().to(Pype.size) == 0
def test_zipping_with_a_function_returns_an_empty_pipe(): assert tuple(_empty_pype().zip_with(lambda n: n * 2)) == ()
def test_chunking_returns_empty_pipe(): assert tuple(_empty_pype().chunk(2)) == ()
def test_asking_for_the_unique_items_returns_an_empty_pipe(): assert tuple(_empty_pype().uniq()) == ()
def test_cloning_returns_empty_pipe(): assert tuple(_empty_pype().clone()) == ()
def test_unzipping_returns_an_empty_pipe(): assert tuple(map(tuple, _empty_pype().unzip())) == ()
def test_distributing_items_returns_pipe_with_n_empty_pipes(): assert tuple(map(tuple, tuple(_empty_pype().dist(3)))) == ((), (), ())
def test_sliding_a_window_of_size_0_over_items_returns_a_pipe_with_empty_window( ): assert tuple(map(tuple, _empty_pype().window(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()
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), )
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()
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
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
def test_zipping_with_itself_returns_an_empty_pipe(): assert tuple(_empty_pype().zip()) == ()