blob: 51be1948ab8ea045e8d0a7d1c55a82c2cb014a97 [file] [log] [blame]
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from gppylib.operations import Operation
"""
These objects needed for gppylib.operations.test.test_utils are pulled out of said file for
pickle/import/visibility reasons. See gppylib.operations.utils.RemoteOperation, #4.
"""
class TestOperation(Operation):
def execute(self):
return 1
class MyException(Exception): pass
class RaiseOperation(Operation):
def execute(self):
raise MyException()
# Exceptions cannot be nested.
# They cannot be pickled for reasons inherent to python. See utils.py
class RaiseOperation_Nested(Operation):
def execute(self):
raise RaiseOperation_Nested.MyException2()
class MyException2(Exception): pass
# Exceptions with args must follow a strange idiom! http://bugs.python.org/issue1692335
class RaiseOperation_Unsafe(Operation):
def execute(self):
raise ExceptionWithArgsUnsafe(1, 2)
class RaiseOperation_Safe(Operation):
def execute(self):
raise ExceptionWithArgs(1, 2)
# This is the proper idiom for a pickle-able exception with arguments: http://bugs.python.org/issue1692335
class ExceptionWithArgs(Exception):
def __init__(self, x, y):
self.x, self.y = x, y
Exception.__init__(self, x, y)
class ExceptionWithArgsUnsafe(Exception):
def __init__(self, x, y):
self.x, self.y = x, y
class RaiseOperation_Unpicklable(Operation):
def execute(self):
from pygresql import pg
raise pg.DatabaseError()