Merge branch 'remove-dependency-on-2to3'

* remove-dependency-on-2to3:
  Remove need for Python 2to3
  Modify examples to be both Python 2 and 3 compatible
  Remove python3 specific runme3.py test files
  Convert python tests using 2to3
  Convert python test scripts to be Python 2 and 3 compatible
  Convert swigobject python test to be python 2 and 3 compatible
  Convert two tests to work with both Python 2 and 3
  Improve director_exception Python test
  Remove further print statements from Python tests
  Improve Python testing catching exceptions
  Improve contract Python testcase testing
  Remove print statements from Python tests
This commit is contained in:
William S Fulton 2020-08-15 19:03:38 +01:00
commit baec830f75
147 changed files with 1193 additions and 1427 deletions

View file

@ -7,6 +7,10 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
Version 4.1.0 (in progress) Version 4.1.0 (in progress)
=========================== ===========================
2020-08-15: wsfulton
[Python] All Python examples and tests are written to be Python 2 and Python 3
compatible, removing the need for 2to3 to run the examples or test-suite.
2020-08-13: wsfulton 2020-08-13: wsfulton
[C#] Add support for void *VOID_INT_PTR for member variables. [C#] Add support for void *VOID_INT_PTR for member variables.

View file

@ -381,13 +381,7 @@ python_static_cpp: $(SRCDIR_SRCS)
# Running a Python example # Running a Python example
# ----------------------------------------------------------------- # -----------------------------------------------------------------
ifeq (,$(PY3)) PYSCRIPT = $(RUNME).py
PYSCRIPT = $(RUNME).py
else
PYSCRIPT = $(RUNME)3.py
endif
PY2TO3 = @PY2TO3@ `@PY2TO3@ -l | grep -v -E "Available|import$$" | awk '{print "-f "$$0}'`
python_run: $(PYSCRIPT) python_run: $(PYSCRIPT)
ifneq (,$(PYCODESTYLE)) ifneq (,$(PYCODESTYLE))
@ -400,10 +394,6 @@ $(RUNME).py: $(SRCDIR)$(RUNME).py
cp $< $@ cp $< $@
endif endif
$(RUNME)3.py: $(SRCDIR)$(RUNME).py
cp $< $@
$(PY2TO3) -w $@ >/dev/null 2>&1
# ----------------------------------------------------------------- # -----------------------------------------------------------------
# Version display # Version display
# ----------------------------------------------------------------- # -----------------------------------------------------------------
@ -421,7 +411,6 @@ python_clean:
rm -f core @EXTRA_CLEAN@ rm -f core @EXTRA_CLEAN@
rm -f *.@OBJEXT@ *@SO@ *$(PYTHON_SO) rm -f *.@OBJEXT@ *@SO@ *$(PYTHON_SO)
rm -f $(TARGET).py rm -f $(TARGET).py
if test -f $(SRCDIR)$(RUNME).py; then rm -f $(RUNME)3.py $(RUNME)3.py.bak; fi
case "x$(SRCDIR)" in x|x./);; *) rm -f $(RUNME).py;; esac case "x$(SRCDIR)" in x|x./);; *) rm -f $(RUNME).py;; esac

View file

@ -11,7 +11,7 @@ class PyCallback(example.Callback):
example.Callback.__init__(self) example.Callback.__init__(self)
def run(self): def run(self):
print "PyCallback.run()" print("PyCallback.run()")
# Create an Caller instance # Create an Caller instance
@ -20,8 +20,8 @@ caller = example.Caller()
# Add a simple C++ callback (caller owns the callback, so # Add a simple C++ callback (caller owns the callback, so
# we disown it first by clearing the .thisown flag). # we disown it first by clearing the .thisown flag).
print "Adding and calling a normal C++ callback" print("Adding and calling a normal C++ callback")
print "----------------------------------------" print("----------------------------------------")
callback = example.Callback() callback = example.Callback()
callback.thisown = 0 callback.thisown = 0
@ -29,9 +29,9 @@ caller.setCallback(callback)
caller.call() caller.call()
caller.delCallback() caller.delCallback()
print print("")
print "Adding and calling a Python callback" print("Adding and calling a Python callback")
print "------------------------------------" print("------------------------------------")
# Add a Python callback (caller owns the callback, so we # Add a Python callback (caller owns the callback, so we
# disown it first by calling __disown__). # disown it first by calling __disown__).
@ -40,9 +40,9 @@ caller.setCallback(PyCallback().__disown__())
caller.call() caller.call()
caller.delCallback() caller.delCallback()
print print("")
print "Adding and calling another Python callback" print("Adding and calling another Python callback")
print "------------------------------------------" print("------------------------------------------")
# Let's do the same but use the weak reference this time. # Let's do the same but use the weak reference this time.
@ -53,5 +53,5 @@ caller.delCallback()
# All done. # All done.
print print("")
print "python exit" print("python exit")

View file

@ -7,15 +7,15 @@ import example
# ----- Object creation ----- # ----- Object creation -----
print "Creating some objects:" print("Creating some objects:")
c = example.Circle(10) c = example.Circle(10)
print " Created circle", c print(" Created circle %s" % c)
s = example.Square(10) s = example.Square(10)
print " Created square", s print(" Created square %s" % s)
# ----- Access a static member ----- # ----- Access a static member -----
print "\nA total of", example.cvar.Shape_nshapes, "shapes were created" print("\nA total of %d shapes were created" % example.cvar.Shape_nshapes)
# ----- Member data access ----- # ----- Member data access -----
@ -27,25 +27,25 @@ c.y = 30
s.x = -10 s.x = -10
s.y = 5 s.y = 5
print "\nHere is their current position:" print("\nHere is their current position:")
print " Circle = (%f, %f)" % (c.x, c.y) print(" Circle = (%f, %f)" % (c.x, c.y))
print " Square = (%f, %f)" % (s.x, s.y) print(" Square = (%f, %f)" % (s.x, s.y))
# ----- Call some methods ----- # ----- Call some methods -----
print "\nHere are some properties of the shapes:" print("\nHere are some properties of the shapes:")
for o in [c, s]: for o in [c, s]:
print " ", o print(" %s" % o)
print " area = ", o.area() print(" area = %s" % o.area())
print " perimeter = ", o.perimeter() print(" perimeter = %s" % o.perimeter())
# prevent o from holding a reference to the last object looked at # prevent o from holding a reference to the last object looked at
o = None o = None
print "\nGuess I'll clean up now" print("\nGuess I'll clean up now")
# Note: this invokes the virtual destructor # Note: this invokes the virtual destructor
del c del c
del s del s
print example.cvar.Shape_nshapes, "shapes remain" print("%d shapes remain" % example.cvar.Shape_nshapes)
print "Goodbye" print("Goodbye")

View file

@ -2,22 +2,24 @@
import example import example
print "ICONST =", example.ICONST, "(should be 42)" print("ICONST = %s (should be 42)" % example.ICONST)
print "FCONST =", example.FCONST, "(should be 2.1828)" print("FCONST = %s (should be 2.1828)" % example.FCONST)
print "CCONST =", example.CCONST, "(should be 'x')" print("CCONST = %s (should be 'x')" % example.CCONST)
print "CCONST2 =", example.CCONST2, "(this should be on a new line)" print("CCONST2 = %s (this should be on a new line)" % example.CCONST2)
print "SCONST =", example.SCONST, "(should be 'Hello World')" print("SCONST = %s (should be 'Hello World')" % example.SCONST)
print "SCONST2 =", example.SCONST2, "(should be '\"Hello World\"')" print("SCONST2 = %s (should be '\"Hello World\"')" % example.SCONST2)
print "EXPR =", example.EXPR, "(should be 48.5484)" print("EXPR = %s (should be 48.5484)" % example.EXPR)
print "iconst =", example.iconst, "(should be 37)" print("iconst = %s (should be 37)" % example.iconst)
print "fconst =", example.fconst, "(should be 3.14)" print("fconst = %s (should be 3.14)" % example.fconst)
try: try:
print "EXTERN = ", example.EXTERN, "(Arg! This shouldn't print anything)" x = example.EXTERN
print("%s (Arg! This shouldn't print anything)" % x)
except AttributeError: except AttributeError:
print "EXTERN isn't defined (good)" print("EXTERN isn't defined (good)")
try: try:
print "FOO = ", example.FOO, "(Arg! This shouldn't print anything)" x = example.FOO
print("%s (Arg! This shouldn't print anything)" % x)
except AttributeError: except AttributeError:
print "FOO isn't defined (good)" print("FOO isn't defined (good)")

View file

@ -7,15 +7,15 @@ import example
x = 42 x = 42
y = 105 y = 105
g = example.gcd(x, y) g = example.gcd(x, y)
print "The gcd of %d and %d is %d" % (x, y, g) print("The gcd of %d and %d is %d" % (x, y, g))
# Manipulate the Foo global variable # Manipulate the Foo global variable
# Output its current value # Output its current value
print "Foo = ", example.cvar.Foo print("Foo = %s" % example.cvar.Foo)
# Change its value # Change its value
example.cvar.Foo = 3.1415926 example.cvar.Foo = 3.1415926
# See if the change took effect # See if the change took effect
print "Foo = ", example.cvar.Foo print("Foo = %s" % example.cvar.Foo)

View file

@ -2,4 +2,4 @@
import example import example
print "example.Foo.bar.__doc__ =", repr(example.Foo.bar.__doc__), "(Should be 'No comment')" print("example.Foo.bar.__doc__ = %s (Should be 'No comment')" % repr(example.Foo.bar.__doc__))

View file

@ -5,24 +5,24 @@
import example import example
print "Creating some objects:" print("Creating some objects:")
c = example.MakeCircle(10) c = example.MakeCircle(10)
print " Created circle", c print(" Created circle %s" % c)
s = example.MakeSquare(10) s = example.MakeSquare(10)
print " Created square", s print(" Created square %s" % s)
r = example.MakeRectangleInt(10, 20) r = example.MakeRectangleInt(10, 20)
print " Created rectangle", r print(" Created rectangle %s" % r)
print "\nHere are some properties of the shapes:" print("\nHere are some properties of the shapes:")
for o in [c, s, r]: for o in [c, s, r]:
print " ", o print(" %s" % o)
print " area = ", o.area() print(" area = %s" % o.area())
print " perimeter = ", o.perimeter() print(" perimeter = %s" % o.perimeter())
print "\nRunning pydoc, this is the equivalent to executing: pydoc -w ./example.py" print("\nRunning pydoc, this is the equivalent to executing: pydoc -w ./example.py")
import pydoc import pydoc
pydoc.writedoc("example") pydoc.writedoc("example")
print "Open example.html in your browser to view the generated python docs" print("Open example.html in your browser to view the generated python docs")

View file

@ -5,24 +5,24 @@ import example
# ----- Object creation ----- # ----- Object creation -----
# Print out the value of some enums # Print out the value of some enums
print "*** color ***" print("*** color ***")
print " RED =", example.RED print(" RED = %s" % example.RED)
print " BLUE =", example.BLUE print(" BLUE = %s" % example.BLUE)
print " GREEN =", example.GREEN print(" GREEN = %s" % example.GREEN)
print "\n*** Foo::speed ***" print("\n*** Foo::speed ***")
print " Foo_IMPULSE =", example.Foo.IMPULSE print(" Foo_IMPULSE = %s" % example.Foo.IMPULSE)
print " Foo_WARP =", example.Foo.WARP print(" Foo_WARP = %s" % example.Foo.WARP)
print " Foo_LUDICROUS =", example.Foo.LUDICROUS print(" Foo_LUDICROUS = %s" % example.Foo.LUDICROUS)
print "\nTesting use of enums with functions\n" print("\nTesting use of enums with functions\n")
example.enum_test(example.RED, example.Foo.IMPULSE) example.enum_test(example.RED, example.Foo.IMPULSE)
example.enum_test(example.BLUE, example.Foo.WARP) example.enum_test(example.BLUE, example.Foo.WARP)
example.enum_test(example.GREEN, example.Foo.LUDICROUS) example.enum_test(example.GREEN, example.Foo.LUDICROUS)
example.enum_test(1234, 5678) example.enum_test(1234, 5678)
print "\nTesting use of enum with class method" print("\nTesting use of enum with class method")
f = example.Foo() f = example.Foo()
f.enum_test(example.Foo.IMPULSE) f.enum_test(example.Foo.IMPULSE)

View file

@ -7,36 +7,36 @@ import example
t = example.Test() t = example.Test()
try: try:
t.unknown() t.unknown()
except RuntimeError, e: except RuntimeError as e:
print "incomplete type", e.args[0] print("incomplete type %s" % e.args[0])
try: try:
t.simple() t.simple()
except RuntimeError, e: except RuntimeError as e:
print e.args[0] print(e.args[0])
try: try:
t.message() t.message()
except RuntimeError, e: except RuntimeError as e:
print e.args[0] print(e.args[0])
if not example.is_python_builtin(): if not example.is_python_builtin():
try: try:
t.hosed() t.hosed()
except example.Exc, e: except example.Exc as e:
print e.code, e.msg print("%s %s" % (e.code, e.msg))
else: else:
try: try:
t.hosed() t.hosed()
except BaseException, e: except BaseException as e:
# Throwing builtin classes as exceptions not supported (-builtin # Throwing builtin classes as exceptions not supported (-builtin
# option) # option)
print e print(e)
for i in range(1, 4): for i in range(1, 4):
try: try:
t.multi(i) t.multi(i)
except RuntimeError, e: except RuntimeError as e:
print e.args[0] print(e.args[0])
except example.Exc, e: except example.Exc as e:
print e.code, e.msg print("%s %s" % (e.code, e.msg))

View file

@ -2,44 +2,44 @@
import example import example
if example.is_python_builtin(): if example.is_python_builtin():
print "Skipping example: -builtin option does not support %exceptionclass" print("Skipping example: -builtin option does not support %exceptionclass")
exit(0) exit(0)
q = example.intQueue(10) q = example.intQueue(10)
print "Inserting items into intQueue" print("Inserting items into intQueue")
print type(example.FullError) print(type(example.FullError))
try: try:
for i in range(0, 100): for i in range(0, 100):
q.enqueue(i) q.enqueue(i)
except example.FullError, e: except example.FullError as e:
print "Maxsize is", e.maxsize print("Maxsize is %s" % e.maxsize)
print "Removing items" print("Removing items")
try: try:
while 1: while True:
q.dequeue() q.dequeue()
except example.EmptyError, e: except example.EmptyError as e:
pass pass
q = example.doubleQueue(1000) q = example.doubleQueue(1000)
print "Inserting items into doubleQueue" print("Inserting items into doubleQueue")
try: try:
for i in range(0, 10000): for i in range(0, 10000):
q.enqueue(i * 1.5) q.enqueue(i * 1.5)
except example.FullError, e: except example.FullError as e:
print "Maxsize is", e.maxsize print("Maxsize is %s" % e.maxsize)
print "Removing items" print("Removing items")
try: try:
while 1: while True:
q.dequeue() q.dequeue()
except example.EmptyError, e: except example.EmptyError as e:
pass pass

View file

@ -21,9 +21,9 @@ class CEO(example.Manager):
# the director wrappers to call CEO.getPosition. # the director wrappers to call CEO.getPosition.
e = CEO("Alice") e = CEO("Alice")
print e.getName(), "is a", e.getPosition() print("%s is a %s" % (e.getName(), e.getPosition()))
print "Just call her \"%s\"" % e.getTitle() print("Just call her \"%s\"" % e.getTitle())
print "----------------------" print("----------------------")
# Create a new EmployeeList instance. This class does not have a C++ # Create a new EmployeeList instance. This class does not have a C++
@ -40,7 +40,7 @@ list = example.EmployeeList()
e = e.__disown__() e = e.__disown__()
list.addEmployee(e) list.addEmployee(e)
print "----------------------" print("----------------------")
# Now we access the first four items in list (three are C++ objects that # Now we access the first four items in list (three are C++ objects that
# EmployeeList's constructor adds, the last is our CEO). The virtual # EmployeeList's constructor adds, the last is our CEO). The virtual
@ -59,13 +59,13 @@ print "----------------------"
# passes down through the C++ director class to the Python implementation # passes down through the C++ director class to the Python implementation
# in CEO. All this routing takes place transparently. # in CEO. All this routing takes place transparently.
print "(position, title) for items 0-3:" print("(position, title) for items 0-3:")
print " %s, \"%s\"" % (list.get_item(0).getPosition(), list.get_item(0).getTitle()) print(" %s, \"%s\"" % (list.get_item(0).getPosition(), list.get_item(0).getTitle()))
print " %s, \"%s\"" % (list.get_item(1).getPosition(), list.get_item(1).getTitle()) print(" %s, \"%s\"" % (list.get_item(1).getPosition(), list.get_item(1).getTitle()))
print " %s, \"%s\"" % (list.get_item(2).getPosition(), list.get_item(2).getTitle()) print(" %s, \"%s\"" % (list.get_item(2).getPosition(), list.get_item(2).getTitle()))
print " %s, \"%s\"" % (list.get_item(3).getPosition(), list.get_item(3).getTitle()) print(" %s, \"%s\"" % (list.get_item(3).getPosition(), list.get_item(3).getTitle()))
print "----------------------" print("----------------------")
# Time to delete the EmployeeList, which will delete all the Employee* # Time to delete the EmployeeList, which will delete all the Employee*
# items it contains. The last item is our CEO, which gets destroyed as its # items it contains. The last item is our CEO, which gets destroyed as its
@ -75,8 +75,8 @@ print "----------------------"
# usual to destroy the object. # usual to destroy the object.
del list del list
print "----------------------" print("----------------------")
# All done. # All done.
print "python exit" print("python exit")

View file

@ -7,14 +7,14 @@ b = 42
# Now call our C function with a bunch of callbacks # Now call our C function with a bunch of callbacks
print "Trying some C callback functions" print("Trying some C callback functions")
print " a =", a print(" a = %s" % a)
print " b =", b print(" b = %s" % b)
print " ADD(a,b) =", example.do_op(a, b, example.ADD) print(" ADD(a,b) = %s" % example.do_op(a, b, example.ADD))
print " SUB(a,b) =", example.do_op(a, b, example.SUB) print(" SUB(a,b) = %s" % example.do_op(a, b, example.SUB))
print " MUL(a,b) =", example.do_op(a, b, example.MUL) print(" MUL(a,b) = %s" % example.do_op(a, b, example.MUL))
print "Here is what the C callback function objects look like in Python" print("Here is what the C callback function objects look like in Python")
print " ADD =", example.ADD print(" ADD = %s" % example.ADD)
print " SUB =", example.SUB print(" SUB = %s" % example.SUB)
print " MUL =", example.MUL print(" MUL = %s" % example.MUL)

