def test_prints_each_item_using_str(): mock_stdout = Mock(spec_set=sys.stdout) _a_fun_day_pype().print(file=mock_stdout) mock_stdout.write.assert_has_calls([ call('a'), call('\n'), call('fun'), call('\n'), call('day'), call('\n') ])
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_grouping_by_key_consumes_pipe(): pipe = _a_fun_day_pype() next(iter(pipe.group_by(len))) assert tuple(pipe) == ()
def test_self_zipping_with_different_sized_items_gives_pipe_with_items_the_size_of_the_longest_one_with_padding( ): assert tuple(_a_fun_day_pype().zip(trunc=False, pad='?')) == (('a', 'f', 'd'), ('?', 'u', 'a'), ('?', 'n', 'y'))
def test_sorts_items(): assert tuple(_a_fun_day_pype().sort()) == ('a', 'day', 'fun')
def test_interleaves_items_with_other_iterable_truncating_to_shortest(): assert tuple(_123_pype().interleave(_a_fun_day_pype(), n=2)) == (1, 2, 'a', 3, 'fun')
def test_transforms_iterable_items_and_flattens_them_into_a_pipe_of_elements(): assert tuple(_a_fun_day_pype().flatmap(str.upper)) == ('A', 'F', 'U', 'N', 'D', 'A', 'Y')
def test_enumerates_items_with_a_swapped_index(): assert tuple(_a_fun_day_pype().enum(start=1, swap=True)) == (('a', 1), ('fun', 2), ('day', 3))
def test_zipping_with_function_fails_with_non_callable_functions(fn): """""" with raises(TypeError): tuple(_a_fun_day_pype().zip_with(fn))
def test_interleaving_fails_with_non_int_n(n): """""" with raises(TypeError): tuple(_123_pype().interleave(_a_fun_day_pype(), n=n))
def test_interleaving_fails_with_non_positive_int(n): """""" with raises(ValueError): tuple(_123_pype().interleave(_a_fun_day_pype(), n=n))
def test_flatmapping_fails_with_non_callable_mappings(fn): """""" with raises(TypeError): tuple(_a_fun_day_pype().flatmap(fn))
def test_zipping_with_a_function_does_not_consume_pipe(): pipe = _a_fun_day_pype() next(iter(pipe.zip_with(len))) assert tuple(pipe) == _fun_day
def test_roundrobin_distribution_consumes_pipe(): pipe = _a_fun_day_pype() next(iter(pipe.roundrobin())) assert tuple(pipe) == ()
def test_interleaves_items_with_other_iterable_does_not_consume_pipe(): pipe = _123_pype() next(iter(pipe.interleave(_a_fun_day_pype()))) assert tuple(pipe) == _23
def test_zipping_with_function_is_deferred(): pipe = _a_fun_day_pype() pipe.zip_with(len) assert tuple(pipe) == _a_fun_day
def test_enumerates_items(): assert tuple(_a_fun_day_pype().enum(start=1)) == ((1, 'a'), (2, 'fun'), (3, 'day'))
def test_flattening_is_deferred(): pipe = _a_fun_day_pype() pipe.flat() assert tuple(pipe) == _a_fun_day
def test_flattens_pipe_of_iterables_into_a_single_iterable(): assert tuple(_a_fun_day_pype().flat()) == ('a', 'f', 'u', 'n', 'd', 'a', 'y')
def test_flatmapping_is_deferred(): pipe = _a_fun_day_pype() pipe.flatmap(str.upper) assert tuple(pipe) == _a_fun_day
def test_groups_items_by_given_key(): assert tuple(_a_fun_day_pype().group_by(len)) == ((1, ['a']), (3, ['fun', 'day']))
def test_computing_item_frequencies_is_deferred(): pipe = _a_fun_day_pype() pipe.freqs() assert tuple(pipe) == _a_fun_day
def test_interleaves_items_with_other_iterable_skipping_items_if_other_pipe_is_exhausted( ): assert tuple(_123_pype().interleave(_a_fun_day_pype(), n=2, trunc=False)) == (1, 2, 'a', 3, 'fun', 'day')
def test_grouping_by_key_is_deferred(): pipe = _a_fun_day_pype() pipe.group_by(len) assert tuple(pipe) == _a_fun_day
def test_returns_iterable_items_elements_in_a_roundrobin_fashion(): assert tuple(_a_fun_day_pype().roundrobin()) == ('a', 'f', 'd', 'u', 'a', 'n', 'y')
def test_interleaves_items_with_other_iterable_is_deferred(): pipe = _123_pype() pipe.interleave(_a_fun_day_pype(), trunc=False) assert tuple(pipe) == _123
def test_sorts_items_in_reverse_order(): assert tuple(_a_fun_day_pype().sort(rev=True)) == ('fun', 'day', 'a')
def test_distributing_roundrobin_is_deferred(): pipe = _a_fun_day_pype() pipe.roundrobin() assert tuple(pipe) == _a_fun_day
def test_self_zipping_with_a_function_pairs_items_with_output_of_said_function( ): assert tuple(_a_fun_day_pype().zip_with(len)) == (('a', 1), ('fun', 3), ('day', 3))
def test_self_zipping_is_deferred(): pipe = _a_fun_day_pype() pipe.zip() assert tuple(pipe) == _a_fun_day