diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2022-01-11 15:11:04 +0000 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2022-01-14 22:48:11 +0000 |
commit | cf8788c411d8096104628dfd5901620b8ea3a315 (patch) | |
tree | a03bd6e7816dab242539d75db9d002f71e99e3df | |
parent | 761099720966c2d6701a1dc1473e918de3571665 (diff) | |
download | swig-cf8788c411d8096104628dfd5901620b8ea3a315.tar.gz |
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.
22 files changed, 52 insertions, 74 deletions
diff --git a/Examples/python/import/runme.py b/Examples/python/import/runme.py index afa21a2b3..7970dec26 100644 --- a/Examples/python/import/runme.py +++ b/Examples/python/import/runme.py @@ -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")) diff --git a/Examples/python/import_template/runme.py b/Examples/python/import_template/runme.py index b14f8d35e..74a918426 100644 --- a/Examples/python/import_template/runme.py +++ b/Examples/python/import_template/runme.py @@ -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")) diff --git a/Examples/test-suite/python/autodoc_runme.py b/Examples/test-suite/python/autodoc_runme.py index 7bc918644..960458584 100644 --- a/Examples/test-suite/python/autodoc_runme.py +++ b/Examples/test-suite/python/autodoc_runme.py @@ -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" diff --git a/Examples/test-suite/python/contract_runme.py b/Examples/test-suite/python/contract_runme.py index b6bab3a09..3194b6ac7 100644 --- a/Examples/test-suite/python/contract_runme.py +++ b/Examples/test-suite/python/contract_runme.py @@ -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 diff --git a/Examples/test-suite/python/default_args_runme.py b/Examples/test-suite/python/default_args_runme.py index 0ce47ab79..b8077cc28 100644 --- a/Examples/test-suite/python/default_args_runme.py +++ b/Examples/test-suite/python/default_args_runme.py @@ -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: diff --git a/Examples/test-suite/python/director_abstract_runme.py b/Examples/test-suite/python/director_abstract_runme.py index c8c4b36dc..fbc54808e 100644 --- a/Examples/test-suite/python/director_abstract_runme.py +++ b/Examples/test-suite/python/director_abstract_runme.py @@ -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) diff --git a/Examples/test-suite/python/director_basic_runme.py b/Examples/test-suite/python/director_basic_runme.py index 79cd0e2eb..2d07c3ad5 100644 --- a/Examples/test-suite/python/director_basic_runme.py +++ b/Examples/test-suite/python/director_basic_runme.py @@ -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) diff --git a/Examples/test-suite/python/director_nested_runme.py b/Examples/test-suite/python/director_nested_runme.py index b2c4b0d40..24216f9dd 100644 --- a/Examples/test-suite/python/director_nested_runme.py +++ b/Examples/test-suite/python/director_nested_runme.py @@ -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": diff --git a/Examples/test-suite/python/kwargs_feature_runme.py b/Examples/test-suite/python/kwargs_feature_runme.py index 387658ec3..d07525ffc 100644 --- a/Examples/test-suite/python/kwargs_feature_runme.py +++ b/Examples/test-suite/python/kwargs_feature_runme.py @@ -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 diff --git a/Examples/test-suite/python/li_boost_shared_ptr_runme.py b/Examples/test-suite/python/li_boost_shared_ptr_runme.py index ecda7fdb1..2e241d590 100644 --- a/Examples/test-suite/python/li_boost_shared_ptr_runme.py +++ b/Examples/test-suite/python/li_boost_shared_ptr_runme.py @@ -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()) diff --git a/Examples/test-suite/python/li_factory_runme.py b/Examples/test-suite/python/li_factory_runme.py index fb2c81e45..ce0e3caef 100644 --- a/Examples/test-suite/python/li_factory_runme.py +++ b/Examples/test-suite/python/li_factory_runme.py @@ -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 diff --git a/Examples/test-suite/python/li_std_auto_ptr_runme.py b/Examples/test-suite/python/li_std_auto_ptr_runme.py index 6d2479f87..d62224ff6 100644 --- a/Examples/test-suite/python/li_std_auto_ptr_runme.py +++ b/Examples/test-suite/python/li_std_auto_ptr_runme.py @@ -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" diff --git a/Examples/test-suite/python/operator_overload_runme.py b/Examples/test-suite/python/operator_overload_runme.py index 31c49058e..cd565f619 100644 --- a/Examples/test-suite/python/operator_overload_runme.py +++ b/Examples/test-suite/python/operator_overload_runme.py @@ -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) diff --git a/Examples/test-suite/python/overload_simple_runme.py b/Examples/test-suite/python/overload_simple_runme.py index 8ad813b86..56763828d 100644 --- a/Examples/test-suite/python/overload_simple_runme.py +++ b/Examples/test-suite/python/overload_simple_runme.py @@ -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 diff --git a/Examples/test-suite/python/overload_template_runme.py b/Examples/test-suite/python/overload_template_runme.py index a484d8f0e..8bd105add 100644 --- a/Examples/test-suite/python/overload_template_runme.py +++ b/Examples/test-suite/python/overload_template_runme.py @@ -140,6 +140,6 @@ if (nsoverload() != 1050): raise RuntimeError(("nsoverload(const char *)")) -A_foo(1) +A.foo(1) b = B() b.foo(1) diff --git a/Examples/test-suite/python/python_overload_simple_cast_runme.py b/Examples/test-suite/python/python_overload_simple_cast_runme.py index 7a0174af8..2aee5bb53 100644 --- a/Examples/test-suite/python/python_overload_simple_cast_runme.py +++ b/Examples/test-suite/python/python_overload_simple_cast_runme.py @@ -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 diff --git a/Examples/test-suite/python/refcount_runme.py b/Examples/test-suite/python/refcount_runme.py index 2cab6a77e..5bea25fa1 100644 --- a/Examples/test-suite/python/refcount_runme.py +++ b/Examples/test-suite/python/refcount_runme.py @@ -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 diff --git a/Examples/test-suite/python/return_const_value_runme.py b/Examples/test-suite/python/return_const_value_runme.py index 809eed97a..8cbac125c 100644 --- a/Examples/test-suite/python/return_const_value_runme.py +++ b/Examples/test-suite/python/return_const_value_runme.py @@ -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())) diff --git a/Examples/test-suite/python/template_static_runme.py b/Examples/test-suite/python/template_static_runme.py index c87a52439..84da28438 100644 --- a/Examples/test-suite/python/template_static_runme.py +++ b/Examples/test-suite/python/template_static_runme.py @@ -1,3 +1,3 @@ from template_static import * -Foo_bar_double(1) +Foo.bar_double(1) diff --git a/Examples/test-suite/python/typemap_out_optimal_runme.py b/Examples/test-suite/python/typemap_out_optimal_runme.py index c7a34308e..c325ece55 100644 --- a/Examples/test-suite/python/typemap_out_optimal_runme.py +++ b/Examples/test-suite/python/typemap_out_optimal_runme.py @@ -1,4 +1,4 @@ from typemap_out_optimal import * cvar.XX_debug = False -x = XX_create() +x = XX.create() diff --git a/Examples/test-suite/python/virtual_poly_runme.py b/Examples/test-suite/python/virtual_poly_runme.py index 0df6271ef..6708b6f99 100644 --- a/Examples/test-suite/python/virtual_poly_runme.py +++ b/Examples/test-suite/python/virtual_poly_runme.py @@ -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 diff --git a/Examples/test-suite/python/voidtest_runme.py b/Examples/test-suite/python/voidtest_runme.py index b16cacf00..dd25b4c25 100644 --- a/Examples/test-suite/python/voidtest_runme.py +++ b/Examples/test-suite/python/voidtest_runme.py @@ -4,7 +4,7 @@ voidtest.globalfunc() f = voidtest.Foo() f.memberfunc() -voidtest.Foo_staticmemberfunc() +voidtest.Foo.staticmemberfunc() def fvoid(): |