View file

@ -7,18 +7,18 @@ b = 42
# Now call our C function with a bunch of callbacks # Now call our C function with a bunch of callbacks
print "Trying some C callback functions" print("Trying some C callback functions")
print " a =", a print(" a = %s" % a)
print " b =", b print(" b = %s" % b)
print " ADD(a,b) =", example.do_op(a, b, example.ADD) print(" ADD(a,b) = %s" % example.do_op(a, b, example.ADD))
print " SUB(a,b) =", example.do_op(a, b, example.SUB) print(" SUB(a,b) = %s" % example.do_op(a, b, example.SUB))
print " MUL(a,b) =", example.do_op(a, b, example.MUL) print(" MUL(a,b) = %s" % example.do_op(a, b, example.MUL))
print "Here is what the C callback function objects look like in Python" print("Here is what the C callback function objects look like in Python")
print " ADD =", example.ADD print(" ADD = %s" % example.ADD)
print " SUB =", example.SUB print(" SUB = %s" % example.SUB)
print " MUL =", example.MUL print(" MUL = %s" % example.MUL)
print "Call the functions directly..." print("Call the functions directly...")
print " add(a,b) =", example.add(a, b) print(" add(a,b) = %s" % example.add(a, b))
print " sub(a,b) =", example.sub(a, b) print(" sub(a,b) = %s" % example.sub(a, b))

View file

@ -12,5 +12,5 @@ for i in range(0, 100):
a(i) # Note: function call a(i) # Note: function call
b(math.sqrt(i)) # Note: function call b(math.sqrt(i)) # Note: function call
print a.result() print(a.result())
print b.result() print(b.result())

View file

@ -1,15 +1,22 @@
# file: runme.py # file: runme.py
# Test various properties of classes defined in separate modules # Test various properties of classes defined in separate modules
import sys
print("Testing the %import directive")
print "Testing the %import directive"
import base import base
import foo import foo
import bar import bar
import spam import spam
def write_flush(s):
# Python 2/3 compatible write and flush
sys.stdout.write(s)
sys.stdout.flush()
# Create some objects # Create some objects
print "Creating some objects" print("Creating some objects")
a = base.Base() a = base.Base()
b = foo.Foo() b = foo.Foo()
@ -17,91 +24,74 @@ c = bar.Bar()
d = spam.Spam() d = spam.Spam()
# Try calling some methods # Try calling some methods
print "Testing some methods" print("Testing some methods")
print "",
print "Should see 'Base::A' ---> ", write_flush(" Should see 'Base::A' ---> ")
a.A() a.A()
print "Should see 'Base::B' ---> ", write_flush(" Should see 'Base::B' ---> ")
a.B() a.B()
print "Should see 'Foo::A' ---> ", write_flush(" Should see 'Foo::A' ---> ")
b.A() b.A()
print "Should see 'Foo::B' ---> ", write_flush(" Should see 'Foo::B' ---> ")
b.B() b.B()
print "Should see 'Bar::A' ---> ", write_flush(" Should see 'Bar::A' ---> ")
c.A() c.A()
print "Should see 'Bar::B' ---> ", write_flush(" Should see 'Bar::B' ---> ")
c.B() c.B()
print "Should see 'Spam::A' ---> ", write_flush(" Should see 'Spam::A' ---> ")
d.A() d.A()
print "Should see 'Spam::B' ---> ", write_flush(" Should see 'Spam::B' ---> ")
d.B() d.B()
# Try some casts # Try some casts
print "\nTesting some casts\n" print("\nTesting some casts\n")
print "",
x = a.toBase() x = a.toBase()
print "Should see 'Base::A' ---> ", write_flush(" Should see 'Base::A' ---> ")
x.A() x.A()
print "Should see 'Base::B' ---> ", write_flush(" Should see 'Base::B' ---> ")
x.B() x.B()
x = b.toBase() x = b.toBase()
print "Should see 'Foo::A' ---> ", write_flush(" Should see 'Foo::A' ---> ")
x.A() x.A()
print "Should see 'Base::B' ---> ", write_flush(" Should see 'Base::B' ---> ")
x.B() x.B()
x = c.toBase() x = c.toBase()
print "Should see 'Bar::A' ---> ", write_flush(" Should see 'Bar::A' ---> ")
x.A() x.A()
print "Should see 'Base::B' ---> ", write_flush(" Should see 'Base::B' ---> ")
x.B() x.B()
x = d.toBase() x = d.toBase()
print "Should see 'Spam::A' ---> ", write_flush(" Should see 'Spam::A' ---> ")
x.A() x.A()
print "Should see 'Base::B' ---> ", write_flush(" Should see 'Base::B' ---> ")
x.B() x.B()
x = d.toBar() x = d.toBar()
print "Should see 'Bar::B' ---> ", write_flush(" Should see 'Bar::B' ---> ")
x.B() x.B()
print "\nTesting some dynamic casts\n" print("\nTesting some dynamic casts\n")
x = d.toBase() x = d.toBase()
print " Spam -> Base -> Foo : ",
y = foo.Foo_fromBase(x) y = foo.Foo_fromBase(x)
if y: print(" Spam -> Base -> Foo : {} swig".format("bad" if y else "good"))
print "bad swig"
else:
print "good swig"
print " Spam -> Base -> Bar : ",
y = bar.Bar_fromBase(x) y = bar.Bar_fromBase(x)
if y: print(" Spam -> Base -> Bar : {} swig".format("good" if y else "bad"))
print "good swig"
else:
print "bad swig"
print " Spam -> Base -> Spam : ",
y = spam.Spam_fromBase(x) y = spam.Spam_fromBase(x)
if y: print(" Spam -> Base -> Spam : {} swig".format("good" if y else "bad"))
print "good swig"
else:
print "bad swig"
print " Foo -> Spam : ",
y = spam.Spam_fromBase(b) y = spam.Spam_fromBase(b)
if y: print(" Foo -> Spam : {} swig".format("bad" if y else "good"))
print "bad swig"
else:
print "good swig"

View file

@ -6,26 +6,26 @@ def run_except_on_windows(commandline, env=None):
if os.name != "nt" and sys.platform != "cygwin": if os.name != "nt" and sys.platform != "cygwin":
# Strange failures on windows/cygin/mingw # Strange failures on windows/cygin/mingw
subprocess.check_call(commandline, env=env, shell=True) subprocess.check_call(commandline, env=env, shell=True)
print(" Finished running: " + commandline) print((" Finished running: " + commandline))
# Test import of modules content from within __init__.py # Test import of modules content from within __init__.py
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__))) testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py" print("Testing " + testname + " - %module(package=...) + python 'import' in __init__.py")
if sys.version_info < (2, 5): if sys.version_info < (2, 5):
print " Skipping test as Python version is < 2.5 and does not support relative import syntax: 'from . import x'" print(" Skipping test as Python version is < 2.5 and does not support relative import syntax: 'from . import x'")
sys.exit(0) sys.exit(0)
if sys.version_info < (3, 0): if sys.version_info < (3, 0):
import py2.pkg2 import py2.pkg2
print " Finished importing py2.pkg2" print(" Finished importing py2.pkg2")
commandline = sys.executable + " -m py2.pkg2.bar" commandline = sys.executable + " -m py2.pkg2.bar"
run_except_on_windows(commandline) run_except_on_windows(commandline)
commandline = sys.executable + " -m py2.pkg2.foo" commandline = sys.executable + " -m py2.pkg2.foo"
run_except_on_windows(commandline) run_except_on_windows(commandline)
else: else:
import py3.pkg2 import py3.pkg2
print " Finished importing py3.pkg2" print(" Finished importing py3.pkg2")
# commandline = sys.executable + " -m py3.pkg2.bar" # commandline = sys.executable + " -m py3.pkg2.bar"
# run_except_on_windows(commandline) # run_except_on_windows(commandline)
# commandline = sys.executable + " -m py3.pkg2.foo" # commandline = sys.executable + " -m py3.pkg2.foo"

View file

@ -6,24 +6,24 @@ def run_except_on_windows(commandline, env=None):
if os.name != "nt" and sys.platform != "cygwin": if os.name != "nt" and sys.platform != "cygwin":
# Strange failures on windows/cygin/mingw # Strange failures on windows/cygin/mingw
subprocess.check_call(commandline, env=env, shell=True) subprocess.check_call(commandline, env=env, shell=True)
print(" Finished running: " + commandline) print((" Finished running: " + commandline))
# Test import of modules content from within __init__.py # Test import of modules content from within __init__.py
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__))) testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py" print("Testing " + testname + " - %module(package=...) + python 'import' in __init__.py")
if sys.version_info < (2, 5): if sys.version_info < (2, 5):
print " Skipping test as Python version is < 2.5 and does not support relative import syntax: 'from . import x'" print(" Skipping test as Python version is < 2.5 and does not support relative import syntax: 'from . import x'")
sys.exit(0) sys.exit(0)
if sys.version_info < (3, 0): if sys.version_info < (3, 0):
import py2.pkg2 import py2.pkg2
print " Finished importing py2.pkg2" print(" Finished importing py2.pkg2")
commandline = sys.executable + " -m py2.pkg2.bar" commandline = sys.executable + " -m py2.pkg2.bar"
run_except_on_windows(commandline) run_except_on_windows(commandline)
else: else:
import py3.pkg2 import py3.pkg2
print " Finished importing py3.pkg2" print(" Finished importing py3.pkg2")
# commandline = sys.executable + " -m py3.pkg2.bar" # commandline = sys.executable + " -m py3.pkg2.bar"
# run_except_on_windows(commandline) # run_except_on_windows(commandline)

View file

@ -6,24 +6,24 @@ def run_except_on_windows(commandline, env=None):
if os.name != "nt" and sys.platform != "cygwin": if os.name != "nt" and sys.platform != "cygwin":
# Strange failures on windows/cygin/mingw # Strange failures on windows/cygin/mingw
subprocess.check_call(commandline, env=env, shell=True) subprocess.check_call(commandline, env=env, shell=True)
print(" Finished running: " + commandline) print((" Finished running: " + commandline))
# Test import of modules content from within __init__.py # Test import of modules content from within __init__.py
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__))) testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py" print("Testing " + testname + " - %module(package=...) + python 'import' in __init__.py")
if sys.version_info < (2, 5): if sys.version_info < (2, 5):
print " Skipping test as Python version is < 2.5 and does not support relative import syntax: 'from . import x'" print(" Skipping test as Python version is < 2.5 and does not support relative import syntax: 'from . import x'")
sys.exit(0) sys.exit(0)
if sys.version_info < (3, 0): if sys.version_info < (3, 0):
import py2.pkg2 import py2.pkg2
print " Finished importing py2.pkg2" print(" Finished importing py2.pkg2")
commandline = sys.executable + " -m py2.pkg2.bar" commandline = sys.executable + " -m py2.pkg2.bar"
run_except_on_windows(commandline) run_except_on_windows(commandline)
else: else:
import py3.pkg2 import py3.pkg2
print " Finished importing py3.pkg2" print(" Finished importing py3.pkg2")
# commandline = sys.executable + " -m py3.pkg2.bar" # commandline = sys.executable + " -m py3.pkg2.bar"
# run_except_on_windows(commandline) # run_except_on_windows(commandline)

View file

@ -3,10 +3,10 @@ import sys
# Test import of a SWIG generated module renamed as the package's __init__.py # Test import of a SWIG generated module renamed as the package's __init__.py
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__))) testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
print "Testing " + testname + " - module renamed as __init__.py" print("Testing " + testname + " - module renamed as __init__.py")
if sys.version_info >= (3, 0, 0) and sys.version_info < (3, 3, 0): if sys.version_info >= (3, 0, 0) and sys.version_info < (3, 3, 0):
print " Not importing as Python version is >= 3.0 and < 3.3" print(" Not importing as Python version is >= 3.0 and < 3.3")
# Package detection does not work in these versions. # Package detection does not work in these versions.
# Can be fixed by using this in the interface file: # Can be fixed by using this in the interface file:
# %module(moduleimport="from . import $module") foo # without -builtin # %module(moduleimport="from . import $module") foo # without -builtin
@ -14,7 +14,7 @@ if sys.version_info >= (3, 0, 0) and sys.version_info < (3, 3, 0):
sys.exit(0) sys.exit(0)
import pkg1 import pkg1
print " Finished importing pkg1" print(" Finished importing pkg1")
if pkg1.foofunction(123) != 1230: if pkg1.foofunction(123) != 1230:
raise RuntimeError("foofunction failed") raise RuntimeError("foofunction failed")
@ -23,4 +23,4 @@ fc = pkg1.FooClass()
if fc.foomethod(1) != 6: if fc.foomethod(1) != 6:
raise RuntimeError("foomethod failed") raise RuntimeError("foomethod failed")
print " Finished testing pkg1" print(" Finished testing pkg1")

View file

@ -5,14 +5,14 @@ import subprocess
import sys import sys
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__))) testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
print "Testing " + testname + " - namespace packages" print("Testing " + testname + " - namespace packages")
if sys.version_info < (3, 3, 0): if sys.version_info < (3, 3, 0):
print " Not importing nstest as Python version is < 3.3" print(" Not importing nstest as Python version is < 3.3")
sys.exit(0) sys.exit(0)
import nstest import nstest
print " Finished importing nstest" print(" Finished importing nstest")
nstest.main() nstest.main()

View file

@ -6,26 +6,26 @@ def run_except_on_windows(commandline, env=None):
if os.name != "nt" and sys.platform != "cygwin": if os.name != "nt" and sys.platform != "cygwin":
# Strange failures on windows/cygin/mingw # Strange failures on windows/cygin/mingw
subprocess.check_call(commandline, env=env, shell=True) subprocess.check_call(commandline, env=env, shell=True)
print(" Finished running: " + commandline) print((" Finished running: " + commandline))
# Test import of modules content from within __init__.py # Test import of modules content from within __init__.py
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__))) testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
print "Testing " + testname + " - %module(package=...) with -relativeimport" print("Testing " + testname + " - %module(package=...) with -relativeimport")
if sys.version_info < (2, 5): if sys.version_info < (2, 5):
print " Skipping test as Python version is < 2.5 and does not support relative import syntax: 'from . import x'" print(" Skipping test as Python version is < 2.5 and does not support relative import syntax: 'from . import x'")
sys.exit(0) sys.exit(0)
if sys.version_info < (3, 0): if sys.version_info < (3, 0):
import py2.pkg2.bar import py2.pkg2.bar
print " Finished importing py2.pkg2.bar" print(" Finished importing py2.pkg2.bar")
commandline = sys.executable + " -m py2.pkg2.bar" commandline = sys.executable + " -m py2.pkg2.bar"
run_except_on_windows(commandline) run_except_on_windows(commandline)
commandline = sys.executable + " -m py2.pkg2.pkg3.foo" commandline = sys.executable + " -m py2.pkg2.pkg3.foo"
run_except_on_windows(commandline) run_except_on_windows(commandline)
else: else:
import py3.pkg2.bar import py3.pkg2.bar
print " Finished importing py3.pkg2.bar" print(" Finished importing py3.pkg2.bar")
commandline = sys.executable + " -m py3.pkg2.bar" commandline = sys.executable + " -m py3.pkg2.bar"
run_except_on_windows(commandline) run_except_on_windows(commandline)
commandline = sys.executable + " -m py3.pkg2.pkg3.foo" commandline = sys.executable + " -m py3.pkg2.pkg3.foo"

View file

@ -6,26 +6,26 @@ def run_except_on_windows(commandline, env=None):
if os.name != "nt" and sys.platform != "cygwin": if os.name != "nt" and sys.platform != "cygwin":
# Strange failures on windows/cygin/mingw # Strange failures on windows/cygin/mingw
subprocess.check_call(commandline, env=env, shell=True) subprocess.check_call(commandline, env=env, shell=True)
print(" Finished running: " + commandline) print((" Finished running: " + commandline))
# Test import of modules content from within __init__.py # Test import of modules content from within __init__.py
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__))) testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py" print("Testing " + testname + " - %module(package=...) + python 'import' in __init__.py")
if sys.version_info < (2, 5): if sys.version_info < (2, 5):
print " Skipping test as Python version is < 2.5 and does not support relative import syntax: 'from . import x'" print(" Skipping test as Python version is < 2.5 and does not support relative import syntax: 'from . import x'")
sys.exit(0) sys.exit(0)
if sys.version_info < (3, 0): if sys.version_info < (3, 0):
import py2.pkg2.bar import py2.pkg2.bar
print " Finished importing py2.pkg2.bar" print(" Finished importing py2.pkg2.bar")
commandline = sys.executable + " -m py2.pkg2.bar" commandline = sys.executable + " -m py2.pkg2.bar"
run_except_on_windows(commandline) run_except_on_windows(commandline)
commandline = sys.executable + " -m py2.pkg2.pkg3.pkg4.foo" commandline = sys.executable + " -m py2.pkg2.pkg3.pkg4.foo"
run_except_on_windows(commandline) run_except_on_windows(commandline)
else: else:
import py3.pkg2.bar import py3.pkg2.bar
print " Finished importing py3.pkg2.bar" print(" Finished importing py3.pkg2.bar")
commandline = sys.executable + " -m py3.pkg2.bar" commandline = sys.executable + " -m py3.pkg2.bar"
run_except_on_windows(commandline) run_except_on_windows(commandline)
commandline = sys.executable + " -m py3.pkg2.pkg3.pkg4.foo" commandline = sys.executable + " -m py3.pkg2.pkg3.pkg4.foo"

View file

@ -6,26 +6,26 @@ def run_except_on_windows(commandline, env=None):
if os.name != "nt" and sys.platform != "cygwin": if os.name != "nt" and sys.platform != "cygwin":
# Strange failures on windows/cygin/mingw # Strange failures on windows/cygin/mingw
subprocess.check_call(commandline, env=env, shell=True) subprocess.check_call(commandline, env=env, shell=True)
print(" Finished running: " + commandline) print((" Finished running: " + commandline))
# Test import of modules content from within __init__.py # Test import of modules content from within __init__.py
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__))) testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
print "Testing " + testname + " - %module(package=...) with -relativeimport" print("Testing " + testname + " - %module(package=...) with -relativeimport")
if sys.version_info < (2, 5): if sys.version_info < (2, 5):
print " Skipping test as Python version is < 2.5 and does not support relative import syntax: 'from . import x'" print(" Skipping test as Python version is < 2.5 and does not support relative import syntax: 'from . import x'")
sys.exit(0) sys.exit(0)
if sys.version_info < (3, 0): if sys.version_info < (3, 0):
import py2.pkg2.bar import py2.pkg2.bar
print " Finished importing py2.pkg2.bar" print(" Finished importing py2.pkg2.bar")
commandline = sys.executable + " -m py2.pkg2.bar" commandline = sys.executable + " -m py2.pkg2.bar"
run_except_on_windows(commandline) run_except_on_windows(commandline)
commandline = sys.executable + " -m py2.pkg2.pkg3.foo" commandline = sys.executable + " -m py2.pkg2.pkg3.foo"
run_except_on_windows(commandline) run_except_on_windows(commandline)
else: else:
import py3.pkg2.bar import py3.pkg2.bar
print " Finished importing py3.pkg2.bar" print(" Finished importing py3.pkg2.bar")
commandline = sys.executable + " -m py3.pkg2.bar" commandline = sys.executable + " -m py3.pkg2.bar"
run_except_on_windows(commandline) run_except_on_windows(commandline)
commandline = sys.executable + " -m py3.pkg2.pkg3.foo" commandline = sys.executable + " -m py3.pkg2.pkg3.foo"

