def test_multiple_processor_error(exception_class, expected_exception_class): processor = MultipleProcessor( lambda x: raise_(exception_class, 'invalid_value'), lambda x: x.lower()) with pytest.raises(expected_exception_class): processor('value')
class Parser(BaseParser): columns = [ Column('first_name', index=0), Column('last_name', index=1), Column('age', index=2, processor=lambda x: x if isinstance(x, int) else raise_(ColumnError())), ]
assert exc_info.value.messages == [ 'Not processed because the string contains errors.' ] assert result == { 'first_name': 'Ivan', 'last_name': 'Ivanov', 'age': 34, 'row_index': 1, } @pytest.mark.parametrize( 'column_processor, expected_exception', ( (lambda x: raise_(StopParsing, 'invalid_column_value'), StopParsing), (lambda x: raise_(ColumnError, 'invalid_column_value'), ColumnError), (lambda x: raise_(ValueError), ColumnError), (lambda x: raise_(TypeError), ColumnError), (lambda x: raise_(Exception), ColumnError), ), ) def test_parse_column_exceptions(column_processor, expected_exception, row_factory): class Parser(BaseParser): columns = [Column('column_name', index=0, processor=column_processor)] parser = Parser(None) row = row_factory([0]) with pytest.raises(expected_exception):