from director_exception import *
class MyException(Exception):
def __init__(self, a, b):
self.msg = a + b
class MyFoo(Foo):
def ping(self):
raise NotImplementedError("MyFoo::ping() EXCEPTION")
class MyFoo2(Foo):
def ping(self):
return True
pass
class MyFoo3(Foo):
def ping(self):
raise MyException("foo", "bar")
class MyFoo4(Foo):
def ping(self, *args):
t = type("bad", "call")
return "Foo4.ping"
a = MyFoo()
b = launder(a)
try:
b.pong()
raise RuntimeError("Exception was not thrown")
except NotImplementedError as e:
if not str(e) == "MyFoo::ping() EXCEPTION":
raise RuntimeError("Unexpected error message: %s" % str(e))
except TypeError:
pass
a = MyFoo2()
b = launder(a)
try:
b.pong()
raise RuntimeError("Exception was not thrown")
except TypeError as e:
if not str(e).startswith("SWIG director type mismatch in output value of type 'std::string'"):
raise RuntimeError("Unexpected error message: %s" % str(e))
a = MyFoo3()
b = launder(a)
try:
b.pong()
raise RuntimeError("Exception was not thrown")
except MyException as e:
if e.msg != "foobar":
raise RuntimeError("Unexpected error message: %s" % str(e))
a = MyFoo4()
b = launder(a)
try:
b.pong()
raise RuntimeError("Exception was not thrown")
except TypeError as e:
if not str(e).startswith("type() takes 1 or 3 arguments"):
raise RuntimeError("Unexpected error message: %s" % str(e))
if not is_python_builtin():
try:
raise Exception2()
except Exception2:
pass
try:
raise Exception1()
except Exception1:
pass