View file

@ -6,21 +6,21 @@ def run_except_on_windows(commandline, env=None):
if os.name != "nt" and sys.platform != "cygwin": if os.name != "nt" and sys.platform != "cygwin":
# Strange failures on windows/cygin/mingw # Strange failures on windows/cygin/mingw
subprocess.check_call(commandline, env=env, shell=True) subprocess.check_call(commandline, env=env, shell=True)
print(" Finished running: " + commandline) print((" Finished running: " + commandline))
# Test import of same modules from different packages # Test import of same modules from different packages
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__))) testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py" print("Testing " + testname + " - %module(package=...) + python 'import' in __init__.py")
import pkg2.foo import pkg2.foo
print " Finished importing pkg2.foo" print(" Finished importing pkg2.foo")
var2 = pkg2.foo.Pkg2_Foo() var2 = pkg2.foo.Pkg2_Foo()
classname = str(type(var2)) classname = str(type(var2))
if classname.find("pkg2.foo.Pkg2_Foo") == -1: if classname.find("pkg2.foo.Pkg2_Foo") == -1:
raise RuntimeError("failed type checking: " + classname) raise RuntimeError("failed type checking: " + classname)
print " Successfully created object pkg2.foo.Pkg2_Foo" print(" Successfully created object pkg2.foo.Pkg2_Foo")
commandline = sys.executable + " -m pkg2.foo" commandline = sys.executable + " -m pkg2.foo"
run_except_on_windows(commandline) run_except_on_windows(commandline)

View file

@ -6,20 +6,20 @@ def run_except_on_windows(commandline, env=None):
if os.name != "nt" and sys.platform != "cygwin": if os.name != "nt" and sys.platform != "cygwin":
# Strange failures on windows/cygin/mingw # Strange failures on windows/cygin/mingw
subprocess.check_call(commandline, env=env, shell=True) subprocess.check_call(commandline, env=env, shell=True)
print(" Finished running: " + commandline) print((" Finished running: " + commandline))
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__))) testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py" print("Testing " + testname + " - %module(package=...) + python 'import' in __init__.py")
import pkg1.pkg2.foo import pkg1.pkg2.foo
print " Finished importing pkg1.pkg2.foo" print(" Finished importing pkg1.pkg2.foo")
var2 = pkg1.pkg2.foo.Pkg2_Foo() var2 = pkg1.pkg2.foo.Pkg2_Foo()
classname = str(type(var2)) classname = str(type(var2))
if classname.find("pkg1.pkg2.foo.Pkg2_Foo") == -1: if classname.find("pkg1.pkg2.foo.Pkg2_Foo") == -1:
raise RuntimeError("failed type checking: " + classname) raise RuntimeError("failed type checking: " + classname)
print " Successfully created object pkg1.pkg2.foo.Pkg2_Foo" print(" Successfully created object pkg1.pkg2.foo.Pkg2_Foo")
commandline = sys.executable + " -m pkg1.pkg2.foo" commandline = sys.executable + " -m pkg1.pkg2.foo"
run_except_on_windows(commandline) run_except_on_windows(commandline)

View file

@ -6,14 +6,14 @@ def run_except_on_windows(commandline, env=None):
if os.name != "nt" and sys.platform != "cygwin": if os.name != "nt" and sys.platform != "cygwin":
# Strange failures on windows/cygin/mingw # Strange failures on windows/cygin/mingw
subprocess.check_call(commandline, env=env, shell=True) subprocess.check_call(commandline, env=env, shell=True)
print(" Finished running: " + commandline) print((" Finished running: " + commandline))
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__))) testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
print "Testing " + testname + " - split modules" print("Testing " + testname + " - split modules")
import pkg1.foo import pkg1.foo
print " Finished importing pkg1.foo" print(" Finished importing pkg1.foo")
if not(pkg1.foo.count() == 3): if not(pkg1.foo.count() == 3):
raise RuntimeError("test failed") raise RuntimeError("test failed")

View file

@ -6,14 +6,14 @@ def run_except_on_windows(commandline, env=None):
if os.name != "nt" and sys.platform != "cygwin": if os.name != "nt" and sys.platform != "cygwin":
# Strange failures on windows/cygin/mingw # Strange failures on windows/cygin/mingw
subprocess.check_call(commandline, env=env, shell=True) subprocess.check_call(commandline, env=env, shell=True)
print(" Finished running: " + commandline) print((" Finished running: " + commandline))
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__))) testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
print "Testing " + testname + " - split modules" print("Testing " + testname + " - split modules")
import pkg1.foo import pkg1.foo
print " Finished importing pkg1.foo" print(" Finished importing pkg1.foo")
if not(pkg1.foo.count() == 3): if not(pkg1.foo.count() == 3):
raise RuntimeError("test failed") raise RuntimeError("test failed")

View file

@ -1,15 +1,22 @@
# file: runme.py # file: runme.py
# Test various properties of classes defined in separate modules # Test various properties of classes defined in separate modules
import sys
print("Testing the %import directive with templates")
print "Testing the %import directive with templates"
import base import base
import foo import foo
import bar import bar
import spam import spam
def write_flush(s):
# Python 2/3 compatible write and flush
sys.stdout.write(s)
sys.stdout.flush()
# Create some objects # Create some objects
print "Creating some objects" print("Creating some objects")
a = base.intBase() a = base.intBase()
b = foo.intFoo() b = foo.intFoo()
@ -17,91 +24,74 @@ c = bar.intBar()
d = spam.intSpam() d = spam.intSpam()
# Try calling some methods # Try calling some methods
print "Testing some methods" print("Testing some methods")
print "",
print "Should see 'Base::A' ---> ", write_flush(" Should see 'Base::A' ---> ")
a.A() a.A()
print "Should see 'Base::B' ---> ", write_flush(" Should see 'Base::B' ---> ")
a.B() a.B()
print "Should see 'Foo::A' ---> ", write_flush(" Should see 'Foo::A' ---> ")
b.A() b.A()
print "Should see 'Foo::B' ---> ", write_flush(" Should see 'Foo::B' ---> ")
b.B() b.B()
print "Should see 'Bar::A' ---> ", write_flush(" Should see 'Bar::A' ---> ")
c.A() c.A()
print "Should see 'Bar::B' ---> ", write_flush(" Should see 'Bar::B' ---> ")
c.B() c.B()
print "Should see 'Spam::A' ---> ", write_flush(" Should see 'Spam::A' ---> ")
d.A() d.A()
print "Should see 'Spam::B' ---> ", write_flush(" Should see 'Spam::B' ---> ")
d.B() d.B()
# Try some casts # Try some casts
print "\nTesting some casts\n" print("\nTesting some casts\n")
print "",
x = a.toBase() x = a.toBase()
print "Should see 'Base::A' ---> ", write_flush(" Should see 'Base::A' ---> ")
x.A() x.A()
print "Should see 'Base::B' ---> ", write_flush(" Should see 'Base::B' ---> ")
x.B() x.B()
x = b.toBase() x = b.toBase()
print "Should see 'Foo::A' ---> ", write_flush(" Should see 'Foo::A' ---> ")
x.A() x.A()
print "Should see 'Base::B' ---> ", write_flush(" Should see 'Base::B' ---> ")
x.B() x.B()
x = c.toBase() x = c.toBase()
print "Should see 'Bar::A' ---> ", write_flush(" Should see 'Bar::A' ---> ")
x.A() x.A()
print "Should see 'Base::B' ---> ", write_flush(" Should see 'Base::B' ---> ")
x.B() x.B()
x = d.toBase() x = d.toBase()
print "Should see 'Spam::A' ---> ", write_flush(" Should see 'Spam::A' ---> ")
x.A() x.A()
print "Should see 'Base::B' ---> ", write_flush(" Should see 'Base::B' ---> ")
x.B() x.B()
x = d.toBar() x = d.toBar()
print "Should see 'Bar::B' ---> ", write_flush(" Should see 'Bar::B' ---> ")
x.B() x.B()
print "\nTesting some dynamic casts\n" print("\nTesting some dynamic casts\n")
x = d.toBase() x = d.toBase()
print " Spam -> Base -> Foo : ",
y = foo.intFoo_fromBase(x) y = foo.intFoo_fromBase(x)
if y: print(" Spam -> Base -> Foo : {} swig".format("bad" if y else "good"))
print "bad swig"
else:
print "good swig"
print " Spam -> Base -> Bar : ",
y = bar.intBar_fromBase(x) y = bar.intBar_fromBase(x)
if y: print(" Spam -> Base -> Bar : {} swig".format("good" if y else "bad"))
print "good swig"
else:
print "bad swig"
print " Spam -> Base -> Spam : ",
y = spam.intSpam_fromBase(x) y = spam.intSpam_fromBase(x)
if y: print(" Spam -> Base -> Spam : {} swig".format("good" if y else "bad"))
print "good swig"
else:
print "bad swig"
print " Foo -> Spam : ",
y = spam.intSpam_fromBase(b) y = spam.intSpam_fromBase(b)
if y: print(" Foo -> Spam : {} swig".format("bad" if y else "good"))
print "bad swig"
else:
print "good swig"

View file

@ -89,7 +89,6 @@ to look at the <a href="http://www.python.org/sigs/distutils-sig/">distutils</a>
<h2>Compatibility</h2> <h2>Compatibility</h2>
For Python 3, set the environment variable <tt>PY3=1</tt>. For Python 3, set the environment variable <tt>PY3=1</tt>.
This will ensure the 2to3 program is run prior to running any example.
<p> <p>
Your mileage may vary. If you experience a problem, please let us know by Your mileage may vary. If you experience a problem, please let us know by

View file

@ -7,14 +7,14 @@ import example
x = 42 x = 42
y = 105 y = 105
g = example.gcd(x, y) g = example.gcd(x, y)
print "The gcd of %d and %d is %d" % (x, y, g) print("The gcd of %d and %d is %d" % (x, y, g))
# Call the gcdmain() function # Call the gcdmain() function
example.gcdmain(["gcdmain", "42", "105"]) example.gcdmain(["gcdmain", "42", "105"])
# Call the count function # Call the count function
print example.count("Hello World", "l") print(example.count("Hello World", "l"))
# Call the capitalize function # Call the capitalize function
print example.capitalize("hello world") print(example.capitalize("hello world"))

View file

@ -4,17 +4,17 @@ import example
a = example.Complex(2, 3) a = example.Complex(2, 3)
b = example.Complex(-5, 10) b = example.Complex(-5, 10)
print "a =", a print("a = %s" % a)
print "b =", b print("b = %s" % b)
c = a + b c = a + b
print "c =", c print("c = %s" % c)
print "a*b =", a * b print("a*b = %s" % (a * b))
print "a-c =", a - c print("a-c = %s" % (a - c))
e = example.ComplexCopy(a - c) e = example.ComplexCopy(a - c)
print "e =", e print("e = %s" % e)
# Big expression # Big expression
f = ((a + b) * (c + b * e)) + (-a) f = ((a + b) * (c + b * e)) + (-a)
print "f =", f print("f = %s" % f)

View file

@ -3,23 +3,23 @@
import example import example
# First create some objects using the pointer library. # First create some objects using the pointer library.
print "Testing the pointer library" print("Testing the pointer library")
a = example.new_intp() a = example.new_intp()
b = example.new_intp() b = example.new_intp()
c = example.new_intp() c = example.new_intp()
example.intp_assign(a, 37) example.intp_assign(a, 37)
example.intp_assign(b, 42) example.intp_assign(b, 42)
print " a =", a print(" a = %s" % a)
print " b =", b print(" b = %s" % b)
print " c =", c print(" c = %s" % c)
# Call the add() function with some pointers # Call the add() function with some pointers
example.add(a, b, c) example.add(a, b, c)
# Now get the result # Now get the result
r = example.intp_value(c) r = example.intp_value(c)
print " 37 + 42 =", r print(" 37 + 42 = %s" % r)
# Clean up the pointers # Clean up the pointers
example.delete_intp(a) example.delete_intp(a)
@ -30,12 +30,12 @@ example.delete_intp(c)
# This should be much easier. Now how it is no longer # This should be much easier. Now how it is no longer
# necessary to manufacture pointers. # necessary to manufacture pointers.
print "Trying the typemap library" print("Trying the typemap library")
r = example.sub(37, 42) r = example.sub(37, 42)
print " 37 - 42 =", r print(" 37 - 42 = %s" % r)
# Now try the version with multiple return values # Now try the version with multiple return values
print "Testing multiple return values" print("Testing multiple return values")
q, r = example.divide(42, 37) q, r = example.divide(42, 37)
print " 42/37 = %d remainder %d" % (q, r) print(" 42/37 = %d remainder %d" % (q, r))

View file

@ -6,12 +6,12 @@ import example
# ----- Object creation ----- # ----- Object creation -----
print "Creating some objects:" print("Creating some objects:")
a = example.Vector(3, 4, 5) a = example.Vector(3, 4, 5)
b = example.Vector(10, 11, 12) b = example.Vector(10, 11, 12)
print " Created", a.cprint() print(" Created %s" % a.cprint())
print " Created", b.cprint() print(" Created %s" % b.cprint())
# ----- Call an overloaded operator ----- # ----- Call an overloaded operator -----
@ -21,9 +21,9 @@ print " Created", b.cprint()
# #
# It returns a new allocated object. # It returns a new allocated object.
print "Adding a+b" print("Adding a+b")
c = example.addv(a, b) c = example.addv(a, b)
print " a+b =", c.cprint() print(" a+b = %s" % c.cprint())
# Note: Unless we free the result, a memory leak will occur # Note: Unless we free the result, a memory leak will occur
del c del c
@ -31,9 +31,9 @@ del c
# ----- Create a vector array ----- # ----- Create a vector array -----
# Note: Using the high-level interface here # Note: Using the high-level interface here
print "Creating an array of vectors" print("Creating an array of vectors")
va = example.VectorArray(10) va = example.VectorArray(10)
print " va = ", va print(" va = %s" % va)
# ----- Set some values in the array ----- # ----- Set some values in the array -----
@ -45,17 +45,17 @@ va.set(2, example.addv(a, b))
# Get some values from the array # Get some values from the array
print "Getting some array values" print("Getting some array values")
for i in range(0, 5): for i in range(0, 5):
print " va(%d) = %s" % (i, va.get(i).cprint()) print(" va(%d) = %s" % (i, va.get(i).cprint()))
# Watch under resource meter to check on this # Watch under resource meter to check on this
print "Making sure we don't leak memory." print("Making sure we don't leak memory.")
for i in xrange(0, 1000000): for i in range(0, 1000000):
c = va.get(i % 10) c = va.get(i % 10)
# ----- Clean up ----- # ----- Clean up -----
print "Cleaning up" print("Cleaning up")
del va del va
del a del a

View file

@ -7,15 +7,15 @@ import example
x = 42 x = 42
y = 105 y = 105
g = example.gcd(x, y) g = example.gcd(x, y)
print "The gcd of %d and %d is %d" % (x, y, g) print("The gcd of %d and %d is %d" % (x, y, g))
# Manipulate the Foo global variable # Manipulate the Foo global variable
# Output its current value # Output its current value
print "Foo = ", example.cvar.Foo print("Foo = %s" % example.cvar.Foo)
# Change its value # Change its value
example.cvar.Foo = 3.1415926 example.cvar.Foo = 3.1415926
# See if the change took effect # See if the change took effect
print "Foo = ", example.cvar.Foo print("Foo = %s" % example.cvar.Foo)

View file

@ -7,17 +7,17 @@ import example
# ----- Object creation ----- # ----- Object creation -----
print "Creating some objects:" print("Creating some objects:")
cc = example.Circle(10) cc = example.Circle(10)
c = example.ShapePtr(cc) c = example.ShapePtr(cc)
print " Created circle", c print(" Created circle %s" % c)
ss = example.Square(10) ss = example.Square(10)
s = example.ShapePtr(ss) s = example.ShapePtr(ss)
print " Created square", s print(" Created square %s" % s)
# ----- Access a static member ----- # ----- Access a static member -----
print "\nA total of", example.cvar.Shape_nshapes, "shapes were created" print("\nA total of %s shapes were created" % example.cvar.Shape_nshapes)
# ----- Member data access ----- # ----- Member data access -----
@ -29,19 +29,19 @@ c.y = 30
s.x = -10 s.x = -10
s.y = 5 s.y = 5
print "\nHere is their current position:" print("\nHere is their current position:")
print " Circle = (%f, %f)" % (c.x, c.y) print(" Circle = (%f, %f)" % (c.x, c.y))
print " Square = (%f, %f)" % (s.x, s.y) print(" Square = (%f, %f)" % (s.x, s.y))
# ----- Call some methods ----- # ----- Call some methods -----
print "\nHere are some properties of the shapes:" print("\nHere are some properties of the shapes:")
for o in [c, s]: for o in [c, s]:
print " ", o print(" %s" % o)
print " area = ", o.area() print(" area = %s" % o.area())
print " perimeter = ", o.perimeter() print(" perimeter = %s" % o.perimeter())
print "\nGuess I'll clean up now" print("\nGuess I'll clean up now")
# Note: this invokes the virtual destructor # Note: this invokes the virtual destructor
del c del c
@ -50,5 +50,5 @@ del cc
del ss del ss
s = 3 s = 3
print example.cvar.Shape_nshapes, "shapes remain" print("%d shapes remain" % example.cvar.Shape_nshapes)
print "Goodbye" print("Goodbye")

View file

