Test-suite fixes for python -classic

These are mostly workarounds for static class members not being supported for
old style classes, as documented in Python.html, "C++ classes".
This commit is contained in:
William S Fulton 2015-01-31 15:04:35 +00:00
commit 76bcec1d87
18 changed files with 118 additions and 41 deletions

View file

@ -50,6 +50,8 @@ matrix:
env: SWIGLANG=python SWIG_FEATURES=-builtin env: SWIGLANG=python SWIG_FEATURES=-builtin
- compiler: gcc - compiler: gcc
env: SWIGLANG=python SWIG_FEATURES=-builtin PY3=3 env: SWIGLANG=python SWIG_FEATURES=-builtin PY3=3
- compiler: gcc
env: SWIGLANG=python SWIG_FEATURES=-classic
- compiler: gcc - compiler: gcc
env: SWIGLANG=ruby env: SWIGLANG=ruby
- compiler: gcc - compiler: gcc
@ -60,6 +62,9 @@ matrix:
# Occasional gcc internal compiler error # Occasional gcc internal compiler error
- compiler: gcc - compiler: gcc
env: SWIGLANG=octave SWIGJOBS=-j3 VER=3.8 env: SWIGLANG=octave SWIGJOBS=-j3 VER=3.8
# Not quite working yet
- compiler: gcc
env: SWIGLANG=python SWIG_FEATURES=-classic
before_install: before_install:
- date -u - date -u
- uname -a - uname -a

View file

@ -9,6 +9,13 @@ def check(got, expected, expected_builtin = None, skip = False):
if expect != got: if expect != got:
raise RuntimeError("\n" + "Expected: [" + str(expect) + "]\n" + "Got : [" + str(got) + "]") raise RuntimeError("\n" + "Expected: [" + str(expect) + "]\n" + "Got : [" + str(got) + "]")
def is_new_style_class(cls):
return hasattr(cls, "__class__")
if not is_new_style_class(A):
# Missing static methods make this hard to test... skip if -classic is used!
exit(0)
skip = True # skip builtin check - the autodoc is missing, but it probably should not be skip = True # skip builtin check - the autodoc is missing, but it probably should not be
check(A.__doc__, "Proxy of C++ A class", "::A") check(A.__doc__, "Proxy of C++ A class", "::A")

View file

@ -1,7 +1,16 @@
#!/usr/bin/evn python #!/usr/bin/evn python
from cpp_static import * from cpp_static import *
def is_new_style_class(cls):
return hasattr(cls, "__class__")
if is_new_style_class(StaticFunctionTest):
StaticFunctionTest.static_func() StaticFunctionTest.static_func()
StaticFunctionTest.static_func_2(1) StaticFunctionTest.static_func_2(1)
StaticFunctionTest.static_func_3(1,2) StaticFunctionTest.static_func_3(1,2)
else:
StaticFunctionTest().static_func()
StaticFunctionTest().static_func_2(1)
StaticFunctionTest().static_func_3(1,2)
StaticMemberTest.static_int = 10 StaticMemberTest.static_int = 10
assert StaticMemberTest.static_int == 10 assert StaticMemberTest.static_int == 10

View file

@ -1,5 +1,8 @@
# Note that this test is also used by python_default_args_runme.py hence the use of __main__ and the run function # Note that this test is also used by python_default_args_runme.py hence the use of __main__ and the run function
def is_new_style_class(cls):
return hasattr(cls, "__class__")
def run(module_name): def run(module_name):
default_args = __import__(module_name) default_args = __import__(module_name)
ec = default_args.EnumClass() ec = default_args.EnumClass()
@ -71,13 +74,15 @@ def run(module_name):
error = 0 error = 0
if error: raise RuntimeError("Foo::meth ignore is not working") if error: raise RuntimeError("Foo::meth ignore is not working")
if default_args.Klass.inc(100, default_args.Klass(22)).val != 122: Klass_inc = default_args.Klass.inc if is_new_style_class(default_args.Klass) else default_args.Klass_inc
if Klass_inc(100, default_args.Klass(22)).val != 122:
raise RuntimeError("Klass::inc failed") raise RuntimeError("Klass::inc failed")
if default_args.Klass.inc(100).val != 99: if Klass_inc(100).val != 99:
raise RuntimeError("Klass::inc failed") raise RuntimeError("Klass::inc failed")
if default_args.Klass.inc().val != 0: if Klass_inc().val != 0:
raise RuntimeError("Klass::inc failed") raise RuntimeError("Klass::inc failed")
default_args.trickyvalue1(10); default_args.trickyvalue1(10, 10) default_args.trickyvalue1(10); default_args.trickyvalue1(10, 10)

