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
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") print("\nTesting some dynamic casts\n")
x = d.toBase() x = d.toBase()
y = foo.Foo_fromBase(x) y = foo.Foo.fromBase(x)
print(" Spam -> Base -> Foo : {} swig".format("bad" if y else "good")) 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")) 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")) 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")) print(" Foo -> Spam : {} swig".format("bad" if y else "good"))

View file

@ -84,14 +84,14 @@ x.B()
print("\nTesting some dynamic casts\n") print("\nTesting some dynamic casts\n")
x = d.toBase() x = d.toBase()
y = foo.intFoo_fromBase(x) y = foo.intFoo.fromBase(x)
print(" Spam -> Base -> Foo : {} swig".format("bad" if y else "good")) 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")) 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")) 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")) 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") "func0static(e, arg2, hello, f=2) -> int")
check(inspect.getdoc(_autodoc.A_func0static), check(inspect.getdoc(_autodoc.A_func0static),
"A_func0static(e, arg2, hello, f=2) -> int") "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), check(inspect.getdoc(A.func1static),
"func1static(A e, short arg2, Tuple hello, double f=2) -> int") "func1static(A e, short arg2, Tuple hello, double f=2) -> int")
check(inspect.getdoc(_autodoc.A_func1static), check(inspect.getdoc(_autodoc.A_func1static),
"A_func1static(A e, short arg2, Tuple hello, double f=2) -> int") "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), check(inspect.getdoc(A.func2static),
"func2static(e, arg2, hello, f=2) -> int\n" "func2static(e, arg2, hello, f=2) -> int\n"
"\n" "\n"
@ -91,15 +87,6 @@ check(inspect.getdoc(_autodoc.A_func2static),
"arg2: short\n" "arg2: short\n"
"hello: int tuple[2]\n" "hello: int tuple[2]\n"
"f: double") "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), check(inspect.getdoc(A.func3static),
"func3static(A e, short arg2, Tuple hello, double f=2) -> int\n" "func3static(A e, short arg2, Tuple hello, double f=2) -> int\n"
"\n" "\n"
@ -118,15 +105,6 @@ check(inspect.getdoc(_autodoc.A_func3static),
"arg2: short\n" "arg2: short\n"
"hello: int tuple[2]\n" "hello: int tuple[2]\n"
"f: double") "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), check(inspect.getdoc(A.variable_a),
"variable_a" "variable_a"

View file

@ -58,15 +58,15 @@ try:
except RuntimeError: 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)
raise Exception("Failed! Static method preassertion") raise Exception("Failed! Static method preassertion")
except RuntimeError: except RuntimeError:
pass pass
try: try:
contract.Foo_stest_prepost(4, -10) contract.Foo.stest_prepost(4, -10)
raise Exception("Failed! Static method posteassertion") raise Exception("Failed! Static method posteassertion")
except RuntimeError: except RuntimeError:
pass pass

View file

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

View file

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

View file

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

View file

@ -54,7 +54,7 @@ class C(FooBar_int):
pass pass
cc = C() cc = C()
c = FooBar_int_get_self(cc) c = FooBar_int.get_self(cc)
c.advance() c.advance()
if c.get_name() != "FooBar::get_name hello": 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: if f.foo(b=1, a=2) != 3:
raise RuntimeError raise RuntimeError
if Foo_statfoo(b=2) != 3: if Foo.statfoo(b=2) != 3:
raise RuntimeError raise RuntimeError
if f.efoo(b=2) != 3: if f.efoo(b=2) != 3:
raise RuntimeError raise RuntimeError
if Foo_sfoo(b=2) != 3: if Foo.sfoo(b=2) != 3:
raise RuntimeError raise RuntimeError
@ -31,13 +31,13 @@ b = BarInt(b=2, a=1)
if b.bar(b=1, a=2) != 3: if b.bar(b=1, a=2) != 3:
raise RuntimeError raise RuntimeError
if BarInt_statbar(b=2) != 3: if BarInt.statbar(b=2) != 3:
raise RuntimeError raise RuntimeError
if b.ebar(b=2) != 3: if b.ebar(b=2) != 3:
raise RuntimeError raise RuntimeError
if BarInt_sbar(b=2) != 3: if BarInt.sbar(b=2) != 3:
raise RuntimeError raise RuntimeError

View file

@ -20,7 +20,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" % raise RuntimeError("Klass.total_count=%s" %
li_boost_shared_ptr.Klass.getTotal_count()) li_boost_shared_ptr.Klass.getTotal_count())

View file

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

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

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

View file

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

View file

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

View file

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

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)
if a.ref_count() != 3: if a.ref_count() != 3:
@ -13,7 +13,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())
@ -38,7 +38,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,10 +1,10 @@
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):
raise RuntimeError("Runtime test1 failed. p.getVal()={}".format(p.getVal())) 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): if (p.getVal() != 17):
raise RuntimeError("Runtime test2 failed. p.getVal()={}".format(p.getVal())) raise RuntimeError("Runtime test2 failed. p.getVal()={}".format(p.getVal()))

View file

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

View file

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

View file

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

View file

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