@ -11,45 +11,45 @@ dmap = {}
dmap["hello"] = 1.0 dmap["hello"] = 1.0
dmap["hi"] = 2.0 dmap["hi"] = 2.0
print dmap.items() print(list(dmap.items()))
print dmap.keys() print(list(dmap.keys()))
print dmap.values() print(list(dmap.values()))
print dmap print(dmap)
hmap = example.halfd(dmap) hmap = example.halfd(dmap)
dmap = hmap dmap = hmap
print dmap print(dmap)
for i in dmap.iterkeys(): for i in dmap.keys():
print "key", i print("key %s" % i)
for i in dmap.itervalues(): for i in dmap.values():
print "val", i print("val %s" % i)
for k, v in dmap.iteritems(): for k, v in dmap.items():
print "item", k, v print("item %s %s" % (k, v))
dmap = example.DoubleMap() dmap = example.DoubleMap()
dmap["hello"] = 1.0 dmap["hello"] = 1.0
dmap["hi"] = 2.0 dmap["hi"] = 2.0
for i in dmap.iterkeys(): for i in dmap.keys():
print "key", i print("key %s" % i)
for i in dmap.itervalues(): for i in dmap.values():
print "val", i print("val %s" % i)
for k, v in dmap.iteritems(): for k, v in dmap.items():
print "item", k, v print("item %s %s" % (k, v))
print dmap.items() print(list(dmap.items()))
print dmap.keys() print(list(dmap.keys()))
print dmap.values() print(list(dmap.values()))
hmap = example.halfd(dmap) hmap = example.halfd(dmap)
print hmap.keys() print(list(hmap.keys()))
print hmap.values() print(list(hmap.values()))
dmap = {} dmap = {}
@ -57,23 +57,23 @@ dmap["hello"] = 2
dmap["hi"] = 4 dmap["hi"] = 4
hmap = example.halfi(dmap) hmap = example.halfi(dmap)
print hmap print(hmap)
print hmap.keys() print(list(hmap.keys()))
print hmap.values() print(list(hmap.values()))
dmap = hmap dmap = hmap
for i in dmap.iterkeys(): for i in dmap.keys():
print "key", i print("key %s" % i)
for i in dmap.itervalues(): for i in dmap.values():
print "val", i print("val %s" % i)
for i in dmap.iteritems(): for i in dmap.items():
print "item", i print("item %s" % str(i))
for k, v in dmap.iteritems(): for k, v in dmap.items():
print "item", k, v print("item %s %s" % (k, v))
print dmap print(dmap)

View file

@ -4,32 +4,30 @@ import example
# Call average with a Python list... # Call average with a Python list...
print example.average([1, 2, 3, 4]) print(example.average([1, 2, 3, 4]))
# ... or a wrapped std::vector<int> # ... or a wrapped std::vector<int>
v = example.IntVector(4) v = example.IntVector(4)
for i in range(len(v)): for i in range(len(v)):
v[i] = i + 1 v[i] = i + 1
print example.average(v) print(example.average(v))
# half will return a Python list. # half will return a Python list.
# Call it with a Python tuple... # Call it with a Python tuple...
print example.half((1.0, 1.5, 2.0, 2.5, 3.0)) print(example.half((1.0, 1.5, 2.0, 2.5, 3.0)))
# ... or a wrapped std::vector<double> # ... or a wrapped std::vector<double>
v = example.DoubleVector() v = example.DoubleVector()
for i in [1, 2, 3, 4]: for i in [1, 2, 3, 4]:
v.append(i) v.append(i)
print example.half(v) print(example.half(v))
# now halve a wrapped std::vector<double> in place # now halve a wrapped std::vector<double> in place
example.halve_in_place(v) example.halve_in_place(v)
for i in range(len(v)): print([i for i in v])
print v[i], "; ",
print

View file

@ -3,8 +3,8 @@
import example import example
# Call some templated functions # Call some templated functions
print example.maxint(3, 7) print(example.maxint(3, 7))
print example.maxdouble(3.14, 2.18) print(example.maxdouble(3.14, 2.18))
# Create some class # Create some class
@ -21,12 +21,12 @@ sum = 0
for i in range(0, 100): for i in range(0, 100):
sum = sum + iv.getitem(i) sum = sum + iv.getitem(i)
print sum print(sum)
sum = 0.0 sum = 0.0
for i in range(0, 1000): for i in range(0, 1000):
sum = sum + dv.getitem(i) sum = sum + dv.getitem(i)
print sum print(sum)
del iv del iv
del dv del dv

View file

@ -22,51 +22,51 @@ example.cvar.name = "Bill"
# Now print out the values of the variables # Now print out the values of the variables
print "Variables (values printed from Python)" print("Variables (values printed from Python)")
print "ivar =", example.cvar.ivar print("ivar = %s" % example.cvar.ivar)
print "svar =", example.cvar.svar print("svar = %s" % example.cvar.svar)
print "lvar =", example.cvar.lvar print("lvar = %s" % example.cvar.lvar)
print "uivar =", example.cvar.uivar print("uivar = %s" % example.cvar.uivar)
print "usvar =", example.cvar.usvar print("usvar = %s" % example.cvar.usvar)
print "ulvar =", example.cvar.ulvar print("ulvar = %s" % example.cvar.ulvar)
print "scvar =", example.cvar.scvar print("scvar = %s" % example.cvar.scvar)
print "ucvar =", example.cvar.ucvar print("ucvar = %s" % example.cvar.ucvar)
print "fvar =", example.cvar.fvar print("fvar = %s" % example.cvar.fvar)
print "dvar =", example.cvar.dvar print("dvar = %s" % example.cvar.dvar)
print "cvar =", example.cvar.cvar print("cvar = %s" % example.cvar.cvar)
print "strvar =", example.cvar.strvar print("strvar = %s" % example.cvar.strvar)
print "cstrvar =", example.cvar.cstrvar print("cstrvar = %s" % example.cvar.cstrvar)
print "iptrvar =", example.cvar.iptrvar print("iptrvar = %s" % example.cvar.iptrvar)
print "name =", example.cvar.name print("name = %s" % example.cvar.name)
print "ptptr =", example.cvar.ptptr, example.Point_print(example.cvar.ptptr) print("ptptr = %s %s" % (example.cvar.ptptr, example.Point_print(example.cvar.ptptr)))
print "pt =", example.cvar.pt, example.Point_print(example.cvar.pt) print("pt = %s %s" % (example.cvar.pt, example.Point_print(example.cvar.pt)))
print "\nVariables (values printed from C)" print("\nVariables (values printed from C)")
example.print_vars() example.print_vars()
print "\nNow I'm going to try and modify some read only variables" print("\nNow I'm going to try and modify some read only variables")
print " Trying to set 'path'" print(" Trying to set 'path'")
try: try:
example.cvar.path = "Whoa!" example.cvar.path = "Whoa!"
print "Hey, what's going on?!?! This shouldn't work" print("Hey, what's going on?!?! This shouldn't work")
except Exception: except Exception:
print "Good." print("Good.")
print " Trying to set 'status'" print(" Trying to set 'status'")
try: try:
example.cvar.status = 0 example.cvar.status = 0
print "Hey, what's going on?!?! This shouldn't work" print("Hey, what's going on?!?! This shouldn't work")
except Exception: except Exception:
print "Good." print("Good.")
print "\nI'm going to try and update a structure variable.\n" print("\nI'm going to try and update a structure variable.\n")
example.cvar.pt = example.cvar.ptptr example.cvar.pt = example.cvar.ptptr
print "The new value is" print("The new value is")
example.pt_print() example.pt_print()
print "You should see the value", example.Point_print(example.cvar.ptptr) print("You should see the value %s" % example.Point_print(example.cvar.ptptr))

View file

@ -10,20 +10,10 @@ endif
LANGUAGE = python LANGUAGE = python
PYTHON = $(PYBIN) PYTHON = $(PYBIN)
SCRIPTSUFFIX = _runme.py
PYCODESTYLE = @PYCODESTYLE@ PYCODESTYLE = @PYCODESTYLE@
PYCODESTYLE_FLAGS = --ignore=E252,E30,E402,E501,E731,E741,W291,W391 PYCODESTYLE_FLAGS = --ignore=E252,E30,E402,E501,E731,E741,W291,W391
#*_runme.py for Python 2.x, *_runme3.py for Python 3.x
PY2SCRIPTSUFFIX = _runme.py
PY3SCRIPTSUFFIX = _runme3.py
PY2TO3 = @PY2TO3@ -x import
ifeq (,$(PY3))
SCRIPTSUFFIX = $(PY2SCRIPTSUFFIX)
else
SCRIPTSUFFIX = $(PY3SCRIPTSUFFIX)
endif
srcdir = @srcdir@ srcdir = @srcdir@
top_srcdir = @top_srcdir@ top_srcdir = @top_srcdir@
top_builddir = @top_builddir@ top_builddir = @top_builddir@
@ -108,7 +98,6 @@ C_TEST_CASES += \
include $(srcdir)/../common.mk include $(srcdir)/../common.mk
# Overridden variables here # Overridden variables here
SCRIPTDIR = .
LIBS = -L. LIBS = -L.
VALGRIND_OPT += --suppressions=pythonswig.supp VALGRIND_OPT += --suppressions=pythonswig.supp
@ -117,35 +106,25 @@ VALGRIND_OPT += --suppressions=pythonswig.supp
# Rules for the different types of tests # Rules for the different types of tests
%.cpptest: %.cpptest:
+$(convert_testcase)
$(setup) $(setup)
+$(swig_and_compile_cpp) +$(swig_and_compile_cpp)
$(check_pep8) $(check_pep8)
$(run_testcase) $(run_testcase)
%.ctest: %.ctest:
+$(convert_testcase)
$(setup) $(setup)
+$(swig_and_compile_c) +$(swig_and_compile_c)
$(check_pep8) $(check_pep8)
$(run_testcase) $(run_testcase)
%.multicpptest: %.multicpptest:
+$(convert_testcase)
$(setup) $(setup)
+$(swig_and_compile_multi_cpp) +$(swig_and_compile_multi_cpp)
$(check_pep8_multi_cpp) $(check_pep8_multi_cpp)
$(run_testcase) $(run_testcase)
# Python code style checking
# Runs the testcase. A testcase is only run if
# a file is found which has _runme.py (or _runme3.py for Python 3) appended after the testcase name.
py_runme = $(SCRIPTPREFIX)$*$(SCRIPTSUFFIX)
py2_runme = $(SCRIPTPREFIX)$*$(PY2SCRIPTSUFFIX)
py3_runme = $(SCRIPTPREFIX)$*$(PY3SCRIPTSUFFIX)
ifneq (,$(PYCODESTYLE)) ifneq (,$(PYCODESTYLE))
check_pep8 = $(COMPILETOOL) $(PYCODESTYLE) $(PYCODESTYLE_FLAGS) $(SCRIPTPREFIX)$*.py check_pep8 = $(COMPILETOOL) $(PYCODESTYLE) $(PYCODESTYLE_FLAGS) $(SCRIPTPREFIX)$*.py
@ -155,70 +134,16 @@ check_pep8_multi_cpp = \
done done
endif endif
run_python = env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH PYTHONPATH=.:$(srcdir):$$PYTHONPATH $(RUNTOOL) $(PYTHON) $(py_runme) # Runs the testcase. A testcase is only run if
# a file is found which has _runme.py appended after the testcase name.
run_testcase = \ run_testcase = \
if [ -f $(SCRIPTDIR)/$(py_runme) ]; then \ if [ -f $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \
$(run_python);\ env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH PYTHONPATH=.:$(srcdir):$$PYTHONPATH $(RUNTOOL) $(PYTHON) $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); \
fi fi
# Grab runme file ready for running: copied for out of source tree builds, and/or run 2to3
# Note terminal (double colon) rules creating runme files to fix possible infinite recursion,
# see https://github.com/swig/swig/pull/688
ifeq ($(SCRIPTDIR),$(srcdir))
# in source tree build
ifeq (,$(PY3))
convert_testcase =
else
convert_testcase = \
if [ -f $(srcdir)/$(py2_runme) ]; then \
$(MAKE) $(SCRIPTDIR)/$(py_runme); \
fi
# For converting python 2 tests into Python 3 tests
$(SCRIPTDIR)/$(SCRIPTPREFIX)%$(SCRIPTSUFFIX):: $(srcdir)/$(SCRIPTPREFIX)%$(PY2SCRIPTSUFFIX)
cp $< $@
$(PY2TO3) -w $@ >/dev/null 2>&1
endif
else
# out of source tree build
ifeq (,$(PY3))
convert_testcase = \
if [ -f $(srcdir)/$(py2_runme) ]; then \
$(MAKE) $(SCRIPTDIR)/$(py_runme); \
fi
$(SCRIPTDIR)/$(SCRIPTPREFIX)%$(SCRIPTSUFFIX):: $(srcdir)/$(SCRIPTPREFIX)%$(PY2SCRIPTSUFFIX)
cp $< $@
else
convert_testcase = \
if [ -f $(srcdir)/$(py2_runme) ]; then \
$(MAKE) $(SCRIPTDIR)/$(py_runme); \
elif [ -f $(srcdir)/$(py3_runme) ]; then \
$(MAKE) $(SCRIPTDIR)/$(py3_runme); \
fi
# For when there is a _runme3.py instead of a _runme.py, ie a Python 3 only run test
$(SCRIPTDIR)/$(SCRIPTPREFIX)%$(SCRIPTSUFFIX):: $(srcdir)/$(SCRIPTPREFIX)%$(PY3SCRIPTSUFFIX)
cp $< $@
# For converting python 2 tests into Python 3 tests
$(SCRIPTDIR)/$(SCRIPTPREFIX)%$(SCRIPTSUFFIX):: $(srcdir)/$(SCRIPTPREFIX)%$(PY2SCRIPTSUFFIX)
cp $< $@
$(PY2TO3) -w $@ >/dev/null 2>&1
endif
endif
# Clean: remove the generated .py file # Clean: remove the generated .py file
# We only remove the _runme3.py if it is generated by 2to3 from a _runme.py.
%.clean: %.clean:
@rm -f $*.py @rm -f $*.py
@if test -f $(srcdir)/$(py2_runme); then rm -f $(SCRIPTDIR)/$(py3_runme) $(SCRIPTDIR)/$(py3_runme).bak; fi
@if test "x$(SCRIPTDIR)" != "x$(srcdir)"; then rm -f $(SCRIPTDIR)/$(py_runme); fi
clean: clean:
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' python_clean $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' python_clean

View file

@ -6,7 +6,6 @@ if mainc(largs) != 3:
targs = ("hi", "hola") targs = ("hi", "hola")
if mainv(targs, 1) != "hola": if mainv(targs, 1) != "hola":
print(mainv(targs, 1))
raise RuntimeError("bad main typemap") raise RuntimeError("bad main typemap")
targs = ("hi", "hola") targs = ("hi", "hola")

View file

@ -5,7 +5,7 @@ f.data = cvar.global_data
for i in range(0, 8): for i in range(0, 8):
if get_value(f.data, i) != get_value(cvar.global_data, i): if get_value(f.data, i) != get_value(cvar.global_data, i):
raise RuntimeError, "Bad array assignment" raise RuntimeError("Bad array assignment")
for i in range(0, 8): for i in range(0, 8):
@ -15,4 +15,4 @@ cvar.global_data = f.data
for i in range(0, 8): for i in range(0, 8):
if get_value(f.data, i) != get_value(cvar.global_data, i): if get_value(f.data, i) != get_value(cvar.global_data, i):
raise RuntimeError, "Bad array assignment" raise RuntimeError("Bad array assignment")

View file

@ -2,16 +2,14 @@ from char_binary import *
t = Test() t = Test()
if t.strlen("hile") != 4: if t.strlen("hile") != 4:
print t.strlen("hile") raise RuntimeError("bad multi-arg typemap {}".format(t.strlen("hile")))
raise RuntimeError, "bad multi-arg typemap"
if t.ustrlen("hile") != 4: if t.ustrlen("hile") != 4:
print t.ustrlen("hile") raise RuntimeError("bad multi-arg typemap {}".format(t.ustrlen("hile")))
raise RuntimeError, "bad multi-arg typemap"
if t.strlen("hil\0") != 4: if t.strlen("hil\0") != 4:
raise RuntimeError, "bad multi-arg typemap" raise RuntimeError("bad multi-arg typemap")
if t.ustrlen("hil\0") != 4: if t.ustrlen("hil\0") != 4:
raise RuntimeError, "bad multi-arg typemap" raise RuntimeError("bad multi-arg typemap")
# #
# creating a raw char* # creating a raw char*
@ -25,18 +23,17 @@ pchar_setitem(pc, 4, 0)
if t.strlen(pc) != 4: if t.strlen(pc) != 4:
raise RuntimeError, "bad multi-arg typemap" raise RuntimeError("bad multi-arg typemap")
if t.ustrlen(pc) != 4: if t.ustrlen(pc) != 4:
raise RuntimeError, "bad multi-arg typemap" raise RuntimeError("bad multi-arg typemap")
cvar.var_pchar = pc cvar.var_pchar = pc
if cvar.var_pchar != "hola": if cvar.var_pchar != "hola":
print cvar.var_pchar raise RuntimeError("bad pointer case {}".format(cvar.var_pchar))
raise RuntimeError, "bad pointer case"
cvar.var_namet = pc cvar.var_namet = pc
# if cvar.var_namet != "hola\0": # if cvar.var_namet != "hola\0":
if cvar.var_namet != "hola": if cvar.var_namet != "hola":
raise RuntimeError, "bad pointer case" raise RuntimeError("bad pointer case")
delete_pchar(pc) delete_pchar(pc)

View file

@ -3,16 +3,16 @@ import complextest
a = complex(-1, 2) a = complex(-1, 2)
if complextest.Conj(a) != a.conjugate(): if complextest.Conj(a) != a.conjugate():
raise RuntimeError, "bad complex mapping" raise RuntimeError("bad complex mapping")
if complextest.Conjf(a) != a.conjugate(): if complextest.Conjf(a) != a.conjugate():
raise RuntimeError, "bad complex mapping" raise RuntimeError("bad complex mapping")
if complextest.Conj2(a) != a.conjugate(): if complextest.Conj2(a) != a.conjugate():
raise RuntimeError, "bad complex mapping" raise RuntimeError("bad complex mapping")
if complextest.Conjf2(a) != a.conjugate(): if complextest.Conjf2(a) != a.conjugate():
raise RuntimeError, "bad complex mapping" raise RuntimeError("bad complex mapping")
v = (complex(1, 2), complex(2, 3), complex(4, 3), 1) v = (complex(1, 2), complex(2, 3), complex(4, 3), 1)
@ -27,4 +27,4 @@ p = complextest.ComplexPair()
p.z1 = complex(0, 1) p.z1 = complex(0, 1)
p.z2 = complex(0, -1) p.z2 = complex(0, -1)
if complextest.Conj(p.z2) != p.z1: if complextest.Conj(p.z2) != p.z1:
raise RuntimeError, "bad complex mapping" raise RuntimeError("bad complex mapping")