View file

@ -1,5 +1,8 @@
import director_abstract import director_abstract
def is_new_style_class(cls):
return hasattr(cls, "__class__")
class MyFoo(director_abstract.Foo): class MyFoo(director_abstract.Foo):
def __init__(self): def __init__(self):
director_abstract.Foo.__init__(self) director_abstract.Foo.__init__(self)
@ -32,12 +35,14 @@ me1 = MyExample1()
if director_abstract.Example1_get_color(me1, 1,2,3) != 1: if director_abstract.Example1_get_color(me1, 1,2,3) != 1:
raise RuntimeError raise RuntimeError
MyExample2_static = MyExample2 if is_new_style_class(MyExample2) else MyExample2(0, 0)
me2 = MyExample2(1,2) me2 = MyExample2(1,2)
if MyExample2.get_color(me2, 1,2,3) != 2: if MyExample2_static.get_color(me2, 1,2,3) != 2:
raise RuntimeError raise RuntimeError
MyExample3_static = MyExample3 if is_new_style_class(MyExample3) else MyExample3()
me3 = MyExample3() me3 = MyExample3()
if MyExample3.get_color(me3, 1,2,3) != 3: if MyExample3_static.get_color(me3, 1,2,3) != 3:
raise RuntimeError raise RuntimeError
error = 1 error = 1

View file

@ -1,5 +1,8 @@
from global_namespace import * from global_namespace import *
def is_new_style_class(cls):
return hasattr(cls, "__class__")
k1 = Klass1() k1 = Klass1()
k2 = Klass2() k2 = Klass2()
k3 = Klass3() k3 = Klass3()
@ -8,8 +11,10 @@ k5 = Klass5()
k6 = Klass6() k6 = Klass6()
k7 = Klass7() k7 = Klass7()
KlassMethods.methodA(k1, k2, k3, k4, k5, k6, k7) KlassMethods_static = KlassMethods if is_new_style_class(KlassMethods) else KlassMethods()
KlassMethods.methodB(k1, k2, k3, k4, k5, k6, k7)
KlassMethods_static.methodA(k1, k2, k3, k4, k5, k6, k7)
KlassMethods_static.methodB(k1, k2, k3, k4, k5, k6, k7)
k1 = getKlass1A() k1 = getKlass1A()
k2 = getKlass2A() k2 = getKlass2A()
@ -19,8 +24,8 @@ k5 = getKlass5A()
k6 = getKlass6A() k6 = getKlass6A()
k7 = getKlass7A() k7 = getKlass7A()
KlassMethods.methodA(k1, k2, k3, k4, k5, k6, k7) KlassMethods_static.methodA(k1, k2, k3, k4, k5, k6, k7)
KlassMethods.methodB(k1, k2, k3, k4, k5, k6, k7) KlassMethods_static.methodB(k1, k2, k3, k4, k5, k6, k7)
k1 = getKlass1B() k1 = getKlass1B()
k2 = getKlass2B() k2 = getKlass2B()
@ -30,11 +35,13 @@ k5 = getKlass5B()
k6 = getKlass6B() k6 = getKlass6B()
k7 = getKlass7B() k7 = getKlass7B()
KlassMethods.methodA(k1, k2, k3, k4, k5, k6, k7) KlassMethods_static.methodA(k1, k2, k3, k4, k5, k6, k7)
KlassMethods.methodB(k1, k2, k3, k4, k5, k6, k7) KlassMethods_static.methodB(k1, k2, k3, k4, k5, k6, k7)
XYZMethods.methodA(XYZ1(), XYZ2(), XYZ3(), XYZ4(), XYZ5(), XYZ6(), XYZ7()) XYZMethods_static = XYZMethods if is_new_style_class(XYZMethods) else XYZMethods()
XYZMethods.methodB(XYZ1(), XYZ2(), XYZ3(), XYZ4(), XYZ5(), XYZ6(), XYZ7()) XYZMethods_static.methodA(XYZ1(), XYZ2(), XYZ3(), XYZ4(), XYZ5(), XYZ6(), XYZ7())
XYZMethods_static.methodB(XYZ1(), XYZ2(), XYZ3(), XYZ4(), XYZ5(), XYZ6(), XYZ7())
TheEnumMethods.methodA(theenum1, theenum2, theenum3) TheEnumMethods_static = TheEnumMethods if is_new_style_class(TheEnumMethods) else TheEnumMethods()
TheEnumMethods.methodA(theenum1, theenum2, theenum3) TheEnumMethods_static.methodA(theenum1, theenum2, theenum3)
TheEnumMethods_static.methodA(theenum1, theenum2, theenum3)

