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

@ -9,6 +9,13 @@ def check(got, expected, expected_builtin = None, skip = False):
if expect != 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
check(A.__doc__, "Proxy of C++ A class", "::A")

View file

@ -1,7 +1,16 @@
#!/usr/bin/evn python
from cpp_static import *
StaticFunctionTest.static_func()
StaticFunctionTest.static_func_2(1)
StaticFunctionTest.static_func_3(1,2)
def is_new_style_class(cls):
return hasattr(cls, "__class__")
if is_new_style_class(StaticFunctionTest):
StaticFunctionTest.static_func()
StaticFunctionTest.static_func_2(1)
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
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
def is_new_style_class(cls):
return hasattr(cls, "__class__")
def run(module_name):
default_args = __import__(module_name)
ec = default_args.EnumClass()
@ -71,13 +74,15 @@ def run(module_name):
error = 0
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")
if default_args.Klass.inc(100).val != 99:
if Klass_inc(100).val != 99:
raise RuntimeError("Klass::inc failed")
if default_args.Klass.inc().val != 0:
if Klass_inc().val != 0:
raise RuntimeError("Klass::inc failed")
default_args.trickyvalue1(10); default_args.trickyvalue1(10, 10)

View file

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

View file

@ -1,5 +1,8 @@
from global_namespace import *
def is_new_style_class(cls):
return hasattr(cls, "__class__")
k1 = Klass1()
k2 = Klass2()
k3 = Klass3()
@ -8,8 +11,10 @@ k5 = Klass5()
k6 = Klass6()
k7 = Klass7()
KlassMethods.methodA(k1, k2, k3, k4, k5, k6, k7)
KlassMethods.methodB(k1, k2, k3, k4, k5, k6, k7)
KlassMethods_static = KlassMethods if is_new_style_class(KlassMethods) else KlassMethods()
KlassMethods_static.methodA(k1, k2, k3, k4, k5, k6, k7)
KlassMethods_static.methodB(k1, k2, k3, k4, k5, k6, k7)
k1 = getKlass1A()
k2 = getKlass2A()
@ -19,8 +24,8 @@ k5 = getKlass5A()
k6 = getKlass6A()
k7 = getKlass7A()
KlassMethods.methodA(k1, k2, k3, k4, k5, k6, k7)
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 = getKlass1B()
k2 = getKlass2B()
@ -30,11 +35,13 @@ k5 = getKlass5B()
k6 = getKlass6B()
k7 = getKlass7B()
KlassMethods.methodA(k1, k2, k3, k4, k5, k6, k7)
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)
XYZMethods.methodA(XYZ1(), XYZ2(), XYZ3(), XYZ4(), XYZ5(), XYZ6(), XYZ7())
XYZMethods.methodB(XYZ1(), XYZ2(), XYZ3(), XYZ4(), XYZ5(), XYZ6(), XYZ7())
XYZMethods_static = XYZMethods if is_new_style_class(XYZMethods) else XYZMethods()
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.methodA(theenum1, theenum2, theenum3)
TheEnumMethods_static = TheEnumMethods if is_new_style_class(TheEnumMethods) else TheEnumMethods()
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:
raise RuntimeError(str(a) + " does not equal " + str(b))
def is_new_style_class(cls):
return hasattr(cls, "__class__")
#### Class ####
# No implicit conversion
@ -39,13 +42,14 @@ check(2, A_int(1.0).get())
check(3, A_int(B()).get())
check(4, A_int("hello").get())
check(1, A_int.sget(1))
check(2, A_int.sget(1.0))
check(3, A_int.sget(B()))
A_int_static = A_int if is_new_style_class(A_int) else A_int(0)
check(1, A_int_static.sget(1))
check(2, A_int_static.sget(1.0))
check(3, A_int_static.sget(B()))
# explicit constructor:
try:
check(4, A_int.sget("hello"))
check(4, A_int_static.sget("hello"))
raise RuntimeError
except TypeError:
pass

View file

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

View file

@ -17,7 +17,7 @@ class li_boost_shared_ptr_runme:
self.runtest()
# 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())
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")
k2 = makeKlassAutoPtr("second")
if Klass.getTotal_count() != 2:
if Klass_getTotal_count() != 2:
raise "number of objects should be 2"
del k1
if Klass.getTotal_count() != 1:
if Klass_getTotal_count() != 1:
raise "number of objects should be 1"
if k2.getLabel() != "second":
raise "wrong object label"
del k2
if Klass.getTotal_count() != 0:
if Klass_getTotal_count() != 0:
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))
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):
failed(a, b, "different sizes")
for i in range(len(a)):

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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