View file

@ -4,33 +4,26 @@ error = 0
p = constover.test("test") p = constover.test("test")
if p != "test": if p != "test":
print "test failed!" raise RuntimeError("test failed!")
error = 1
p = constover.test_pconst("test") p = constover.test_pconst("test")
if p != "test_pconst": if p != "test_pconst":
print "test_pconst failed!" raise RuntimeError("test_pconst failed!")
error = 1
f = constover.Foo() f = constover.Foo()
p = f.test("test") p = f.test("test")
if p != "test": if p != "test":
print "member-test failed!" raise RuntimeError("member-test failed!")
error = 1
p = f.test_pconst("test") p = f.test_pconst("test")
if p != "test_pconst": if p != "test_pconst":
print "member-test_pconst failed!" raise RuntimeError("member-test_pconst failed!")
error = 1
p = f.test_constm("test") p = f.test_constm("test")
if p != "test_constmethod": if p != "test_constmethod":
print "member-test_constm failed!" raise RuntimeError("member-test_constm failed!")
error = 1
p = f.test_pconstm("test") p = f.test_pconstm("test")
if p != "test_pconstmethod": if p != "test_pconstmethod":
print "member-test_pconstm failed!" raise RuntimeError("member-test_pconstm failed!")
error = 1
sys.exit(error)

View file

@ -2,141 +2,141 @@ import contract
contract.test_preassert(1, 2) contract.test_preassert(1, 2)
try: try:
contract.test_preassert(-1) contract.test_preassert(-1, 3)
print "Failed! Preassertions are broken" raise Exception("Failed! Preassertions are broken")
except: except RuntimeError:
pass pass
contract.test_postassert(3) contract.test_postassert(3)
try: try:
contract.test_postassert(-3) contract.test_postassert(-3)
print "Failed! Postassertions are broken" raise Exception("Failed! Postassertions are broken")
except: except RuntimeError:
pass pass
contract.test_prepost(2, 3) contract.test_prepost(2, 3)
contract.test_prepost(5, -4) contract.test_prepost(5, -4)
try: try:
contract.test_prepost(-3, 4) contract.test_prepost(-3, 4)
print "Failed! Preassertions are broken" raise Exception("Failed! Preassertions are broken")
except: except RuntimeError:
pass pass
try: try:
contract.test_prepost(4, -10) contract.test_prepost(4, -10)
print "Failed! Postassertions are broken" raise Exception("Failed! Postassertions are broken")
except: except RuntimeError:
pass pass
f = contract.Foo() f = contract.Foo()
f.test_preassert(4, 5) f.test_preassert(4, 5)
try: try:
f.test_preassert(-2, 3) f.test_preassert(-2, 3)
print "Failed! Method preassertion." raise Exception("Failed! Method preassertion.")
except: except RuntimeError:
pass pass
f.test_postassert(4) f.test_postassert(4)
try: try:
f.test_postassert(-4) f.test_postassert(-4)
print "Failed! Method postassertion" raise Exception("Failed! Method postassertion")
except: except RuntimeError:
pass pass
f.test_prepost(3, 4) f.test_prepost(3, 4)
f.test_prepost(4, -3) f.test_prepost(4, -3)
try: try:
f.test_prepost(-4, 2) f.test_prepost(-4, 2)
print "Failed! Method preassertion." raise Exception("Failed! Method preassertion.")
except: except RuntimeError:
pass pass
try: try:
f.test_prepost(4, -10) f.test_prepost(4, -10)
print "Failed! Method postassertion." raise Exception("Failed! Method postassertion.")
except: except RuntimeError:
pass pass
contract.Foo_stest_prepost(4, 0) contract.Foo_stest_prepost(4, 0)
try: try:
contract.Foo_stest_prepost(-4, 2) contract.Foo_stest_prepost(-4, 2)
print "Failed! Static method preassertion" raise Exception("Failed! Static method preassertion")
except: except RuntimeError:
pass pass
try: try:
contract.Foo_stest_prepost(4, -10) contract.Foo_stest_prepost(4, -10)
print "Failed! Static method posteassertion" raise Exception("Failed! Static method posteassertion")
except: except RuntimeError:
pass pass
b = contract.Bar() b = contract.Bar()
try: try:
b.test_prepost(2, -4) b.test_prepost(2, -4)
print "Failed! Inherited preassertion." raise Exception("Failed! Inherited preassertion.")
except: except RuntimeError:
pass pass
d = contract.D() d = contract.D()
try: try:
d.foo(-1, 1, 1, 1, 1) d.foo(-1, 1, 1, 1, 1)
print "Failed! Inherited preassertion (D)." raise Exception("Failed! Inherited preassertion (D).")
except: except RuntimeError:
pass pass
try: try:
d.foo(1, -1, 1, 1, 1) d.foo(1, -1, 1, 1, 1)
print "Failed! Inherited preassertion (D)." raise Exception("Failed! Inherited preassertion (D).")
except: except RuntimeError:
pass pass
try: try:
d.foo(1, 1, -1, 1, 1) d.foo(1, 1, -1, 1, 1)
print "Failed! Inherited preassertion (D)." raise Exception("Failed! Inherited preassertion (D).")
except: except RuntimeError:
pass pass
try: try:
d.foo(1, 1, 1, -1, 1) d.foo(1, 1, 1, -1, 1)
print "Failed! Inherited preassertion (D)." raise Exception("Failed! Inherited preassertion (D).")
except: except RuntimeError:
pass pass
try: try:
d.foo(1, 1, 1, 1, -1) d.foo(1, 1, 1, 1, -1)
print "Failed! Inherited preassertion (D)." raise Exception("Failed! Inherited preassertion (D).")
except: except RuntimeError:
pass pass
try: try:
d.bar(-1, 1, 1, 1, 1) d.bar(-1, 1, 1, 1, 1)
print "Failed! Inherited preassertion (D)." raise Exception("Failed! Inherited preassertion (D).")
except: except RuntimeError:
pass pass
try: try:
d.bar(1, -1, 1, 1, 1) d.bar(1, -1, 1, 1, 1)
print "Failed! Inherited preassertion (D)." raise Exception("Failed! Inherited preassertion (D).")
except: except RuntimeError:
pass pass
try: try:
d.bar(1, 1, -1, 1, 1) d.bar(1, 1, -1, 1, 1)
print "Failed! Inherited preassertion (D)." raise Exception("Failed! Inherited preassertion (D).")
except: except RuntimeError:
pass pass
try: try:
d.bar(1, 1, 1, -1, 1) d.bar(1, 1, 1, -1, 1)
print "Failed! Inherited preassertion (D)." raise Exception("Failed! Inherited preassertion (D).")
except: except RuntimeError:
pass pass
try: try:
d.bar(1, 1, 1, 1, -1) d.bar(1, 1, 1, 1, -1)
print "Failed! Inherited preassertion (D)." raise Exception("Failed! Inherited preassertion (D).")
except: except RuntimeError:
pass pass
# Namespace # Namespace
my = contract.myClass(1) my = contract.myClass(1)
try: try:
my = contract.myClass(0) my = contract.myClass(0)
print "Failed! constructor preassertion" raise Exception("Failed! constructor preassertion")
except: except RuntimeError:
pass pass

View file

@ -4,20 +4,20 @@ a = cpp11_alternate_function_syntax.SomeStruct()
res = a.addNormal(4, 5) res = a.addNormal(4, 5)
if res != 9: if res != 9:
raise RuntimeError, ("SomeStruct::addNormal(4,5) returns ", res, " should be 9.") raise RuntimeError("SomeStruct::addNormal(4,5) returns ", res, " should be 9.")
res = a.addAlternate(4, 5) res = a.addAlternate(4, 5)
if res != 9: if res != 9:
raise RuntimeError, ("SomeStruct::addAlternate(4,5) returns ", res, " should be 9.") raise RuntimeError("SomeStruct::addAlternate(4,5) returns ", res, " should be 9.")
res = a.addAlternateConst(4, 5) res = a.addAlternateConst(4, 5)
if res != 9: if res != 9:
raise RuntimeError, ("SomeStruct::addAlternateConst(4,5) returns ", res, " should be 9.") raise RuntimeError("SomeStruct::addAlternateConst(4,5) returns ", res, " should be 9.")
res = a.addAlternateNoExcept(4, 5) res = a.addAlternateNoExcept(4, 5)
if res != 9: if res != 9:
raise RuntimeError, ("SomeStruct::addAlternateNoExcept(4,5) returns ", res, " should be 9.") raise RuntimeError("SomeStruct::addAlternateNoExcept(4,5) returns ", res, " should be 9.")
res = a.addAlternateConstNoExcept(4, 5) res = a.addAlternateConstNoExcept(4, 5)
if res != 9: if res != 9:
raise RuntimeError, ("SomeStruct::addAlternateConstNoExcept(4,5) returns ", res, " should be 9.") raise RuntimeError("SomeStruct::addAlternateConstNoExcept(4,5) returns ", res, " should be 9.")

View file

@ -3,16 +3,16 @@ import cpp11_decltype
a = cpp11_decltype.A() a = cpp11_decltype.A()
a.i = 5 a.i = 5
if a.i != 5: if a.i != 5:
raise RuntimeError, "Assignment to a.i failed." raise RuntimeError("Assignment to a.i failed.")
a.j = 10 a.j = 10
if a.j != 10: if a.j != 10:
raise RuntimeError, "Assignment to a.j failed." raise RuntimeError("Assignment to a.j failed.")
b = a.foo(5) b = a.foo(5)
if b != 10: if b != 10:
raise RuntimeError, "foo(5) should return 10." raise RuntimeError("foo(5) should return 10.")
b = a.foo(6) b = a.foo(6)
if b != 0: if b != 0:
raise RuntimeError, "foo(6) should return 0." raise RuntimeError("foo(6) should return 0.")

View file