View file

@ -4,6 +4,9 @@ def check(a, b):
if a != b: if a != b:
raise RuntimeError(str(a) + " does not equal " + str(b)) raise RuntimeError(str(a) + " does not equal " + str(b))
def is_new_style_class(cls):
return hasattr(cls, "__class__")
#### Class #### #### Class ####
# No implicit conversion # No implicit conversion
@ -39,13 +42,14 @@ check(2, A_int(1.0).get())
check(3, A_int(B()).get()) check(3, A_int(B()).get())
check(4, A_int("hello").get()) check(4, A_int("hello").get())
check(1, A_int.sget(1)) A_int_static = A_int if is_new_style_class(A_int) else A_int(0)
check(2, A_int.sget(1.0)) check(1, A_int_static.sget(1))
check(3, A_int.sget(B())) check(2, A_int_static.sget(1.0))
check(3, A_int_static.sget(B()))
# explicit constructor: # explicit constructor:
try: try:
check(4, A_int.sget("hello")) check(4, A_int_static.sget("hello"))
raise RuntimeError raise RuntimeError
except TypeError: except TypeError:
pass pass

View file

@ -1,5 +1,8 @@
from li_boost_shared_ptr_bits import * from li_boost_shared_ptr_bits import *
def is_new_style_class(cls):
return hasattr(cls, "__class__")
def check(nd): def check(nd):
nd.i = 200 nd.i = 200
i = nd.i i = nd.i
@ -30,5 +33,8 @@ if sum != 66:
raise "sum is wrong" raise "sum is wrong"
################################ ################################
if is_new_style_class(HiddenDestructor):
p = HiddenDestructor.create() p = HiddenDestructor.create()
else:
p = HiddenDestructor_create()

View file

@ -17,7 +17,7 @@ class li_boost_shared_ptr_runme:
self.runtest() self.runtest()
# Expect 1 instance - the one global variable (GlobalValue) # Expect 1 instance - the one global variable (GlobalValue)
if (li_boost_shared_ptr.Klass.getTotal_count() != 1): if (li_boost_shared_ptr.Klass_getTotal_count() != 1):
raise RuntimeError("Klass.total_count=%s" % li_boost_shared_ptr.Klass.getTotal_count()) raise RuntimeError("Klass.total_count=%s" % li_boost_shared_ptr.Klass.getTotal_count())
wrapper_count = li_boost_shared_ptr.shared_ptr_wrapper_count() wrapper_count = li_boost_shared_ptr.shared_ptr_wrapper_count()

View file

@ -2,16 +2,16 @@ from li_std_auto_ptr import *
k1 = makeKlassAutoPtr("first") k1 = makeKlassAutoPtr("first")
k2 = makeKlassAutoPtr("second") k2 = makeKlassAutoPtr("second")
if Klass.getTotal_count() != 2: if Klass_getTotal_count() != 2:
raise "number of objects should be 2" raise "number of objects should be 2"
del k1 del k1
if Klass.getTotal_count() != 1: if Klass_getTotal_count() != 1:
raise "number of objects should be 1" raise "number of objects should be 1"
if k2.getLabel() != "second": if k2.getLabel() != "second":
raise "wrong object label" raise "wrong object label"
del k2 del k2
if Klass.getTotal_count() != 0: if Klass_getTotal_count() != 0:
raise "no objects should be left" raise "no objects should be left"

View file

@ -7,6 +7,11 @@ 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):
print("Comparing {} and {}\n".format(a, b))
print(" len a: {}\n".format(a.__len__()))
print(" len b: {}\n".format(b.__len__()))
print(" len a: {}\n".format(type(a.__len__())))
print(" len b: {}\n".format(type(b.__len__())))
if len(a) != len(b): if len(a) != len(b):
failed(a, b, "different sizes") failed(a, b, "different sizes")
for i in range(len(a)): for i in range(len(a)):

View file

