Exemplo n.º 1
0
 def test_readme_quick_tutorial_pipeline(self, mypipe: Pipeline):
     mypipe.register(double_even_item)
     mypipe.register(add_one)
     mypipe.register(DropEveryFifthItem())
     result = mypipe.process([1, 2, 3, 4, 5, 6])
     assert isinstance(result, types.GeneratorType)
     assert list(result) == [2, 3, 3, 4, 5, 6, 7, 7]
Exemplo n.º 2
0
    def test_more_useful_handler(self, mypipe: Pipeline):
        problem_items = []
        def handler(stage, item, exc):
            # array elements disappear if they are not copied
            problem_items.append((exc, item[:]))

        int_stage = mypipe.register(sum, group_size=2)
        int_stage.exception(handler)

        list(mypipe.process([1, 2, 3, '4', 5, 6]))
        assert len(problem_items) == 1
        assert isinstance(problem_items[0][0], TypeError)
        assert problem_items[0][1] == [3, '4']
Exemplo n.º 3
0
    def test_more_useful_handler(self, mypipe: Pipeline):
        problem_items = []
        def handler(stage, item, exc):
            problem_items.append((exc, item))

        int_stage = mypipe.register(lambda val: int(val))
        int_stage.exception(handler)

        list(mypipe.process(['10', 5, 'hej', tuple, '2']))
        assert len(problem_items) == 2
        assert isinstance(problem_items[0][0], ValueError)
        assert problem_items[0][1] == 'hej'
        assert isinstance(problem_items[1][0], TypeError)
        assert problem_items[1][1] == tuple
Exemplo n.º 4
0
def test_drop_none_items(mypipe: Pipeline):
    drop_even = lambda num: num if num % 2 == 1 else None
    mypipe.register(drop_even)
    result = mypipe.process([1, 2, 3, 4, 5])
    assert list(result) == [1, 3, 5]
Exemplo n.º 5
0
 def test_can_ignore_errors(self, mypipe: Pipeline):
     int_stage = mypipe.register(sum, group_size=2)
     int_stage.exception(lambda *args: None)
     result = mypipe.process([1, 2, 3, '4', 5, 6])
     assert list(result) == [3, 11]
Exemplo n.º 6
0
 def test_can_ignore_errors(self, mypipe: Pipeline):
     int_stage = mypipe.register(lambda val: int(val))
     int_stage.exception(lambda *args: None)
     result = mypipe.process(['10', 5, 'hej', tuple, '2'])
     assert list(result) == [10, 5, 2]
Exemplo n.º 7
0
 def test_group_size_is_not_divisible_with_input_size(self, mypipe: Pipeline):
     mypipe.register(sum, group_size=6)
     result = mypipe.process([1, 2, 3, 4, 5, 6, 7])
     assert list(result) == [21, 7]
Exemplo n.º 8
0
 def test_group_size_bigger_than_input_list(self, mypipe: Pipeline):
     mypipe.register(sum, group_size=6)
     result = mypipe.process([1, 2, 3, 4, 5])
     assert list(result) == [15]
Exemplo n.º 9
0
 def test_register_method_with_group_option(self, mypipe: Pipeline):
     mypipe.register(sum, group_size=2)
     result = mypipe.process([1, 2, 3, 4])
     assert list(result) == [3, 7]