@ -10,14 +10,14 @@ for x in [cpp11_hash_tables.MapIntInt({1:7}),
cpp11_hash_tables.UnorderedMultiMapIntInt({1:7}) cpp11_hash_tables.UnorderedMultiMapIntInt({1:7})
]: ]:
swig_assert_equal([(k, v) for k, v in x.iteritems()], [(1, 7)]) swig_assert_equal([(k, v) for k, v in x.items()], [(1, 7)])
swig_assert_equal(x.keys(), [1]) swig_assert_equal(list(x.keys()), [1])
swig_assert_equal(x.values(), [7]) swig_assert_equal(list(x.values()), [7])
swig_assert_equal(x.items(), [(1, 7)]) swig_assert_equal(list(x.items()), [(1, 7)])
swig_assert_equal([k for k in x], [1]) swig_assert_equal([k for k in x], [1])
swig_assert_equal([i for i in x.iterkeys()], [1]) swig_assert_equal([i for i in x.keys()], [1])
swig_assert_equal([i for i in x.itervalues()], [7]) swig_assert_equal([i for i in x.values()], [7])
swig_assert_equal([i for i in x.iteritems()], [(1, 7)]) swig_assert_equal([i for i in x.items()], [(1, 7)])
swig_assert_equal(x[1], 7) swig_assert_equal(x[1], 7)
swig_assert_equal(2 in x, False) swig_assert_equal(2 in x, False)
@ -33,7 +33,7 @@ for x in [cpp11_hash_tables.MapIntInt({1:7}),
for x in [cpp11_hash_tables.MultiMapIntInt({1:7}), for x in [cpp11_hash_tables.MultiMapIntInt({1:7}),
cpp11_hash_tables.UnorderedMultiMapIntInt({1:7})]: cpp11_hash_tables.UnorderedMultiMapIntInt({1:7})]:
x[1] = 9 x[1] = 9
swig_assert_equal(sorted([v for k, v in x.iteritems()]), [7, 9]) swig_assert_equal(sorted([v for k, v in x.items()]), [7, 9])
swig_assert_equal(len(x), 2) swig_assert_equal(len(x), 2)
for x in [cpp11_hash_tables.SetInt([1]), for x in [cpp11_hash_tables.SetInt([1]),

View file

@ -3,15 +3,15 @@ import cpp11_null_pointer_constant
a = cpp11_null_pointer_constant.A() a = cpp11_null_pointer_constant.A()
if a._myA != None: if a._myA != None:
raise RuntimeError, ( raise RuntimeError(
"cpp11_null_pointer_constant: _myA should be None, but is ", a._myA) "cpp11_null_pointer_constant: _myA should be None, but is ", a._myA)
b = cpp11_null_pointer_constant.A() b = cpp11_null_pointer_constant.A()
if a._myA != b._myA: if a._myA != b._myA:
raise RuntimeError, ( raise RuntimeError(
"cpp11_null_pointer_constant: a._myA should be the same as b._myA, but ", a._myA, "!=", b._myA) "cpp11_null_pointer_constant: a._myA should be the same as b._myA, but ", a._myA, "!=", b._myA)
a._myA = cpp11_null_pointer_constant.A() a._myA = cpp11_null_pointer_constant.A()
if a._myA == None: if a._myA == None:
raise RuntimeError, ( raise RuntimeError((
"cpp11_null_pointer_constant: _myA should be object, but is None") "cpp11_null_pointer_constant: _myA should be object, but is None"))

View file

@ -34,19 +34,19 @@ if cvar.aa != "Wide string":
raise RuntimeError raise RuntimeError
if cvar.bb != "UTF-8 string": if cvar.bb != "UTF-8 string":
raise RuntimeError, cvar.wide raise RuntimeError(cvar.wide)
if cvar.xx != ")I'm an \"ascii\" \\ string.": if cvar.xx != ")I'm an \"ascii\" \\ string.":
raise RuntimeError, cvar.xx raise RuntimeError(cvar.xx)
if cvar.ee != ")I'm an \"ascii\" \\ string.": if cvar.ee != ")I'm an \"ascii\" \\ string.":
raise RuntimeError, cvar.ee raise RuntimeError(cvar.ee)
if cvar.ff != "I'm a \"raw wide\" \\ string.": if cvar.ff != "I'm a \"raw wide\" \\ string.":
raise RuntimeError, cvar.ff raise RuntimeError(cvar.ff)
if cvar.gg != "I'm a \"raw UTF-8\" \\ string.": if cvar.gg != "I'm a \"raw UTF-8\" \\ string.":
raise RuntimeError, cvar.gg raise RuntimeError(cvar.gg)
def check(got, expected): def check(got, expected):

View file

@ -2,10 +2,10 @@ import cpp11_result_of
result = cpp11_result_of.test_result(cpp11_result_of.SQUARE, 3.0) result = cpp11_result_of.test_result(cpp11_result_of.SQUARE, 3.0)
if result != 9.0: if result != 9.0:
raise RuntimeError, "test_result(square, 3.0) is not 9.0. Got: " + str( raise RuntimeError("test_result(square, 3.0) is not 9.0. Got: " + str(
result) result))
result = cpp11_result_of.test_result_alternative1(cpp11_result_of.SQUARE, 3.0) result = cpp11_result_of.test_result_alternative1(cpp11_result_of.SQUARE, 3.0)
if result != 9.0: if result != 9.0:
raise RuntimeError, "test_result_alternative1(square, 3.0) is not 9.0. Got: " + str( raise RuntimeError("test_result_alternative1(square, 3.0) is not 9.0. Got: " + str(
result) result))

View file

@ -4,24 +4,24 @@ a = cpp11_rvalue_reference.A()
a.setAcopy(5) a.setAcopy(5)
if a.getAcopy() != 5: if a.getAcopy() != 5:
raise RunTimeError, ("int A::getAcopy() value is ", raise RunTimeError("int A::getAcopy() value is ",
a.getAcopy(), " should be 5") a.getAcopy(), " should be 5")
ptr = a.getAptr() ptr = a.getAptr()
a.setAptr(ptr) a.setAptr(ptr)
if a.getAcopy() != 5: if a.getAcopy() != 5:
raise RunTimeError, ("after A::setAptr(): int A::getAcopy() value is ", a.getAcopy( raise RunTimeError("after A::setAptr(): int A::getAcopy() value is ", a.getAcopy(
), " should be 5") ), " should be 5")
a.setAref(ptr) a.setAref(ptr)
if a.getAcopy() != 5: if a.getAcopy() != 5:
raise RunTimeError, ("after A::setAref(): int A::getAcopy() value is ", a.getAcopy( raise RunTimeError("after A::setAref(): int A::getAcopy() value is ", a.getAcopy(
), " should be 5") ), " should be 5")
rvalueref = a.getAmove() rvalueref = a.getAmove()
a.setAmove(rvalueref) a.setAmove(rvalueref)
if a.getAcopy() != 5: if a.getAcopy() != 5:
raise RunTimeError, ("after A::setAmove(): int A::getAcopy() value is ", a.getAcopy( raise RunTimeError("after A::setAmove(): int A::getAcopy() value is ", a.getAcopy(
), " should be 5") ), " should be 5")

View file

@ -3,7 +3,7 @@ import sys
def failed(a, b, msg): def failed(a, b, msg):
raise RuntimeError, msg + " " + str(list(a)) + " " + str(list(b)) raise RuntimeError(msg + " " + str(list(a)) + " " + str(list(b)))
def compare_sequences(a, b): def compare_sequences(a, b):
@ -26,8 +26,8 @@ def steps_exception(swigarray, i, j, step):
a = swigarray[i::step] a = swigarray[i::step]
else: else:
a = swigarray[i:j:step] a = swigarray[i:j:step]
raise RuntimeError, "swigarray[" + str(i) + ":" + str(j) + ":" + str(step) + "] missed steps exception for " + str(list(swigarray)) raise RuntimeError("swigarray[" + str(i) + ":" + str(j) + ":" + str(step) + "] missed steps exception for " + str(list(swigarray)))
except ValueError, e: except ValueError as e:
# print("exception: {}".format(e)) # print("exception: {}".format(e))
pass pass
@ -43,16 +43,16 @@ def del_exception(swigarray, i, j, step):
del swigarray[i::step] del swigarray[i::step]
else: else:
del swigarray[i:j:step] del swigarray[i:j:step]
raise RuntimeError, "swigarray[" + str(i) + ":" + str(j) + ":" + str(step) + "] missed del exception for " + str(list(swigarray)) raise RuntimeError("swigarray[" + str(i) + ":" + str(j) + ":" + str(step) + "] missed del exception for " + str(list(swigarray)))
except ValueError, e: except ValueError as e:
# print("exception: {}".format(e)) # print("exception: {}".format(e))
pass pass
def setslice_exception(swigarray, newval): def setslice_exception(swigarray, newval):
try: try:
swigarray[::] = newval swigarray[::] = newval
raise RuntimeError, "swigarray[::] = " + str(newval) + " missed set exception for swigarray:" + str(list(swigarray)) raise RuntimeError("swigarray[::] = " + str(newval) + " missed set exception for swigarray:" + str(list(swigarray)))
except TypeError, e: except TypeError as e:
# print("exception: {}".format(e)) # print("exception: {}".format(e))
pass pass

View file

@ -9,13 +9,13 @@ if var2.getX() != 2:
m = cpp11_uniform_initialization.MoreInit() m = cpp11_uniform_initialization.MoreInit()
if m.charptr != None: if m.charptr != None:
raise RuntimeError, m.charptr raise RuntimeError(m.charptr)
m.charptr = "hello sir" m.charptr = "hello sir"
if m.charptr != "hello sir": if m.charptr != "hello sir":
raise RuntimeError, m.charptr raise RuntimeError(m.charptr)
if m.more1(m.vi) != 15: if m.more1(m.vi) != 15:
raise RuntimeError, m.vi raise RuntimeError(m.vi)
if m.more1([-1, 1, 2]) != 2: if m.more1([-1, 1, 2]) != 2:
raise RuntimeError, m.vi raise RuntimeError(m.vi)
if m.more1() != 10: if m.more1() != 10:
raise RuntimeError raise RuntimeError

View file

@ -3,21 +3,17 @@ import cpp_enum
f = cpp_enum.Foo() f = cpp_enum.Foo()
if f.hola != f.Hello: if f.hola != f.Hello:
print f.hola raise RuntimeError("f.hola: {}".format(f.hola))
raise RuntimeError
f.hola = f.Hi f.hola = f.Hi
if f.hola != f.Hi: if f.hola != f.Hi:
print f.hola raise RuntimeError("f.hola: {}".format(f.hola))
raise RuntimeError
f.hola = f.Hello f.hola = f.Hello
if f.hola != f.Hello: if f.hola != f.Hello:
print f.hola raise RuntimeError("f.hola: {}".format(f.hola))
raise RuntimeError
cpp_enum.cvar.hi = cpp_enum.Hello cpp_enum.cvar.hi = cpp_enum.Hello
if cpp_enum.cvar.hi != cpp_enum.Hello: if cpp_enum.cvar.hi != cpp_enum.Hello:
print cpp_enum.cvar.hi raise RuntimeError("cpp_enum.cvar.hi: {}".format(cpp_enum.cvar.hi))
raise RuntimeError

View file

@ -108,48 +108,34 @@ def run(module_name):
if Klass_inc().val != 0: if Klass_inc().val != 0:
raise RuntimeError("Klass::inc failed") raise RuntimeError("Klass::inc failed")
tricky_failure = False
tricky = default_args.TrickyInPython() tricky = default_args.TrickyInPython()
if tricky.value_m1(10) != -1: if tricky.value_m1(10) != -1:
print "trickyvalue_m1 failed" raise RuntimeError("trickyvalue_m1 failed")
tricky_failure = True
if tricky.value_m1(10, 10) != 10: if tricky.value_m1(10, 10) != 10:
print "trickyvalue_m1 failed" raise RuntimeError("trickyvalue_m1 failed")
tricky_failure = True
if tricky.value_0xabcdef(10) != 0xabcdef: if tricky.value_0xabcdef(10) != 0xabcdef:
print "trickyvalue_0xabcdef failed" raise RuntimeError("trickyvalue_0xabcdef failed")
tricky_failure = True
if tricky.value_0644(10) != 420: if tricky.value_0644(10) != 420:
print "trickyvalue_0644 failed" raise RuntimeError("trickyvalue_0644 failed")
tricky_failure = True
if tricky.value_perm(10) != 420: if tricky.value_perm(10) != 420:
print "trickyvalue_perm failed" raise RuntimeError("trickyvalue_perm failed")
tricky_failure = True
if tricky.value_m01(10) != -1: if tricky.value_m01(10) != -1:
print "trickyvalue_m01 failed" raise RuntimeError("trickyvalue_m01 failed")
tricky_failure = True
if not tricky.booltest2(): if not tricky.booltest2():
print "booltest2 failed" raise RuntimeError("booltest2 failed")
tricky_failure = True
if tricky.max_32bit_int1() != 0x7FFFFFFF: if tricky.max_32bit_int1() != 0x7FFFFFFF:
print "max_32bit_int1 failed" raise RuntimeError("max_32bit_int1 failed")
tricky_failure = True
if tricky.min_32bit_int1() != -2147483648: if tricky.min_32bit_int1() != -2147483648:
print "min_32bit_int1 failed" raise RuntimeError("min_32bit_int1 failed")
tricky_failure = True
if tricky.max_32bit_int2() != 0x7FFFFFFF: if tricky.max_32bit_int2() != 0x7FFFFFFF:
print "max_32bit_int2 failed" raise RuntimeError("max_32bit_int2 failed")
tricky_failure = True
tricky.too_big_32bit_int1() tricky.too_big_32bit_int1()
tricky.too_small_32bit_int1() tricky.too_small_32bit_int1()
tricky.too_big_32bit_int2() tricky.too_big_32bit_int2()
tricky.too_small_32bit_int2() tricky.too_small_32bit_int2()
if tricky_failure:
raise RuntimeError
default_args.seek() default_args.seek()
default_args.seek(10) default_args.seek(10)

View file

@ -16,24 +16,24 @@ dc.delete_AA(aa)
try: try:
b = dc.new_B() b = dc.new_B()
print "Whoa. new_BB created." raise RuntimeError("Whoa. new_BB created.")
except: except TypeError:
pass pass
del_b = dc.delete_B del_b = dc.delete_B
try: try:
bb = dc.new_BB() bb = dc.new_BB()
print "Whoa. new_BB created." raise RuntimeError("Whoa. new_BB created.")
except: except AttributeError:
pass pass
del_bb = dc.delete_BB del_bb = dc.delete_BB
try: try:
c = dc.new_C() c = dc.new_C()
print "Whoa. new_C created." raise RuntimeError("Whoa. new_C created.")
except: except AttributeError:
pass pass
del_c = dc.delete_C del_c = dc.delete_C
@ -43,24 +43,24 @@ dc.delete_CC(cc)
try: try:
d = dc.new_D() d = dc.new_D()
print "Whoa. new_D created" raise RuntimeError("Whoa. new_D created")
except: except AttributeError:
pass pass
del_d = dc.delete_D del_d = dc.delete_D
try: try:
dd = dc.new_DD() dd = dc.new_DD()
print "Whoa. new_DD created" raise RuntimeError("Whoa. new_DD created")
except: except AttributeError:
pass pass
dd = dc.delete_DD dd = dc.delete_DD
try: try:
ad = dc.new_AD() ad = dc.new_AD()
print "Whoa. new_AD created" raise RuntimeError("Whoa. new_AD created")
except: except AttributeError:
pass pass
del_ad = dc.delete_AD del_ad = dc.delete_AD
@ -73,8 +73,8 @@ dc.delete_EE(ee)
try: try:
eb = dc.new_EB() eb = dc.new_EB()
print "Whoa. new_EB created" raise RuntimeError("Whoa. new_EB created")
except: except AttributeError:
pass pass
del_eb = dc.delete_EB del_eb = dc.delete_EB
@ -83,7 +83,7 @@ f = dc.new_F()
try: try:
del_f = dc.delete_F del_f = dc.delete_F
print "Whoa. delete_F created" raise RuntimeError("Whoa. delete_F created")
except AttributeError: except AttributeError:
pass pass
@ -93,7 +93,7 @@ g = dc.new_G()
try: try:
del_g = dc.delete_G del_g = dc.delete_G
print "Whoa. delete_G created" raise RuntimeError("Whoa. delete_G created")
except AttributeError: except AttributeError:
pass pass

View file

@ -13,10 +13,10 @@ class MyFoo(director_abstract.Foo):
a = MyFoo() a = MyFoo()
if a.ping() != "MyFoo::ping()": if a.ping() != "MyFoo::ping()":
raise RuntimeError, a.ping() raise RuntimeError(a.ping())
if a.pong() != "Foo::pong();MyFoo::ping()": if a.pong() != "Foo::pong();MyFoo::ping()":
raise RuntimeError, a.pong() raise RuntimeError(a.pong())
class MyExample1(director_abstract.Example1): class MyExample1(director_abstract.Example1):

View file

@ -2,4 +2,4 @@ from director_alternating import *
id = getBar().id() id = getBar().id()
if id != idFromGetBar(): if id != idFromGetBar():
raise RuntimeError, "Got wrong id: " + str(id) raise RuntimeError("Got wrong id: " + str(id))

View file

@ -10,18 +10,18 @@ class PyFoo(director_basic.Foo):
a = PyFoo() a = PyFoo()
if a.ping() != "PyFoo::ping()": if a.ping() != "PyFoo::ping()":
raise RuntimeError, a.ping() raise RuntimeError(a.ping())
if a.pong() != "Foo::pong();PyFoo::ping()": if a.pong() != "Foo::pong();PyFoo::ping()":
raise RuntimeError, a.pong() raise RuntimeError(a.pong())
b = director_basic.Foo() b = director_basic.Foo()
if b.ping() != "Foo::ping()": if b.ping() != "Foo::ping()":
raise RuntimeError, b.ping() raise RuntimeError(b.ping())
if b.pong() != "Foo::pong();Foo::ping()": if b.pong() != "Foo::pong();Foo::ping()":
raise RuntimeError, b.pong() raise RuntimeError(b.pong())
a = director_basic.A1(1) a = director_basic.A1(1)

View file

@ -8,4 +8,4 @@ class PyFoo(director_comparison_operators.Foo):
a = PyFoo() a = PyFoo()
if a.test() != "a=1,b=2": if a.test() != "a=1,b=2":
raise RuntimeError, a.test() raise RuntimeError(a.test())

View file

@ -35,4 +35,4 @@ c = b.clone()
vc = c.get_value() vc = c.get_value()
if (v != 3) or (b.val != 5) or (vc != 6): if (v != 3) or (b.val != 5) or (vc != 6):
raise RuntimeError, "Bad virtual detection" raise RuntimeError("Bad virtual detection")

View file

@ -10,7 +10,7 @@ class MyException(Exception):
class MyFoo(Foo): class MyFoo(Foo):
def ping(self): def ping(self):
raise NotImplementedError, "MyFoo::ping() EXCEPTION" raise NotImplementedError("MyFoo::ping() EXCEPTION")
class MyFoo2(Foo): class MyFoo2(Foo):
@ -28,74 +28,58 @@ class MyFoo3(Foo):
class MyFoo4(Foo): class MyFoo4(Foo):
def ping(self, *args): def ping(self, *args):
print(type("bad", "call")) # throws TypeError message: type() takes 1 or 3 arguments t = type("bad", "call") # throws TypeError message: type() takes 1 or 3 arguments
return "Foo4.ping" return "Foo4.ping"
# Check that the NotImplementedError raised by MyFoo.ping() is returned by # Check that the NotImplementedError raised by MyFoo.ping() is returned by
# MyFoo.pong(). # MyFoo.pong().
ok = 0
a = MyFoo() a = MyFoo()
b = launder(a) b = launder(a)
try: try:
b.pong() b.pong()
except NotImplementedError, e: raise RuntimeError("Exception was not thrown")
if str(e) == "MyFoo::ping() EXCEPTION": except NotImplementedError as e:
ok = 1 if not str(e) == "MyFoo::ping() EXCEPTION":
else: raise RuntimeError("Unexpected error message: %s" % str(e))
print "Unexpected error message: %s" % str(e) except TypeError:
except:
pass pass
if not ok:
raise RuntimeError
# Check that the director returns the appropriate TypeError if the return type # Check that the director returns the appropriate TypeError if the return type
# is wrong. # is wrong.
ok = 0
a = MyFoo2() a = MyFoo2()
b = launder(a) b = launder(a)
try: try:
b.pong() b.pong()
except TypeError, e: raise RuntimeError("Exception was not thrown")
except TypeError as e:
# fastdispatch mode adds on Additional Information to the exception message - just check the main exception message exists # fastdispatch mode adds on Additional Information to the exception message - just check the main exception message exists
if str(e).startswith("SWIG director type mismatch in output value of type 'std::string'"): if not str(e).startswith("SWIG director type mismatch in output value of type 'std::string'"):
ok = 1 raise RuntimeError("Unexpected error message: %s" % str(e))
else:
print "Unexpected error message: %s" % str(e)
if not ok:
raise RuntimeError
# Check that the director can return an exception which requires two arguments # Check that the director can return an exception which requires two arguments
# to the constructor, without mangling it. # to the constructor, without mangling it.
ok = 0
a = MyFoo3() a = MyFoo3()
b = launder(a) b = launder(a)
try: try:
b.pong() b.pong()
except MyException, e: raise RuntimeError("Exception was not thrown")
if e.msg == "foobar": except MyException as e:
ok = 1 if e.msg != "foobar":
else: raise RuntimeError("Unexpected error message: %s" % str(e))
print "Unexpected error message: %s" % str(e)
if not ok:
raise RuntimeError
# Check that the director returns the appropriate TypeError thrown in a director method # Check that the director returns the appropriate TypeError thrown in a director method
ok = 0
a = MyFoo4() a = MyFoo4()
b = launder(a) b = launder(a)
try: try:
b.pong() b.pong()
raise RuntimeError("Exception was not thrown")
except TypeError as e: except TypeError as e:
if str(e).startswith("type() takes 1 or 3 arguments"): if not str(e).startswith("type() takes 1 or 3 arguments"):
ok = 1 raise RuntimeError("Unexpected error message: %s" % str(e))
else:
print "Unexpected error message: %s" % str(e)
if not ok:
raise RuntimeError
# This is expected to fail with -builtin option # This is expected to fail with -builtin option

View file

@ -17,6 +17,6 @@ class MyObject(SpObject):
m = MyObject() m = MyObject()
if m.dummy() != 666: if m.dummy() != 666:
raise RuntimeError, "1st call" raise RuntimeError("1st call")
if m.dummy() != 666: # Locked system if m.dummy() != 666: # Locked system
raise RuntimeError, "2nd call" raise RuntimeError("2nd call")

View file

@ -4,4 +4,4 @@ foo = Bravo()
s = foo.abs_method() s = foo.abs_method()
if s != "Bravo::abs_method()": if s != "Bravo::abs_method()":
raise RuntimeError, s raise RuntimeError(s)

View file

@ -14,7 +14,7 @@ class A(FooBar_int):
a = A() a = A()
if a.step() != "Bar::step;Foo::advance;Bar::do_advance;A::do_step;": if a.step() != "Bar::step;Foo::advance;Bar::do_advance;A::do_step;":
raise RuntimeError, "Bad A virtual resolution" raise RuntimeError("Bad A virtual resolution")
class B(FooBar_int): class B(FooBar_int):
@ -34,7 +34,7 @@ class B(FooBar_int):
b = B() b = B()
if b.step() != "Bar::step;Foo::advance;B::do_advance;B::do_step;": if b.step() != "Bar::step;Foo::advance;B::do_advance;B::do_step;":
raise RuntimeError, "Bad B virtual resolution" raise RuntimeError("Bad B virtual resolution")
class C(FooBar_int): class C(FooBar_int):

View file

@ -38,4 +38,4 @@ while i:
a = fi(a) # 20 a = fi(a) # 20
i -= 1 i -= 1
print a print("a: {}".format(a))

View file

@ -35,7 +35,7 @@ try:
raise RuntimeError raise RuntimeError
pass pass
except: except:
raise RuntimeError, "bad FooBar::used" raise RuntimeError("bad FooBar::used")
try: try:
s = fb2.used() s = fb2.used()
@ -43,7 +43,7 @@ try:
raise RuntimeError raise RuntimeError
pass pass
except: except:
raise RuntimeError, "bad FooBar2::used" raise RuntimeError("bad FooBar2::used")
try: try:
s = b.pong() s = b.pong()
@ -51,7 +51,7 @@ try:
raise RuntimeError raise RuntimeError
pass pass
except: except:
raise RuntimeError, "bad Bar::pong" raise RuntimeError("bad Bar::pong")
try: try:
s = f.pong() s = f.pong()
@ -59,7 +59,7 @@ try:
raise RuntimeError raise RuntimeError
pass pass
except: except:
raise RuntimeError, " bad Foo::pong" raise RuntimeError(" bad Foo::pong")
try: try:
s = fb.pong() s = fb.pong()
@ -67,7 +67,7 @@ try:
raise RuntimeError raise RuntimeError
pass pass
except: except:
raise RuntimeError, " bad FooBar::pong" raise RuntimeError(" bad FooBar::pong")
protected = 1 protected = 1
try: try:
@ -76,7 +76,7 @@ try:
except: except:
pass pass
if not protected: if not protected:
raise RuntimeError, "Foo::ping is protected" raise RuntimeError("Foo::ping is protected")
protected = 1 protected = 1
try: try:
@ -85,7 +85,7 @@ try:
except: except:
pass pass
if not protected: if not protected:
raise RuntimeError, "Foo::ping is protected" raise RuntimeError("Foo::ping is protected")
protected = 1 protected = 1
@ -95,7 +95,7 @@ try:
except: except:
pass pass
if not protected: if not protected:
raise RuntimeError, "FooBar::pang is protected" raise RuntimeError("FooBar::pang is protected")
protected = 1 protected = 1
@ -105,7 +105,7 @@ try:
except: except:
pass pass
if not protected: if not protected:
raise RuntimeError, "Bar::cheer is protected" raise RuntimeError("Bar::cheer is protected")
protected = 1 protected = 1
try: try:
@ -114,19 +114,19 @@ try:
except: except:
pass pass
if not protected: if not protected:
raise RuntimeError, "Foo::cheer is protected" raise RuntimeError("Foo::cheer is protected")
if fb3.cheer() != "FooBar3::cheer();": if fb3.cheer() != "FooBar3::cheer();":
raise RuntimeError, "bad fb3::cheer" raise RuntimeError("bad fb3::cheer")
if fb2.callping() != "FooBar2::ping();": if fb2.callping() != "FooBar2::ping();":
raise RuntimeError, "bad fb2.callping" raise RuntimeError("bad fb2.callping")
if fb2.callcheer() != "FooBar2::pang();Bar::pong();Foo::pong();FooBar2::ping();": if fb2.callcheer() != "FooBar2::pang();Bar::pong();Foo::pong();FooBar2::ping();":
raise RuntimeError, "bad fb2.callcheer" raise RuntimeError("bad fb2.callcheer")
if fb3.callping() != "Bar::ping();": if fb3.callping() != "Bar::ping();":
raise RuntimeError, "bad fb3.callping" raise RuntimeError("bad fb3.callping")
if fb3.callcheer() != "FooBar3::cheer();": if fb3.callcheer() != "FooBar3::cheer();":
raise RuntimeError, "bad fb3.callcheer" raise RuntimeError("bad fb3.callcheer")

View file

@ -31,7 +31,7 @@ class director_smartptr_MyBarFooDerived(FooDerived):
def check(got, expected): def check(got, expected):
if (got != expected): if (got != expected):
raise RuntimeError, "Failed, got: " + got + " expected: " + expected raise RuntimeError("Failed, got: " + got + " expected: " + expected)
fooBar = FooBar() fooBar = FooBar()

View file

@ -18,12 +18,10 @@ b = B("hello")
b.get(0) b.get(0)
if b.get_first() != "hello world!": if b.get_first() != "hello world!":
print b.get_first() raise RuntimeError("b.get_first(): {}".format(b.get_first()))
raise RuntimeError
b.call_process_func() b.call_process_func()
if b.smem != "hello": if b.smem != "hello":
print smem raise RuntimeError("smem: {}".format(smem))
raise RuntimeError

View file

@ -14,7 +14,6 @@ d = Derived()
d.run() d.run()
if d.val >= 0: if d.val >= 0:
print d.val raise RuntimeError("d.val: {}".format(d.val))
raise RuntimeError
d.stop() d.stop()

View file

@ -16,5 +16,4 @@ c = b.get()
if not (a.this == c.this): if not (a.this == c.this):
print a, c raise RuntimeError("{} {}".format(a, c))
raise RuntimeError

View file

@ -7,22 +7,20 @@ class B(A):
A.__init__(self, string) A.__init__(self, string)
def get_first(self): def get_first(self):
return A.get_first(self) + u" world!" return A.get_first(self) + " world!"
def process_text(self, s): def process_text(self, s):
self.smem = s self.smem = s
b = B(u"hello") b = B("hello")
b.get(0) b.get(0)
if b.get_first() != u"hello world!": if b.get_first() != "hello world!":
print b.get_first() raise RuntimeError("b.get_first(): {}".format(b.get_first()))
raise RuntimeError
b.call_process_func() b.call_process_func()
if b.smem != u"hello": if b.smem != "hello":
print smem raise RuntimeError("smem: {}".format(smem))
raise RuntimeError

View file

@ -8,4 +8,4 @@ y = b.blah()
a = dynamic_cast.do_test(y) a = dynamic_cast.do_test(y)
if a != "Bar::test": if a != "Bar::test":
print "Failed!!" raise RuntimeError("Failed!!")

View file

@ -9,36 +9,35 @@ a = A()
try: try:
a.foo() a.foo()
except E1, e: except E1 as e:
pass pass
except: except:
raise RuntimeError, "bad exception order" raise RuntimeError("bad exception order")
try: try:
a.bar() a.bar()
except E2, e: except E2 as e:
pass pass
except: except:
raise RuntimeError, "bad exception order" raise RuntimeError("bad exception order")
try: try:
a.foobar() a.foobar()
except RuntimeError, e: except RuntimeError as e:
if e.args[0] != "postcatch unknown": if e.args[0] != "postcatch unknown":
print "bad exception order", raise RuntimeError("bad exception order {}".format(e.args))
raise RuntimeError, e.args
try: try:
a.barfoo(1) a.barfoo(1)
except E1, e: except E1 as e:
pass pass
except: except:
raise RuntimeError, "bad exception order" raise RuntimeError("bad exception order")
try: try:
a.barfoo(2) a.barfoo(2)
except E2, e: except E2 as e:
pass pass
except: except:
raise RuntimeError, "bad exception order" raise RuntimeError("bad exception order")

View file

@ -5,4 +5,4 @@ n = Node()
i = sw.addChild(n) i = sw.addChild(n)
if i != 2: if i != 2:
raise RuntimeError, "addChild" raise RuntimeError("addChild")

View file

@ -11,7 +11,7 @@ check(global_two(2, 2), 4)
fail = True fail = True
try: try:
global_void(1) global_void(1)
except TypeError, e: except TypeError as e:
fail = False fail = False
if fail: if fail:
raise RuntimeError("argument count check failed") raise RuntimeError("argument count check failed")
@ -19,7 +19,7 @@ if fail:
fail = True fail = True
try: try:
global_one() global_one()
except TypeError, e: except TypeError as e:
fail = False fail = False
if fail: if fail:
raise RuntimeError("argument count check failed") raise RuntimeError("argument count check failed")
@ -27,7 +27,7 @@ if fail:
fail = True fail = True
try: try:
global_one(2, 2) global_one(2, 2)
except TypeError, e: except TypeError as e:
fail = False fail = False
if fail: if fail:
@ -36,7 +36,7 @@ if fail:
fail = True fail = True
try: try:
global_two(1) global_two(1)
except TypeError, e: except TypeError as e:
fail = False fail = False
if fail: if fail:
@ -45,7 +45,7 @@ if fail:
fail = True fail = True
try: try:
global_two(3, 3, 3) global_two(3, 3, 3)
except TypeError, e: except TypeError as e:
fail = False fail = False
if fail: if fail:

View file

@ -20,7 +20,7 @@ if x != 9876:
fail = True fail = True
try: try:
global_vars.cvar.notexist = "something" global_vars.cvar.notexist = "something"
except AttributeError, e: except AttributeError as e:
fail = False fail = False
if fail: if fail:
raise RuntimeError("AttributeError should have been thrown") raise RuntimeError("AttributeError should have been thrown")
@ -28,7 +28,7 @@ if fail:
fail = True fail = True
try: try:
g = global_vars.cvar.notexist g = global_vars.cvar.notexist
except AttributeError, e: except AttributeError as e:
fail = False fail = False
if fail: if fail:
raise RuntimeError("AttributeError should have been thrown") raise RuntimeError("AttributeError should have been thrown")

View file

@ -3,4 +3,4 @@ import import_stl_a
v_new = import_stl_b.process_vector([1, 2, 3]) v_new = import_stl_b.process_vector([1, 2, 3])
if v_new != (1, 2, 3, 4): if v_new != (1, 2, 3, 4):
raise RuntimeError, v_new raise RuntimeError(v_new)

View file

@ -1,31 +1,21 @@
import inctest import inctest
error = 0
try: try:
a = inctest.A() a = inctest.A()
except: except:
print "didn't find A" raise RuntimeError("didn't find A, therefore, I didn't include 'testdir/subdir1/hello.i'")
print "therefore, I didn't include 'testdir/subdir1/hello.i'"
error = 1
pass pass
try: try:
b = inctest.B() b = inctest.B()
except: except:
print "didn't find B" raise RuntimeError("didn't find B, therefore, I didn't include 'testdir/subdir2/hello.i'")
print "therefore, I didn't include 'testdir/subdir2/hello.i'"
error = 1
pass pass
if error == 1:
raise RuntimeError
# Check the import in subdirectory worked # Check the import in subdirectory worked
if inctest.importtest1(5) != 15: if inctest.importtest1(5) != 15:
print "import test 1 failed" raise RuntimeError("import test 1 failed")
raise RuntimeError
if inctest.importtest2("black") != "white": if inctest.importtest2("black") != "white":
print "import test 2 failed" raise RuntimeError("import test 2 failed")
raise RuntimeError

View file

@ -6,14 +6,14 @@ c = inherit_missing.Spam()
x = inherit_missing.do_blah(a) x = inherit_missing.do_blah(a)
if x != "Foo::blah": if x != "Foo::blah":
print "Whoa! Bad return", x raise RuntimeError("Whoa! Bad return {}".format(x))
x = inherit_missing.do_blah(b) x = inherit_missing.do_blah(b)
if x != "Bar::blah": if x != "Bar::blah":
print "Whoa! Bad return", x raise RuntimeError("Whoa! Bad return {}".format(x))
x = inherit_missing.do_blah(c) x = inherit_missing.do_blah(c)
if x != "Spam::blah": if x != "Spam::blah":
print "Whoa! Bad return", x raise RuntimeError("Whoa! Bad return {}".format(x))
inherit_missing.delete_Foo(a) inherit_missing.delete_Foo(a)

View file

@ -3,8 +3,7 @@ a = inplaceadd.A(7)
a += 5 a += 5
if a.val != 12: if a.val != 12:
print a.val raise RuntimeError("a.val: {}".format(a.val))
raise RuntimeError
a -= 5 a -= 5
if a.val != 7: if a.val != 7:

View file

@ -8,12 +8,10 @@ if aa.a != 1:
raise RuntimeError raise RuntimeError
aa.a = 3 aa.a = 3
if aa.a != 3: if aa.a != 3:
print aa.a raise RuntimeError("aa.a: {}".format(aa.a))
raise RuntimeError
if aa.b != 2: if aa.b != 2:
print aa.b raise RuntimeError("aa.b: {}".format(aa.b))
raise RuntimeError
aa.b = 5 aa.b = 5
if aa.b != 5: if aa.b != 5:
raise RuntimeError raise RuntimeError
@ -77,7 +75,7 @@ if myStringyClass.ReadOnlyString != "changed string":
try: try:
x = myFoo.does_not_exist x = myFoo.does_not_exist
raise RuntimeError raise RuntimeError
except AttributeError, e: except AttributeError as e:
if str(e).find("does_not_exist") == -1: if str(e).find("does_not_exist") == -1:
raise RuntimeError raise RuntimeError

View file

@ -7,8 +7,7 @@ chell = li_attribute_template.Cintint(1, 2, 3)
def rassert(what, master): def rassert(what, master):
if what != master: if what != master:
print what raise RuntimeError("what: {}".format(what))
raise RuntimeError
# Testing primitive by value attribute # Testing primitive by value attribute
rassert(chell.a, 1) rassert(chell.a, 1)

View file

@ -10,7 +10,7 @@ class li_boost_shared_ptr_runme:
def main(self): def main(self):
if (debug): if (debug):
print "Started" print("Started")
li_boost_shared_ptr.cvar.debug_shared = debug li_boost_shared_ptr.cvar.debug_shared = debug
@ -32,7 +32,7 @@ class li_boost_shared_ptr_runme:
"shared_ptr wrapper count=%s" % wrapper_count) "shared_ptr wrapper count=%s" % wrapper_count)
if (debug): if (debug):
print "Finished" print("Finished")
def runtest(self): def runtest(self):
# simple shared_ptr usage - created in C++ # simple shared_ptr usage - created in C++

View file

@ -11,12 +11,10 @@ if test2() != " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^
raise RuntimeError raise RuntimeError
if test3("hello") != "hello-suffix": if test3("hello") != "hello-suffix":
print test3("hello") raise RuntimeError("test3(\"hello\")")
raise RuntimeError
if test4("hello") != "hello-suffix": if test4("hello") != "hello-suffix":
print test4("hello") raise RuntimeError("test4(\"hello\")")
raise RuntimeError
if test5(4) != "xxxx": if test5(4) != "xxxx":
raise RuntimeError raise RuntimeError

View file

@ -1,28 +1,28 @@
from li_cwstring import * from li_cwstring import *
if count(u"ab\0ab\0ab\0", 0) != 3: if count("ab\0ab\0ab\0", 0) != 3:
raise RuntimeError raise RuntimeError
if test1() != u"Hello World": if test1() != "Hello World":
raise RuntimeError raise RuntimeError
if test2() != u" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_": if test2() != " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_":
raise RuntimeError raise RuntimeError
if test3("hello") != u"hello-suffix": if test3("hello") != "hello-suffix":
raise RuntimeError raise RuntimeError
if test4("hello") != u"hello-suffix": if test4("hello") != "hello-suffix":
raise RuntimeError raise RuntimeError
if test5(4) != u"xxxx": if test5(4) != "xxxx":
raise RuntimeError raise RuntimeError
if test6(10) != u"xxxxx": if test6(10) != "xxxxx":
raise RuntimeError raise RuntimeError
if test7() != u"Hello world!": if test7() != "Hello world!":
raise RuntimeError raise RuntimeError
if test8() != u" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_": if test8() != " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_":
raise RuntimeError raise RuntimeError

View file

@ -9,8 +9,8 @@ ad, get(ad)
ab, get(ab) ab, get(ab)
if get(ai) != get(1): if get(ai) != get(1):
raise RuntimeError, "bad implicit type" raise RuntimeError("bad implicit type")
if get(ad) != get(2.0): if get(ad) != get(2.0):
raise RuntimeError, "bad implicit type" raise RuntimeError("bad implicit type")
if get(ab) != get(b): if get(ab) != get(b):
raise RuntimeError, "bad implicit type" raise RuntimeError("bad implicit type")

View file

@ -6,7 +6,7 @@ import sys
def failed(a, b, msg): def failed(a, b, msg):
raise RuntimeError, msg + " " + str(list(a)) + " " + str(list(b)) raise RuntimeError(msg + " " + str(list(a)) + " " + str(list(b)))
def compare_sequences(a, b): def compare_sequences(a, b):
@ -26,7 +26,7 @@ def compare_containers(pythonlist, swigvector, swiglist):
def container_insert_step(i, j, step, newval): def container_insert_step(i, j, step, newval):
ps = range(6) ps = list(range(6))
iv = vector_int(ps) iv = vector_int(ps)
il = list_int(ps) il = list_int(ps)
@ -43,9 +43,9 @@ def container_insert_step(i, j, step, newval):
else: else:
ps[i:j:step] = newval ps[i:j:step] = newval
ps_error = None ps_error = None
except ValueError, e: except ValueError as e:
ps_error = e ps_error = e
except IndexError, e: except IndexError as e:
ps_error = e ps_error = e
# std::vector<int> # std::vector<int>
@ -61,9 +61,9 @@ def container_insert_step(i, j, step, newval):
else: else:
iv[i:j:step] = newval iv[i:j:step] = newval
iv_error = None iv_error = None
except ValueError, e: except ValueError as e:
iv_error = e iv_error = e
except IndexError, e: except IndexError as e:
iv_error = e iv_error = e
# std::list<int> # std::list<int>
@ -79,14 +79,14 @@ def container_insert_step(i, j, step, newval):
else: else:
il[i:j:step] = newval il[i:j:step] = newval
il_error = None il_error = None
except ValueError, e: except ValueError as e:
il_error = e il_error = e
except IndexError, e: except IndexError as e:
il_error = e il_error = e
if not((type(ps_error) == type(iv_error)) and (type(ps_error) == type(il_error))): if not((type(ps_error) == type(iv_error)) and (type(ps_error) == type(il_error))):
raise RuntimeError, "ValueError exception not consistently thrown: " + \ raise RuntimeError("ValueError exception not consistently thrown: " + \
str(ps_error) + " " + str(iv_error) + " " + str(il_error) str(ps_error) + " " + str(iv_error) + " " + str(il_error))
compare_containers(ps, iv, il) compare_containers(ps, iv, il)
@ -94,7 +94,7 @@ def container_insert_step(i, j, step, newval):
# Check std::vector and std::list delete behaves same as Python list # Check std::vector and std::list delete behaves same as Python list
# delete including exceptions # delete including exceptions
def container_delete_step(i, j, step): def container_delete_step(i, j, step):
ps = range(6) ps = list(range(6))
iv = vector_int(ps) iv = vector_int(ps)
il = list_int(ps) il = list_int(ps)
@ -111,9 +111,9 @@ def container_delete_step(i, j, step):
else: else:
del ps[i:j:step] del ps[i:j:step]
ps_error = None ps_error = None
except ValueError, e: except ValueError as e:
ps_error = e ps_error = e
except IndexError, e: except IndexError as e:
ps_error = e ps_error = e
# std::vector<int> # std::vector<int>
@ -129,9 +129,9 @@ def container_delete_step(i, j, step):
else: else:
del iv[i:j:step] del iv[i:j:step]
iv_error = None iv_error = None
except ValueError, e: except ValueError as e:
iv_error = e iv_error = e
except IndexError, e: except IndexError as e:
iv_error = e iv_error = e
# std::list<int> # std::list<int>
@ -147,14 +147,14 @@ def container_delete_step(i, j, step):
else: else:
del il[i:j:step] del il[i:j:step]
il_error = None il_error = None
except ValueError, e: except ValueError as e:
il_error = e il_error = e
except IndexError, e: except IndexError as e:
il_error = e il_error = e
if not((type(ps_error) == type(iv_error)) and (type(ps_error) == type(il_error))): if not((type(ps_error) == type(iv_error)) and (type(ps_error) == type(il_error))):
raise RuntimeError, "ValueError exception not consistently thrown: " + \ raise RuntimeError("ValueError exception not consistently thrown: " + \
str(ps_error) + " " + str(iv_error) + " " + str(il_error) str(ps_error) + " " + str(iv_error) + " " + str(il_error))
compare_containers(ps, iv, il) compare_containers(ps, iv, il)
@ -252,7 +252,7 @@ for start in [-102, -100, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 10
for step in range(-7, 7): for step in range(-7, 7):
container_delete_step(start, end, step) container_delete_step(start, end, step)
ps = range(6) ps = list(range(6))
iv = vector_int(ps) iv = vector_int(ps)
il = list_int(ps) il = list_int(ps)
del ps[:] del ps[:]

View file

@ -25,8 +25,7 @@ for k in m:
for k in m: for k in m:
if pm[k].this != m[k].this: if pm[k].this != m[k].this:
print pm[k], m[k] raise RuntimeError("Not equal {} {}".format(pm[k], m[k]))
raise RuntimeError
m = {} m = {}
@ -51,31 +50,31 @@ mii[1] = 2
if mii[1] != 2: if mii[1] != 2:
raise RuntimeError raise RuntimeError
if mii.keys() != [1]: if list(mii.keys()) != [1]:
raise RuntimeError("keys") raise RuntimeError("keys")
if mii.values() != [2]: if list(mii.values()) != [2]:
raise RuntimeError("values") raise RuntimeError("values")
if mii.items() != [(1, 2)]: if list(mii.items()) != [(1, 2)]:
raise RuntimeError("items") raise RuntimeError("items")
if [k for k in mii] != [1]: if [k for k in mii] != [1]:
raise RuntimeError("iteration") raise RuntimeError("iteration")
if [i for i in mii.iterkeys()] != [1]: if [i for i in mii.keys()] != [1]:
raise RuntimeError("iterkeys") raise RuntimeError("iterkeys")
if [i for i in mii.itervalues()] != [2]: if [i for i in mii.values()] != [2]:
raise RuntimeError("itervalues") raise RuntimeError("itervalues")
if [i for i in mii.iteritems()] != [(1, 2)]: if [i for i in mii.items()] != [(1, 2)]:
raise RuntimeError("iteritems") raise RuntimeError("iteritems")
slmap = li_std_map.StringLengthNumberMap() slmap = li_std_map.StringLengthNumberMap()
li_std_map.populate(slmap) li_std_map.populate(slmap)
keys = " ".join([k for k in slmap.keys()]) keys = " ".join([k for k in list(slmap.keys())])
if keys != "a aa zzz xxxx aaaaa": if keys != "a aa zzz xxxx aaaaa":
raise RuntimeError("Keys are wrong or in wrong order: " + keys) raise RuntimeError("Keys are wrong or in wrong order: " + keys)
values = " ".join([str(v) for v in slmap.values()]) values = " ".join([str(v) for v in list(slmap.values())])
if values != "1 2 3 4 5": if values != "1 2 3 4 5":
raise RuntimeError("Values are wrong or in wrong order: " + values) raise RuntimeError("Values are wrong or in wrong order: " + values)

View file

@ -14,11 +14,11 @@ if sum != "abc":
raise RuntimeError raise RuntimeError
i = s.__iter__() i = s.__iter__()
if i.next() != "a": if next(i) != "a":
raise RuntimeError raise RuntimeError
if i.next() != "b": if next(i) != "b":
raise RuntimeError raise RuntimeError
if i.next() != "c": if next(i) != "c":
raise RuntimeError raise RuntimeError
@ -26,7 +26,7 @@ b = s.begin()
e = s.end() e = s.end()
sum = "" sum = ""
while (b != e): while (b != e):
sum = sum + b.next() sum = sum + next(b)
if sum != "abc": if sum != "abc":
raise RuntimeError raise RuntimeError
@ -34,7 +34,7 @@ b = s.rbegin()
e = s.rend() e = s.rend()
sum = "" sum = ""
while (b != e): while (b != e):
sum = sum + b.next() sum = sum + next(b)
if sum != "cba": if sum != "cba":
raise RuntimeError raise RuntimeError
@ -47,25 +47,25 @@ si.append(2)
si.append(3) si.append(3)
i = si.__iter__() i = si.__iter__()
if i.next() != 1: if next(i) != 1:
raise RuntimeError raise RuntimeError
if i.next() != 2: if next(i) != 2:
raise RuntimeError raise RuntimeError
if i.next() != 3: if next(i) != 3:
raise RuntimeError raise RuntimeError
if si[0] != 1: if si[0] != 1:
raise RuntimeError raise RuntimeError
i = s.begin() i = s.begin()
i.next() next(i)
s.erase(i) s.erase(i)
b = s.begin() b = s.begin()
e = s.end() e = s.end()
sum = "" sum = ""
while (b != e): while (b != e):
sum = sum + b.next() sum = sum + next(b)
if sum != "ac": if sum != "ac":
raise RuntimeError raise RuntimeError

View file

@ -9,5 +9,4 @@ o << a << " " << 2345 << " " << 1.435
if o.str() != "A class 2345 1.435": if o.str() != "A class 2345 1.435":
print "\"%s\"" % (o.str(),) raise RuntimeError("str failed: \"%s\"".format(o.str()))
raise RuntimeError

View file

@ -4,17 +4,16 @@ x = "hello"
if li_std_string_extra.test_ccvalue(x) != x: if li_std_string_extra.test_ccvalue(x) != x:
raise RuntimeError, "bad string mapping" raise RuntimeError("bad string mapping")
if li_std_string_extra.test_cvalue(x) != x: if li_std_string_extra.test_cvalue(x) != x:
raise RuntimeError, "bad string mapping" raise RuntimeError("bad string mapping")
if li_std_string_extra.test_value(x) != x: if li_std_string_extra.test_value(x) != x:
print x, li_std_string_extra.test_value(x) raise RuntimeError("bad string mapping {} {}".format(x, li_std_string_extra.test_value(x)))
raise RuntimeError, "bad string mapping"
if li_std_string_extra.test_const_reference(x) != x: if li_std_string_extra.test_const_reference(x) != x:
raise RuntimeError, "bad string mapping" raise RuntimeError("bad string mapping")
s = li_std_string_extra.string("he") s = li_std_string_extra.string("he")
@ -23,45 +22,43 @@ s = li_std_string_extra.string("he")
s = s + "llo" s = s + "llo"
if s != x: if s != x:
print s, x raise RuntimeError("bad string mapping {} {}".format(s, x))
raise RuntimeError, "bad string mapping"
if s[1:4] != x[1:4]: if s[1:4] != x[1:4]:
raise RuntimeError, "bad string mapping" raise RuntimeError("bad string mapping")
if li_std_string_extra.test_value(s) != x: if li_std_string_extra.test_value(s) != x:
raise RuntimeError, "bad string mapping" raise RuntimeError("bad string mapping")
if li_std_string_extra.test_const_reference(s) != x: if li_std_string_extra.test_const_reference(s) != x:
raise RuntimeError, "bad string mapping" raise RuntimeError("bad string mapping")
a = li_std_string_extra.A(s) a = li_std_string_extra.A(s)
if li_std_string_extra.test_value(a) != x: if li_std_string_extra.test_value(a) != x:
raise RuntimeError, "bad string mapping" raise RuntimeError("bad string mapping")
if li_std_string_extra.test_const_reference(a) != x: if li_std_string_extra.test_const_reference(a) != x:
raise RuntimeError, "bad string mapping" raise RuntimeError("bad string mapping")
b = li_std_string_extra.string(" world") b = li_std_string_extra.string(" world")
s = a + b s = a + b
if a + b != "hello world": if a + b != "hello world":
print a + b raise RuntimeError("bad string mapping {}".format(a + b))
raise RuntimeError, "bad string mapping"
if a + " world" != "hello world": if a + " world" != "hello world":
raise RuntimeError, "bad string mapping" raise RuntimeError("bad string mapping")
# This is expected to fail with -builtin option # This is expected to fail with -builtin option
# Reverse operators not supported in builtin types # Reverse operators not supported in builtin types
if not li_std_string_extra.is_python_builtin(): if not li_std_string_extra.is_python_builtin():
if "hello" + b != "hello world": if "hello" + b != "hello world":
raise RuntimeError, "bad string mapping" raise RuntimeError("bad string mapping")
c = "hello" + b c = "hello" + b
if c.find_last_of("l") != 9: if c.find_last_of("l") != 9:
raise RuntimeError, "bad string mapping" raise RuntimeError("bad string mapping")
s = "hello world" s = "hello world"
@ -69,33 +66,33 @@ b = li_std_string_extra.B("hi")
b.name = li_std_string_extra.string("hello") b.name = li_std_string_extra.string("hello")
if b.name != "hello": if b.name != "hello":
raise RuntimeError, "bad string mapping" raise RuntimeError("bad string mapping")
b.a = li_std_string_extra.A("hello") b.a = li_std_string_extra.A("hello")
if b.a != "hello": if b.a != "hello":
raise RuntimeError, "bad string mapping" raise RuntimeError("bad string mapping")
if li_std_string_extra.test_value_basic1(x) != x: if li_std_string_extra.test_value_basic1(x) != x:
raise RuntimeError, "bad string mapping" raise RuntimeError("bad string mapping")
if li_std_string_extra.test_value_basic2(x) != x: if li_std_string_extra.test_value_basic2(x) != x:
raise RuntimeError, "bad string mapping" raise RuntimeError("bad string mapping")
if li_std_string_extra.test_value_basic3(x) != x: if li_std_string_extra.test_value_basic3(x) != x:
raise RuntimeError, "bad string mapping" raise RuntimeError("bad string mapping")
if li_std_string_extra.test_value_basic_overload(x) != x: if li_std_string_extra.test_value_basic_overload(x) != x:
raise RuntimeError, "bad overload string" raise RuntimeError("bad overload string")
if li_std_string_extra.test_value_basic_overload(123) != "int": if li_std_string_extra.test_value_basic_overload(123) != "int":
raise RuntimeError, "bad overload int" raise RuntimeError("bad overload int")
try: try:
li_std_string_extra.test_value_basic_overload([x]) li_std_string_extra.test_value_basic_overload([x])
raise RuntimeError, "should throw TypeError" raise RuntimeError("should throw TypeError")
except TypeError as e: except TypeError as e:
if str(e).find("Possible C/C++ prototypes are:") == -1: if str(e).find("Possible C/C++ prototypes are:") == -1:
raise RuntimeError("Incorrect error message text:\n{}".format(e)) raise RuntimeError("Incorrect error message text:\n{}".format(e))
@ -103,7 +100,7 @@ except TypeError as e:
try: try:
li_std_string_extra.test_value_basic_overload([123]) li_std_string_extra.test_value_basic_overload([123])
raise RuntimeError, "should throw TypeError" raise RuntimeError("should throw TypeError")
except TypeError as e: except TypeError as e:
if str(e).find("Possible C/C++ prototypes are:") == -1: if str(e).find("Possible C/C++ prototypes are:") == -1:
raise RuntimeError("Incorrect error message text:\n{}".format(e)) raise RuntimeError("Incorrect error message text:\n{}".format(e))
@ -112,30 +109,30 @@ except TypeError as e:
# Global variables # Global variables
s = "initial string" s = "initial string"
if li_std_string_extra.cvar.GlobalString2 != "global string 2": if li_std_string_extra.cvar.GlobalString2 != "global string 2":
raise RuntimeError, "GlobalString2 test 1" raise RuntimeError("GlobalString2 test 1")
li_std_string_extra.cvar.GlobalString2 = s li_std_string_extra.cvar.GlobalString2 = s
if li_std_string_extra.cvar.GlobalString2 != s: if li_std_string_extra.cvar.GlobalString2 != s:
raise RuntimeError, "GlobalString2 test 2" raise RuntimeError("GlobalString2 test 2")
if li_std_string_extra.cvar.ConstGlobalString != "const global string": if li_std_string_extra.cvar.ConstGlobalString != "const global string":
raise RuntimeError, "ConstGlobalString test" raise RuntimeError("ConstGlobalString test")
# Member variables # Member variables
myStructure = li_std_string_extra.Structure() myStructure = li_std_string_extra.Structure()
if myStructure.MemberString2 != "member string 2": if myStructure.MemberString2 != "member string 2":
raise RuntimeError, "MemberString2 test 1" raise RuntimeError("MemberString2 test 1")
myStructure.MemberString2 = s myStructure.MemberString2 = s
if myStructure.MemberString2 != s: if myStructure.MemberString2 != s:
raise RuntimeError, "MemberString2 test 2" raise RuntimeError("MemberString2 test 2")
if myStructure.ConstMemberString != "const member string": if myStructure.ConstMemberString != "const member string":
raise RuntimeError, "ConstMemberString test" raise RuntimeError("ConstMemberString test")
if li_std_string_extra.cvar.Structure_StaticMemberString2 != "static member string 2": if li_std_string_extra.cvar.Structure_StaticMemberString2 != "static member string 2":
raise RuntimeError, "StaticMemberString2 test 1" raise RuntimeError("StaticMemberString2 test 1")
li_std_string_extra.cvar.Structure_StaticMemberString2 = s li_std_string_extra.cvar.Structure_StaticMemberString2 = s
if li_std_string_extra.cvar.Structure_StaticMemberString2 != s: if li_std_string_extra.cvar.Structure_StaticMemberString2 != s:
raise RuntimeError, "StaticMemberString2 test 2" raise RuntimeError("StaticMemberString2 test 2")
if li_std_string_extra.cvar.Structure_ConstStaticMemberString != "const static member string": if li_std_string_extra.cvar.Structure_ConstStaticMemberString != "const static member string":
raise RuntimeError, "ConstStaticMemberString test" raise RuntimeError("ConstStaticMemberString test")
if li_std_string_extra.test_reference_input("hello") != "hello": if li_std_string_extra.test_reference_input("hello") != "hello":

View file

@ -14,7 +14,7 @@ check(ev.nums[2], 30)
it = ev.nums.iterator() it = ev.nums.iterator()
v = it.value() v = it.value()
check(v, 10) check(v, 10)
it.next() next(it)
v = it.value() v = it.value()
check(v, 20) check(v, 20)

View file

@ -23,20 +23,20 @@ bv[2] = bool(4)
bv[3] = bool(0) bv[3] = bool(0)
if bv[0] != bv[2]: if bv[0] != bv[2]:
raise RuntimeError, "bad std::vector<bool> mapping" raise RuntimeError("bad std::vector<bool> mapping")
b = B(5) b = B(5)
va = VecA([b, None, b, b]) va = VecA([b, None, b, b])
if va[0].f(1) != 6: if va[0].f(1) != 6:
raise RuntimeError, "bad std::vector<A*> mapping" raise RuntimeError("bad std::vector<A*> mapping")
if vecAptr(va) != 6: if vecAptr(va) != 6:
raise RuntimeError, "bad std::vector<A*> mapping" raise RuntimeError("bad std::vector<A*> mapping")
b.val = 7 b.val = 7
if va[3].f(1) != 8: if va[3].f(1) != 8:
raise RuntimeError, "bad std::vector<A*> mapping" raise RuntimeError("bad std::vector<A*> mapping")
ip = PtrInt() ip = PtrInt()
@ -47,7 +47,7 @@ ArrInt_setitem(ap, 2, 123)
vi = IntPtrVector((ip, ap, None)) vi = IntPtrVector((ip, ap, None))
if ArrInt_getitem(vi[0], 0) != ArrInt_getitem(vi[1], 2): if ArrInt_getitem(vi[0], 0) != ArrInt_getitem(vi[1], 2):
raise RuntimeError, "bad std::vector<int*> mapping" raise RuntimeError("bad std::vector<int*> mapping")
delete_ArrInt(ap) delete_ArrInt(ap)
@ -57,42 +57,42 @@ a = halfs([10, 8, 4, 3])
v = IntVector() v = IntVector()
v[0:2] = [1, 2] v[0:2] = [1, 2]
if v[0] != 1 or v[1] != 2: if v[0] != 1 or v[1] != 2:
raise RuntimeError, "bad setslice" raise RuntimeError("bad setslice")
if v[0:-1][0] != 1: if v[0:-1][0] != 1:
raise RuntimeError, "bad getslice" raise RuntimeError("bad getslice")
if v[0:-2].size() != 0: if v[0:-2].size() != 0:
raise RuntimeError, "bad getslice" raise RuntimeError("bad getslice")
v[0:1] = [2] v[0:1] = [2]
if v[0] != 2: if v[0] != 2:
raise RuntimeError, "bad setslice" raise RuntimeError("bad setslice")
v[1:] = [3] v[1:] = [3]
if v[1] != 3: if v[1] != 3:
raise RuntimeError, "bad setslice" raise RuntimeError("bad setslice")
v[2:] = [3] v[2:] = [3]
if v[2] != 3: if v[2] != 3:
raise RuntimeError, "bad setslice" raise RuntimeError("bad setslice")
if v[0:][0] != v[0]: if v[0:][0] != v[0]:
raise RuntimeError, "bad getslice" raise RuntimeError("bad getslice")
del v[:] del v[:]
if v.size() != 0: if v.size() != 0:
raise RuntimeError, "bad getslice" raise RuntimeError("bad getslice")
del v[:] del v[:]
if v.size() != 0: if v.size() != 0:
raise RuntimeError, "bad getslice" raise RuntimeError("bad getslice")
v = vecStr(["hello ", "world"]) v = vecStr(["hello ", "world"])
if v[0] != "hello world": if v[0] != "hello world":
raise RuntimeError, "bad std::string+std::vector" raise RuntimeError("bad std::string+std::vector")
pv = pyvector([1, "hello", (1, 2)]) pv = pyvector([1, "hello", (1, 2)])

View file

@ -5,8 +5,7 @@ a = A()
o = wostringstream() o = wostringstream()
o << a << u" " << 2345 << u" " << 1.435 << wends o << a << " " << 2345 << " " << 1.435 << wends
if o.str() != "A class 2345 1.435\0": if o.str() != "A class 2345 1.435\0":
print "\"%s\"" % (o.str(),) raise RuntimeError("str failed: \"%s\"".format(o.str()))
raise RuntimeError

View file

@ -1,14 +1,13 @@
import li_std_wstring_inherit import li_std_wstring_inherit
import sys import sys
x = u"hello" x = "hello"
s = li_std_wstring_inherit.wstring(u"he") s = li_std_wstring_inherit.wstring("he")
s = s + u"llo" s = s + "llo"
if s != x: if s != x:
print s, x raise RuntimeError("bad string mapping {} {}".format(s, x))
raise RuntimeError("bad string mapping")
if s[1:4] != x[1:4]: if s[1:4] != x[1:4]:
raise RuntimeError("bad string mapping") raise RuntimeError("bad string mapping")
@ -34,12 +33,12 @@ if not li_std_wstring_inherit.is_python_builtin():
b = li_std_wstring_inherit.B("hi") b = li_std_wstring_inherit.B("hi")
b.name = li_std_wstring_inherit.wstring(u"hello") b.name = li_std_wstring_inherit.wstring("hello")
if b.name != "hello": if b.name != "hello":
raise RuntimeError("bad string mapping") raise RuntimeError("bad string mapping")
b.a = li_std_wstring_inherit.A("hello") b.a = li_std_wstring_inherit.A("hello")
if b.a != u"hello": if b.a != "hello":
raise RuntimeError("bad string mapping") raise RuntimeError("bad string mapping")

View file

@ -5,10 +5,10 @@ def check_equal(a, b):
if a != b: if a != b:
raise RuntimeError("failed {} {}".format(a, b)) raise RuntimeError("failed {} {}".format(a, b))
h = u"h" h = "h"
check_equal(li_std_wstring.test_wcvalue(h), h) check_equal(li_std_wstring.test_wcvalue(h), h)
x = u"abc" x = "abc"
check_equal(li_std_wstring.test_ccvalue(x), x) check_equal(li_std_wstring.test_ccvalue(x), x)
check_equal(li_std_wstring.test_cvalue(x), x) check_equal(li_std_wstring.test_cvalue(x), x)
@ -72,7 +72,7 @@ except TypeError:
# Check surrogateescape # Check surrogateescape
if sys.version_info[0:2] > (3, 1): if sys.version_info[0:2] > (3, 1):
x = u"h\udce9llo" # surrogate escaped representation of C char*: "h\xe9llo" x = "h\udce9llo" # surrogate escaped representation of C char*: "h\xe9llo"
if li_std_wstring.non_utf8_c_str() != x: if li_std_wstring.non_utf8_c_str() != x:
raise RuntimeError("surrogateescape not working") raise RuntimeError("surrogateescape not working")
if li_std_wstring.size_wstring(x) != 5 and len(x) != 5: if li_std_wstring.size_wstring(x) != 5 and len(x) != 5:

Some files were not shown because too many files have changed in this diff Show more