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']
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
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]
def create_pipe(self, name): self.pipes[name] = Pipeline(name) LOG.info("Creating new pipe '%s'", name) return self.pipes[name]
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]
def test_define_multistage_pipeline(self, mypipe: Pipeline): mypipe.register(double_even_item) mypipe.register(add_one) mypipe.register(DropEveryFifthItem())
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]
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]
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]
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]
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]