Update Python tests to not use flatstaticmethod access

Use Python class staticmethod syntax to access C++ static member functions,
such as Klass.memberfunction, instead of Klass_memberfunction.
Examples and test-suite changes in preparation for issue #2137.
This commit is contained in:
William S Fulton 2022-01-11 15:11:04 +00:00
parent 7610997209
commit cf8788c411
22 changed files with 52 additions and 74 deletions

View File

@ -84,14 +84,14 @@ x.B()
print("\nTesting some dynamic casts\n")
x = d.toBase()
y = foo.Foo_fromBase(x)
y = foo.Foo.fromBase(x)
print(" Spam -> Base -> Foo : {} swig".format("bad" if y else "good"))
y = bar.Bar_fromBase(x)
y = bar.Bar.fromBase(x)
print(" Spam -> Base -> Bar : {} swig".format("good" if y else "bad"))
y = spam.Spam_fromBase(x)
y = spam.Spam.fromBase(x)
print(" Spam -> Base -> Spam : {} swig".format("good" if y else "bad"))
y = spam.Spam_fromBase(b)
y = spam.Spam.fromBase(b)
print(" Foo -> Spam : {} swig".format("bad" if y else "good"))

View File

@ -84,14 +84,14 @@ x.B()
print("\nTesting some dynamic casts\n")
x = d.toBase()
y = foo.intFoo_fromBase(x)
y = foo.intFoo.fromBase(x)
print(" Spam -> Base -> Foo : {} swig".format("bad" if y else "good"))
y = bar.intBar_fromBase(x)
y = bar.intBar.fromBase(x)
print(" Spam -> Base -> Bar : {} swig".format("good" if y else "bad"))
y = spam.intSpam_fromBase(x)
y = spam.intSpam.fromBase(x)
print(" Spam -> Base -> Spam : {} swig".format("good" if y else "bad"))
y = spam.intSpam_fromBase(b)
y = spam.intSpam.fromBase(b)
print(" Foo -> Spam : {} swig".format("bad" if y else "good"))

View File