@ -1,5 +1,8 @@
from namespace_class import * from namespace_class import *
def is_new_style_class(cls):
return hasattr(cls, "__class__")
try: try:
p = Private1() p = Private1()
error = 1 error = 1
@ -18,7 +21,10 @@ except:
if (error): if (error):
raise RuntimeError, "Private2 is private" raise RuntimeError, "Private2 is private"
if is_new_style_class(EulerT3D):
EulerT3D.toFrame(1,1,1) EulerT3D.toFrame(1,1,1)
else:
EulerT3D().toFrame(1,1,1)
b = BooT_i() b = BooT_i()
b = BooT_H() b = BooT_H()
@ -33,6 +39,7 @@ f.moo(1)
f = FooT_H() f = FooT_H()
f.foo(Hi) f.foo(Hi)
if is_new_style_class(FooT_H):
f_type = str(type(f)) f_type = str(type(f))
if f_type.find("'namespace_class.FooT_H'") == -1: if f_type.find("'namespace_class.FooT_H'") == -1:
raise RuntimeError("Incorrect type: " + f_type) raise RuntimeError("Incorrect type: " + f_type)

View file

@ -1,4 +1,8 @@
from overload_template_fast import * from overload_template_fast import *
def is_new_style_class(cls):
return hasattr(cls, "__class__")
f = foo() f = foo()
a = maximum(3,4) a = maximum(3,4)
@ -140,6 +144,9 @@ if (nsoverload() != 1050):
raise RuntimeError, ("nsoverload(const char *)") raise RuntimeError, ("nsoverload(const char *)")
if is_new_style_class(A):
A.foo(1) A.foo(1)
else:
A_foo(1)
b = B() b = B()
b.foo(1) b.foo(1)

View file

@ -1,12 +1,18 @@
from python_append import * from python_append import *
def is_new_style_class(cls):
return hasattr(cls, "__class__")
# test not relevant for -builtin # test not relevant for -builtin
if is_python_builtin(): if is_python_builtin():
exit(0) exit(0)
t=Test() t=Test()
t.func() t.func()
if is_new_style_class(Test):
t.static_func() t.static_func()
else:
Test_static_func()
if grabpath() != os.path.dirname(mypath): if grabpath() != os.path.dirname(mypath):
raise RuntimeError("grabpath failed") raise RuntimeError("grabpath failed")

View file

@ -5,7 +5,7 @@ from refcount import *
a = A3() a = A3()
b1 = B(a) b1 = B(a)
b2 = B.create(a) b2 = B_create(a)
@ -14,7 +14,7 @@ if a.ref_count() != 3:
rca = b2.get_rca() rca = b2.get_rca()
b3 = B.create(rca) b3 = B_create(rca)
if a.ref_count() != 5: if a.ref_count() != 5:
raise RuntimeError("Count = %d" % a.ref_count()) raise RuntimeError("Count = %d" % a.ref_count())
@ -39,7 +39,7 @@ b5 = global_create(a)
if b5.ref_count() != 1: if b5.ref_count() != 1:
raise RuntimeError raise RuntimeError
b6 = Factory.create(a) b6 = Factory_create(a)
if b6.ref_count() != 1: if b6.ref_count() != 1:
raise RuntimeError raise RuntimeError

View file

@ -1,12 +1,12 @@
import return_const_value import return_const_value
import sys import sys
p = return_const_value.Foo_ptr.getPtr() p = return_const_value.Foo_ptr_getPtr()
if (p.getVal() != 17): if (p.getVal() != 17):
print "Runtime test1 faild. p.getVal()=", p.getVal() print "Runtime test1 faild. p.getVal()=", p.getVal()
sys.exit(1) sys.exit(1)
p = return_const_value.Foo_ptr.getConstPtr() p = return_const_value.Foo_ptr_getConstPtr()
if (p.getVal() != 17): if (p.getVal() != 17):
print "Runtime test2 faild. p.getVal()=", p.getVal() print "Runtime test2 faild. p.getVal()=", p.getVal()
sys.exit(1) sys.exit(1)

View file

@ -1,5 +1,8 @@
from smart_pointer_member import * from smart_pointer_member import *
def is_new_style_class(cls):
return hasattr(cls, "__class__")
f = Foo() f = Foo()
f.y = 1 f.y = 1
@ -20,6 +23,7 @@ if b.x != f.x:
if b.z != f.z: if b.z != f.z:
raise RuntimeError raise RuntimeError
if is_new_style_class(Bar): # feature not supported in old style classes
if Foo.z == Bar.z: if Foo.z == Bar.z:
raise RuntimeError raise RuntimeError

View file

@ -1,5 +1,5 @@
from typemap_out_optimal import * from typemap_out_optimal import *
cvar.XX_debug = False cvar.XX_debug = False
x = XX.create() x = XX_create()