@ -65,14 +65,10 @@ check(inspect.getdoc(A.func0static),
"func0static(e, arg2, hello, f=2) -> int")
check(inspect.getdoc(_autodoc.A_func0static),
"A_func0static(e, arg2, hello, f=2) -> int")
check(inspect.getdoc(A_func0static),
"A_func0static(e, arg2, hello, f=2) -> int")
check(inspect.getdoc(A.func1static),
"func1static(A e, short arg2, Tuple hello, double f=2) -> int")
check(inspect.getdoc(_autodoc.A_func1static),
"A_func1static(A e, short arg2, Tuple hello, double f=2) -> int")
check(inspect.getdoc(A_func1static),
"A_func1static(A e, short arg2, Tuple hello, double f=2) -> int")
check(inspect.getdoc(A.func2static),
"func2static(e, arg2, hello, f=2) -> int\n"
"\n"
@ -91,15 +87,6 @@ check(inspect.getdoc(_autodoc.A_func2static),
"arg2: short\n"
"hello: int tuple[2]\n"
"f: double")
check(inspect.getdoc(A_func2static),
"A_func2static(e, arg2, hello, f=2) -> int\n"
"\n"
"Parameters\n"
"----------\n"
"e: A *\n"
"arg2: short\n"
"hello: int tuple[2]\n"
"f: double")
check(inspect.getdoc(A.func3static),
"func3static(A e, short arg2, Tuple hello, double f=2) -> int\n"
"\n"
@ -118,15 +105,6 @@ check(inspect.getdoc(_autodoc.A_func3static),
"arg2: short\n"
"hello: int tuple[2]\n"
"f: double")
check(inspect.getdoc(A_func3static),
"A_func3static(A e, short arg2, Tuple hello, double f=2) -> int\n"
"\n"
"Parameters\n"
"----------\n"
"e: A *\n"
"arg2: short\n"
"hello: int tuple[2]\n"
"f: double")
check(inspect.getdoc(A.variable_a),
"variable_a"

View File

@ -58,15 +58,15 @@ try:
except RuntimeError:
pass
contract.Foo_stest_prepost(4, 0)
contract.Foo.stest_prepost(4, 0)
try:
contract.Foo_stest_prepost(-4, 2)
contract.Foo.stest_prepost(-4, 2)
raise Exception("Failed! Static method preassertion")
except RuntimeError:
pass
try:
contract.Foo_stest_prepost(4, -10)
contract.Foo.stest_prepost(4, -10)
raise Exception("Failed! Static method posteassertion")
except RuntimeError:
pass

View File

@ -12,7 +12,7 @@ def run(module_name):
de.accelerate()
de.accelerate(default_args.EnumClass.SLOW)
if default_args.Statics_staticMethod() != 60:
if default_args.Statics.staticMethod() != 60:
raise RuntimeError
if default_args.cfunc1(1) != 2:

View File

@ -37,7 +37,7 @@ class MyExample3(director_abstract.Example3_i):
return b
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
me2 = MyExample2(1, 2)

View File

@ -44,8 +44,8 @@ b = director_basic.Bar(3)
d = director_basic.MyClass()
c = PyClass()
cc = director_basic.MyClass_get_self(c)
dd = director_basic.MyClass_get_self(d)
cc = director_basic.MyClass.get_self(c)
dd = director_basic.MyClass.get_self(d)
bc = cc.cmethod(b)
bd = dd.cmethod(b)
@ -86,8 +86,8 @@ for i in range(0, 100):
pymult = PyMulti()
p1 = director_basic.Foo_get_self(pymult)
p2 = director_basic.MyClass_get_self(pymult)
p1 = director_basic.Foo.get_self(pymult)
p2 = director_basic.MyClass.get_self(pymult)
p1.ping()
p2.vmethod(bc)

View File

@ -54,7 +54,7 @@ class C(FooBar_int):
pass
cc = C()
c = FooBar_int_get_self(cc)
c = FooBar_int.get_self(cc)
c.advance()
if c.get_name() != "FooBar::get_name hello":

View File

@ -15,13 +15,13 @@ f = Foo(b=2, a=1)
if f.foo(b=1, a=2) != 3:
raise RuntimeError
if Foo_statfoo(b=2) != 3:
if Foo.statfoo(b=2) != 3:
raise RuntimeError
if f.efoo(b=2) != 3:
raise RuntimeError
if Foo_sfoo(b=2) != 3:
if Foo.sfoo(b=2) != 3:
raise RuntimeError
@ -31,13 +31,13 @@ b = BarInt(b=2, a=1)
if b.bar(b=1, a=2) != 3:
raise RuntimeError
if BarInt_statbar(b=2) != 3:
if BarInt.statbar(b=2) != 3:
raise RuntimeError
if b.ebar(b=2) != 3:
raise RuntimeError
if BarInt_sbar(b=2) != 3:
if BarInt.sbar(b=2) != 3:
raise RuntimeError

View File

@ -20,7 +20,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())

View File

@ -1,11 +1,11 @@
from li_factory import *
circle = Geometry_create(Geometry.CIRCLE)
circle = Geometry.create(Geometry.CIRCLE)
r = circle.radius()
if (r != 1.5):
raise RuntimeError
point = Geometry_create(Geometry.POINT)
point = Geometry.create(Geometry.POINT)
w = point.width()
if (w != 1.0):
raise RuntimeError

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

@ -1,7 +1,7 @@
from operator_overload import *
# first check all the operators are implemented correctly from pure C++ code
Op_sanity_check()
Op.sanity_check()
pop = Op(6)/Op(3)

View File

@ -43,22 +43,22 @@ if s.foo(b) != "foo:Bar *":
if s.foo(v) != "foo:void *":
raise RuntimeError("Spam::foo(void *)")
if Spam_bar(3) != "bar:int":
if Spam.bar(3) != "bar:int":
raise RuntimeError("Spam::bar(int)")
if Spam_bar(3.0) != "bar:double":
if Spam.bar(3.0) != "bar:double":
raise RuntimeError("Spam::bar(double)")
if Spam_bar("hello") != "bar:char *":
if Spam.bar("hello") != "bar:char *":
raise RuntimeError("Spam::bar(char *)")
if Spam_bar(f) != "bar:Foo *":
if Spam.bar(f) != "bar:Foo *":
raise RuntimeError("Spam::bar(Foo *)")
if Spam_bar(b) != "bar:Bar *":
if Spam.bar(b) != "bar:Bar *":
raise RuntimeError("Spam::bar(Bar *)")
if Spam_bar(v) != "bar:void *":
if Spam.bar(v) != "bar:void *":
raise RuntimeError("Spam::bar(void *)")
# Test constructors

View File

@ -140,6 +140,6 @@ if (nsoverload() != 1050):
raise RuntimeError(("nsoverload(const char *)"))
A_foo(1)
A.foo(1)
b = B()
b.foo(1)

View File

@ -115,22 +115,22 @@ if s.foo(b) != "foo:Bar *":
if s.foo(v) != "foo:void *":
raise RuntimeError("Spam::foo(void *)")
if Spam_bar(3) != "bar:int":
if Spam.bar(3) != "bar:int":
raise RuntimeError("Spam::bar(int)")
if Spam_bar(3.0) != "bar:double":
if Spam.bar(3.0) != "bar:double":
raise RuntimeError("Spam::bar(double)")
if Spam_bar("hello") != "bar:char *":
if Spam.bar("hello") != "bar:char *":
raise RuntimeError("Spam::bar(char *)")
if Spam_bar(f) != "bar:Foo *":
if Spam.bar(f) != "bar:Foo *":
raise RuntimeError("Spam::bar(Foo *)")
if Spam_bar(b) != "bar:Bar *":
if Spam.bar(b) != "bar:Bar *":
raise RuntimeError("Spam::bar(Bar *)")
if Spam_bar(v) != "bar:void *":
if Spam.bar(v) != "bar:void *":
raise RuntimeError("Spam::bar(void *)")
# Test constructors

View File

@ -5,7 +5,7 @@ from refcount import *
a = A3()
b1 = B(a)
b2 = B_create(a)
b2 = B.create(a)
if a.ref_count() != 3:
@ -13,7 +13,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())
@ -38,7 +38,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,10 +1,10 @@
import return_const_value
import sys
p = return_const_value.Foo_ptr_getPtr()
p = return_const_value.Foo_ptr.getPtr()
if (p.getVal() != 17):
raise RuntimeError("Runtime test1 failed. p.getVal()={}".format(p.getVal()))
p = return_const_value.Foo_ptr_getConstPtr()
p = return_const_value.Foo_ptr.getConstPtr()
if (p.getVal() != 17):
raise RuntimeError("Runtime test2 failed. p.getVal()={}".format(p.getVal()))

View File

@ -1,3 +1,3 @@
from template_static import *
Foo_bar_double(1)
Foo.bar_double(1)

View File

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

View File

@ -29,10 +29,10 @@ if d.get() != dr.get():
#
# 'narrowing' also works
#
ddc = virtual_poly.NDouble_narrow(d.nnumber())
ddc = virtual_poly.NDouble.narrow(d.nnumber())
if d.get() != ddc.get():
raise RuntimeError
dic = virtual_poly.NInt_narrow(i.nnumber())
dic = virtual_poly.NInt.narrow(i.nnumber())
if i.get() != dic.get():
raise RuntimeError

View File

@ -4,7 +4,7 @@ voidtest.globalfunc()
f = voidtest.Foo()
f.memberfunc()
voidtest.Foo_staticmemberfunc()
voidtest.Foo.staticmemberfunc()
def fvoid():