aboutsummaryrefslogtreecommitdiff
path: root/Examples/test-suite/python
diff options
context:
space:
mode:
authorAlistair Delva <adelva@google.com>2024-04-10 14:15:29 -0700
committerAlistair Delva <adelva@google.com>2024-04-11 12:58:28 -0700
commitd0f0f90be16c2ac553b5fa08512045273135147a (patch)
tree5d9ebb7a04807ea8a609ddd18b0162bc87530e4b /Examples/test-suite/python
parent6ffc1dbf29ba98c4d8aa71ebc9b484e973fe1030 (diff)
downloadswig-d0f0f90be16c2ac553b5fa08512045273135147a.tar.gz
Change-Id: I47cef2be94299220d80265d949a95b58eee2c23b
Diffstat (limited to 'Examples/test-suite/python')
-rw-r--r--Examples/test-suite/python/Makefile.in139
-rw-r--r--Examples/test-suite/python/README9
-rw-r--r--Examples/test-suite/python/abstract_basecast_runme.py15
-rw-r--r--Examples/test-suite/python/argcargvtest_runme.py30
-rw-r--r--Examples/test-suite/python/array_member_runme.py4
-rw-r--r--Examples/test-suite/python/autodoc_runme.py70
-rw-r--r--Examples/test-suite/python/callback_runme.py11
-rw-r--r--Examples/test-suite/python/catches_strings_runme.py21
-rw-r--r--Examples/test-suite/python/ccomplextest_runme.py22
-rw-r--r--Examples/test-suite/python/char_binary_runme.py20
-rw-r--r--Examples/test-suite/python/complextest_runme.py11
-rw-r--r--Examples/test-suite/python/constover_runme.py19
-rw-r--r--Examples/test-suite/python/constructor_copy_non_const_runme.py13
-rw-r--r--Examples/test-suite/python/contract_runme.py96
-rw-r--r--Examples/test-suite/python/copyctor_runme.py13
-rw-r--r--Examples/test-suite/python/cpp11_alternate_function_syntax_runme.py10
-rw-r--r--Examples/test-suite/python/cpp11_decltype_runme.py30
-rw-r--r--Examples/test-suite/python/cpp11_director_using_constructor_runme.py145
-rw-r--r--Examples/test-suite/python/cpp11_final_class_runme.py65
-rw-r--r--Examples/test-suite/python/cpp11_hash_tables_runme.py16
-rw-r--r--Examples/test-suite/python/cpp11_inheriting_constructors_runme.py11
-rw-r--r--Examples/test-suite/python/cpp11_move_only_runme.py27
-rw-r--r--Examples/test-suite/python/cpp11_move_typemaps_runme.py29
-rw-r--r--Examples/test-suite/python/cpp11_null_pointer_constant_runme.py8
-rw-r--r--Examples/test-suite/python/cpp11_raw_string_literals_runme.py14
-rw-r--r--Examples/test-suite/python/cpp11_result_of_runme.py8
-rw-r--r--Examples/test-suite/python/cpp11_rvalue_reference_move_runme.py69
-rw-r--r--Examples/test-suite/python/cpp11_rvalue_reference_runme.py10
-rw-r--r--Examples/test-suite/python/cpp11_shared_ptr_template_upcast_runme.py5
-rw-r--r--Examples/test-suite/python/cpp11_shared_ptr_upcast_runme.py63
-rw-r--r--Examples/test-suite/python/cpp11_std_array_runme.py40
-rw-r--r--Examples/test-suite/python/cpp11_std_unique_ptr_runme.py109
-rw-r--r--Examples/test-suite/python/cpp11_template_explicit_runme.py15
-rw-r--r--Examples/test-suite/python/cpp11_uniform_initialization_runme.py8
-rw-r--r--Examples/test-suite/python/cpp11_using_constructor_runme.py145
-rw-r--r--Examples/test-suite/python/cpp11_variadic_function_templates_runme.py20
-rw-r--r--Examples/test-suite/python/cpp11_variadic_templates_runme.py158
-rw-r--r--Examples/test-suite/python/cpp14_auto_return_type_runme.py10
-rw-r--r--Examples/test-suite/python/cpp14_binary_integer_literals_runme.py9
-rw-r--r--Examples/test-suite/python/cpp17_director_string_view_runme.py34
-rw-r--r--Examples/test-suite/python/cpp17_std_filesystem_runme.py64
-rw-r--r--Examples/test-suite/python/cpp17_string_view_runme.py51
-rw-r--r--Examples/test-suite/python/cpp20_spaceship_operator_runme.py19
-rw-r--r--Examples/test-suite/python/cpp_enum_runme.py12
-rw-r--r--Examples/test-suite/python/cpp_parameters_runme.py296
-rw-r--r--Examples/test-suite/python/default_args_runme.py36
-rw-r--r--Examples/test-suite/python/default_constructor_runme.py32
-rw-r--r--Examples/test-suite/python/director_abstract_runme.py6
-rw-r--r--Examples/test-suite/python/director_alternating_runme.py2
-rw-r--r--Examples/test-suite/python/director_basic_runme.py16
-rw-r--r--Examples/test-suite/python/director_comparison_operators_runme.py11
-rw-r--r--Examples/test-suite/python/director_detect_runme.py2
-rw-r--r--Examples/test-suite/python/director_exception_runme.py52
-rw-r--r--Examples/test-suite/python/director_extend_runme.py4
-rw-r--r--Examples/test-suite/python/director_frob_runme.py2
-rw-r--r--Examples/test-suite/python/director_multiple_inheritance_runme.py36
-rw-r--r--Examples/test-suite/python/director_nested_runme.py6
-rw-r--r--Examples/test-suite/python/director_pass_by_value_runme.py2
-rw-r--r--Examples/test-suite/python/director_profile_runme.py2
-rw-r--r--Examples/test-suite/python/director_property_runme.py37
-rw-r--r--Examples/test-suite/python/director_protected_runme.py30
-rw-r--r--Examples/test-suite/python/director_smartptr_runme.py2
-rw-r--r--Examples/test-suite/python/director_string_runme.py12
-rw-r--r--Examples/test-suite/python/director_thread_runme.py3
-rw-r--r--Examples/test-suite/python/director_unroll_runme.py3
-rw-r--r--Examples/test-suite/python/director_wstring_runme.py34
-rw-r--r--Examples/test-suite/python/doxygen_autodoc_docstring_runme.py44
-rw-r--r--Examples/test-suite/python/doxygen_basic_translate_runme.py12
-rw-r--r--Examples/test-suite/python/doxygen_basic_translate_style2_runme.py2
-rw-r--r--Examples/test-suite/python/doxygen_basic_translate_style3_runme.py82
-rw-r--r--Examples/test-suite/python/doxygen_code_blocks_runme.py58
-rw-r--r--Examples/test-suite/python/doxygen_misc_constructs_runme.py12
-rw-r--r--Examples/test-suite/python/doxygen_translate_all_tags_runme.py14
-rw-r--r--Examples/test-suite/python/doxygen_translate_runme.py3
-rw-r--r--Examples/test-suite/python/dynamic_cast_runme.py2
-rw-r--r--Examples/test-suite/python/exception_order_runme.py21
-rw-r--r--Examples/test-suite/python/extern_c_runme.py7
-rw-r--r--Examples/test-suite/python/final_c_runme.py6
-rw-r--r--Examples/test-suite/python/friends_operator_overloading_runme.py41
-rw-r--r--Examples/test-suite/python/friends_runme.py22
-rw-r--r--Examples/test-suite/python/fvirtual_runme.py2
-rw-r--r--Examples/test-suite/python/global_functions_runme.py10
-rw-r--r--Examples/test-suite/python/global_vars_runme.py4
-rw-r--r--Examples/test-suite/python/ignore_parameter_runme.py1
-rw-r--r--Examples/test-suite/python/import_stl_runme.py2
-rw-r--r--Examples/test-suite/python/inctest_runme.py18
-rw-r--r--Examples/test-suite/python/inherit_missing_runme.py6
-rw-r--r--Examples/test-suite/python/inplaceadd_runme.py3
-rw-r--r--Examples/test-suite/python/kwargs_feature_runme.py69
-rw-r--r--Examples/test-suite/python/langobj_runme.py2
-rw-r--r--Examples/test-suite/python/li_attribute_runme.py11
-rw-r--r--Examples/test-suite/python/li_attribute_template_runme.py3
-rw-r--r--Examples/test-suite/python/li_boost_shared_ptr_director_runme.py42
-rw-r--r--Examples/test-suite/python/li_boost_shared_ptr_runme.py19
-rw-r--r--Examples/test-suite/python/li_constraints_runme.py54
-rw-r--r--Examples/test-suite/python/li_cstring_runme.py6
-rw-r--r--Examples/test-suite/python/li_cwstring_runme.py18
-rw-r--r--Examples/test-suite/python/li_factory_runme.py4
-rw-r--r--Examples/test-suite/python/li_implicit_runme.py6
-rw-r--r--Examples/test-suite/python/li_std_auto_ptr_runme.py104
-rw-r--r--Examples/test-suite/python/li_std_carray_runme.py39
-rw-r--r--Examples/test-suite/python/li_std_containers_int_runme.py46
-rw-r--r--Examples/test-suite/python/li_std_map_runme.py31
-rw-r--r--Examples/test-suite/python/li_std_pair_runme.py47
-rw-r--r--Examples/test-suite/python/li_std_set_runme.py30
-rw-r--r--Examples/test-suite/python/li_std_stream_runme.py3
-rw-r--r--Examples/test-suite/python/li_std_string_extra_runme.py72
-rw-r--r--Examples/test-suite/python/li_std_vector_enum_runme.py2
-rw-r--r--Examples/test-suite/python/li_std_vector_extra_runme.py30
-rw-r--r--Examples/test-suite/python/li_std_vector_runme.py24
-rw-r--r--Examples/test-suite/python/li_std_wstream_runme.py5
-rw-r--r--Examples/test-suite/python/li_std_wstring_inherit_runme.py13
-rw-r--r--Examples/test-suite/python/li_std_wstring_runme.py12
-rw-r--r--Examples/test-suite/python/minherit_runme.py40
-rw-r--r--Examples/test-suite/python/multivalue_runme.py19
-rw-r--r--Examples/test-suite/python/name_warnings_runme.py9
-rw-r--r--Examples/test-suite/python/namespace_class_runme.py4
-rw-r--r--Examples/test-suite/python/not_c_keywords_runme.py7
-rw-r--r--Examples/test-suite/python/operator_overload_runme.py2
-rw-r--r--Examples/test-suite/python/overload_complicated_runme.py22
-rw-r--r--Examples/test-suite/python/overload_null_runme.py14
-rw-r--r--Examples/test-suite/python/overload_simple_runme.py62
-rw-r--r--Examples/test-suite/python/overload_subtype_runme.py4
-rw-r--r--Examples/test-suite/python/overload_template_fast_runme.py78
-rw-r--r--Examples/test-suite/python/overload_template_runme.py80
-rw-r--r--Examples/test-suite/python/pointer_reference_runme.py8
-rw-r--r--Examples/test-suite/python/preproc_cpp_runme.py4
-rw-r--r--Examples/test-suite/python/preproc_defined_runme.py9
-rw-r--r--Examples/test-suite/python/primitive_types_runme.py108
-rw-r--r--Examples/test-suite/python/python_abstractbase_runme.py40
-rw-r--r--Examples/test-suite/python/python_abstractbase_runme3.py35
-rw-r--r--Examples/test-suite/python/python_annotations_c_runme.py31
-rw-r--r--Examples/test-suite/python/python_annotations_variable_c_runme.py24
-rw-r--r--Examples/test-suite/python/python_append_runme.py13
-rw-r--r--Examples/test-suite/python/python_builtin_runme.py25
-rw-r--r--Examples/test-suite/python/python_destructor_exception_runme.py10
-rw-r--r--Examples/test-suite/python/python_flatstaticmethod_runme.py92
-rw-r--r--Examples/test-suite/python/python_nondynamic_runme.py18
-rw-r--r--Examples/test-suite/python/python_overload_simple_cast_runme.py239
-rw-r--r--Examples/test-suite/python/python_pickle_runme.py12
-rw-r--r--Examples/test-suite/python/python_pybuffer_runme.py28
-rw-r--r--Examples/test-suite/python/python_richcompare_runme.py88
-rw-r--r--Examples/test-suite/python/python_runtime_data_runme.py15
-rw-r--r--Examples/test-suite/python/python_strict_unicode_runme.py22
-rw-r--r--Examples/test-suite/python/python_typemap_macro_runme.py27
-rw-r--r--Examples/test-suite/python/refcount_runme.py6
-rw-r--r--Examples/test-suite/python/return_const_value_runme.py10
-rw-r--r--Examples/test-suite/python/smart_pointer_member_runme.py4
-rw-r--r--Examples/test-suite/python/smart_pointer_not_runme.py24
-rw-r--r--Examples/test-suite/python/special_variable_macros_runme.py9
-rw-r--r--Examples/test-suite/python/std_containers_runme.py21
-rw-r--r--Examples/test-suite/python/struct_value_runme.py4
-rw-r--r--Examples/test-suite/python/swigobject_runme.py20
-rw-r--r--Examples/test-suite/python/template_classes_runme.py8
-rw-r--r--Examples/test-suite/python/template_default_arg_runme.py40
-rw-r--r--Examples/test-suite/python/template_static_runme.py2
-rw-r--r--Examples/test-suite/python/template_template_parameters_runme.py33
-rw-r--r--Examples/test-suite/python/template_templated_constructors_runme.py20
-rw-r--r--Examples/test-suite/python/template_typedef_cplx2_runme.py39
-rw-r--r--Examples/test-suite/python/template_typedef_cplx_runme.py36
-rw-r--r--Examples/test-suite/python/template_typedef_runme.py9
-rw-r--r--Examples/test-suite/python/template_typemaps_typedef2_runme.py16
-rw-r--r--Examples/test-suite/python/template_typemaps_typedef_runme.py16
-rw-r--r--Examples/test-suite/python/template_using_member_default_arg_runme.py6
-rw-r--r--Examples/test-suite/python/threads_exception_runme.py16
-rw-r--r--Examples/test-suite/python/typedef_inherit_runme.py12
-rw-r--r--Examples/test-suite/python/typedef_scope_runme.py4
-rw-r--r--Examples/test-suite/python/typemap_arrays_runme.py2
-rw-r--r--Examples/test-suite/python/typemap_out_optimal_runme.py7
-rw-r--r--Examples/test-suite/python/typename_runme.py8
-rw-r--r--Examples/test-suite/python/unicode_strings_runme.py39
-rw-r--r--Examples/test-suite/python/unions_runme.py16
-rw-r--r--Examples/test-suite/python/using_composition_runme.py18
-rw-r--r--Examples/test-suite/python/using_extend_runme.py12
-rw-r--r--Examples/test-suite/python/using_inherit_runme.py24
-rw-r--r--Examples/test-suite/python/using_member_multiple_inherit_runme.py32
-rw-r--r--Examples/test-suite/python/using_member_runme.py24
-rw-r--r--Examples/test-suite/python/using_private_runme.py6
-rw-r--r--Examples/test-suite/python/using_protected_runme.py2
-rw-r--r--Examples/test-suite/python/varargs_overload_runme.py36
-rw-r--r--Examples/test-suite/python/varargs_runme.py20
-rw-r--r--Examples/test-suite/python/virtual_derivation_runme.py2
-rw-r--r--Examples/test-suite/python/virtual_poly_runme.py4
-rw-r--r--Examples/test-suite/python/voidtest_runme.py2
184 files changed, 3906 insertions, 1279 deletions
diff --git a/Examples/test-suite/python/Makefile.in b/Examples/test-suite/python/Makefile.in
index be06f7e51..fca2d3ff5 100644
--- a/Examples/test-suite/python/Makefile.in
+++ b/Examples/test-suite/python/Makefile.in
@@ -2,7 +2,7 @@
# Makefile for python test-suite
#######################################################################
-ifeq (,$(PY3))
+ifneq (,$(PY2))
PYBIN = @PYTHON@
else
PYBIN = @PYTHON3@
@@ -10,26 +10,30 @@ endif
LANGUAGE = python
PYTHON = $(PYBIN)
+SCRIPTSUFFIX = _runme.py
PYCODESTYLE = @PYCODESTYLE@
-PYCODESTYLE_FLAGS = --ignore=E252,E30,E402,E501,E731,W291,W391
-
-#*_runme.py for Python 2.x, *_runme3.py for Python 3.x
-PY2SCRIPTSUFFIX = _runme.py
-PY3SCRIPTSUFFIX = _runme3.py
-PY2TO3 = @PY2TO3@ -x import
-
-ifeq (,$(PY3))
- SCRIPTSUFFIX = $(PY2SCRIPTSUFFIX)
-else
- SCRIPTSUFFIX = $(PY3SCRIPTSUFFIX)
-endif
+PYCODESTYLE_FLAGS = --ignore=E252,E30,E402,E501,E731,E741,W291,W391
+HAVE_CXX11 = @HAVE_CXX11@
+HAVE_CXX14 = @HAVE_CXX14@
+HAVE_CXX17 = @HAVE_CXX17@
+HAVE_CXX20 = @HAVE_CXX20@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
top_builddir = @top_builddir@
+FAILING_CPP_TESTS = \
+ cpp17_map_no_default_ctor \
+
+ifneq (,$(PY2))
+# std_string_view.i is not implemented for Python2 so don't try to run tests needing it.
+FAILING_CPP_TESTS += \
+ cpp17_director_string_view \
+ cpp17_string_view \
+
+endif
+
CPP_TEST_CASES += \
- argcargvtest \
callback \
complextest \
director_stl \
@@ -58,12 +62,15 @@ CPP_TEST_CASES += \
li_std_wstring_inherit \
primitive_types \
python_abstractbase \
+ python_annotations_c \
+ python_annotations_variable_c \
python_append \
python_builtin \
python_destructor_exception \
python_director \
python_docstring \
python_extranative \
+ python_flatstaticmethod \
python_moduleimport \
python_overload_simple_cast \
python_pickle \
@@ -72,79 +79,78 @@ CPP_TEST_CASES += \
python_richcompare \
python_strict_unicode \
python_threads \
+ python_typemap_macro \
simutry \
std_containers \
swigobject \
template_matrix \
-# li_std_carray
# director_profile
CPP11_TEST_CASES = \
cpp11_hash_tables \
cpp11_shared_ptr_const \
+ cpp11_shared_ptr_crtp_upcast \
cpp11_shared_ptr_nullptr_in_containers \
cpp11_shared_ptr_overload \
+ cpp11_shared_ptr_template_upcast \
cpp11_shared_ptr_upcast \
cpp11_std_unordered_map \
cpp11_std_unordered_multimap \
cpp11_std_unordered_multiset \
cpp11_std_unordered_set \
+CPP17_TEST_CASES = \
+ cpp17_std_filesystem
+
C_TEST_CASES += \
+ ccomplextest \
file_test \
li_cstring \
li_cwstring \
python_nondynamic \
python_varargs_typemap \
-#
-# This test only works with modern C compilers
-#
-#C_TEST_CASES += \
-# complextest
+MULTI_CPP_TEST_CASES += \
+ python_runtime_data \
include $(srcdir)/../common.mk
# Overridden variables here
-SCRIPTDIR = .
LIBS = -L.
VALGRIND_OPT += --suppressions=pythonswig.supp
# Custom tests - tests with additional commandline options
-# none!
+python_flatstaticmethod.cpptest: SWIGOPT += -flatstaticmethod
+
+# Make sure just python_runtime_data_builtin.i uses the -builtin option. Note: does not use python_runtime_data.list for all steps.
+python_runtime_data.multicpptest: override SWIG_FEATURES := $(filter-out -builtin,$(SWIG_FEATURES))
+python_runtime_data.multicpptest: override SWIGOPT := $(filter-out -builtin,$(SWIGOPT))
+python_runtime_data.multicpptest: swig_and_compile_multi_cpp = \
+ $(call swig_and_compile_cpp_helper,python_runtime_data_builtin,'$(SWIGOPT) -builtin') && \
+ $(call swig_and_compile_cpp_helper,python_runtime_data_nobuiltin,'$(SWIGOPT)')
# Rules for the different types of tests
%.cpptest:
- +$(convert_testcase)
$(setup)
+$(swig_and_compile_cpp)
$(check_pep8)
$(run_testcase)
%.ctest:
- +$(convert_testcase)
$(setup)
+$(swig_and_compile_c)
$(check_pep8)
$(run_testcase)
%.multicpptest:
- +$(convert_testcase)
$(setup)
+$(swig_and_compile_multi_cpp)
$(check_pep8_multi_cpp)
$(run_testcase)
-
-# Runs the testcase. A testcase is only run if
-# a file is found which has _runme.py (or _runme3.py for Python 3) appended after the testcase name.
-
-py_runme = $(SCRIPTPREFIX)$*$(SCRIPTSUFFIX)
-py2_runme = $(SCRIPTPREFIX)$*$(PY2SCRIPTSUFFIX)
-py3_runme = $(SCRIPTPREFIX)$*$(PY3SCRIPTSUFFIX)
-
+# Python code style checking
ifneq (,$(PYCODESTYLE))
check_pep8 = $(COMPILETOOL) $(PYCODESTYLE) $(PYCODESTYLE_FLAGS) $(SCRIPTPREFIX)$*.py
@@ -154,77 +160,24 @@ check_pep8_multi_cpp = \
done
endif
-run_python = env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH PYTHONPATH=.:$(srcdir):$$PYTHONPATH $(RUNTOOL) $(PYTHON) $(py_runme)
-
+# Runs the testcase. A testcase is only run if
+# a file is found which has _runme.py appended after the testcase name.
run_testcase = \
- if [ -f $(SCRIPTDIR)/$(py_runme) ]; then \
- $(run_python);\
+ if [ -f $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \
+ env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH PYTHONPATH=.:$(srcdir):$$PYTHONPATH $(RUNTOOL) $(PYTHON) $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); \
fi
-# Grab runme file ready for running: copied for out of source tree builds, and/or run 2to3
-# Note terminal (double colon) rules creating runme files to fix possible infinite recursion,
-# see https://github.com/swig/swig/pull/688
-ifeq ($(SCRIPTDIR),$(srcdir))
- # in source tree build
- ifeq (,$(PY3))
- convert_testcase =
- else
- convert_testcase = \
- if [ -f $(srcdir)/$(py2_runme) ]; then \
- $(MAKE) $(SCRIPTDIR)/$(py_runme); \
- fi
-
-# For converting python 2 tests into Python 3 tests
-$(SCRIPTDIR)/$(SCRIPTPREFIX)%$(SCRIPTSUFFIX):: $(srcdir)/$(SCRIPTPREFIX)%$(PY2SCRIPTSUFFIX)
- cp $< $@
- $(PY2TO3) -w $@ >/dev/null 2>&1
-
- endif
-else
- # out of source tree build
- ifeq (,$(PY3))
- convert_testcase = \
- if [ -f $(srcdir)/$(py2_runme) ]; then \
- $(MAKE) $(SCRIPTDIR)/$(py_runme); \
- fi
-
-$(SCRIPTDIR)/$(SCRIPTPREFIX)%$(SCRIPTSUFFIX):: $(srcdir)/$(SCRIPTPREFIX)%$(PY2SCRIPTSUFFIX)
- cp $< $@
-
- else
- convert_testcase = \
- if [ -f $(srcdir)/$(py2_runme) ]; then \
- $(MAKE) $(SCRIPTDIR)/$(py_runme); \
- elif [ -f $(srcdir)/$(py3_runme) ]; then \
- $(MAKE) $(SCRIPTDIR)/$(py3_runme); \
- fi
-
-# For when there is a _runme3.py instead of a _runme.py, ie a Python 3 only run test
-$(SCRIPTDIR)/$(SCRIPTPREFIX)%$(SCRIPTSUFFIX):: $(srcdir)/$(SCRIPTPREFIX)%$(PY3SCRIPTSUFFIX)
- cp $< $@
-
-# For converting python 2 tests into Python 3 tests
-$(SCRIPTDIR)/$(SCRIPTPREFIX)%$(SCRIPTSUFFIX):: $(srcdir)/$(SCRIPTPREFIX)%$(PY2SCRIPTSUFFIX)
- cp $< $@
- $(PY2TO3) -w $@ >/dev/null 2>&1
-
- endif
-
-endif
-
# Clean: remove the generated .py file
-# We only remove the _runme3.py if it is generated by 2to3 from a _runme.py.
%.clean:
@rm -f $*.py
- @if test -f $(srcdir)/$(py2_runme); then rm -f $(SCRIPTDIR)/$(py3_runme) $(SCRIPTDIR)/$(py3_runme).bak; fi
- @if test "x$(SCRIPTDIR)" != "x$(srcdir)"; then rm -f $(SCRIPTDIR)/$(py_runme); fi
clean:
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' python_clean
- rm -f hugemod.h hugemod_a.i hugemod_b.i hugemod_a.py hugemod_b.py hugemod_runme.py
rm -f clientdata_prop_a.py clientdata_prop_b.py import_stl_a.py import_stl_b.py
+ rm -f hugemod.h hugemod_a.i hugemod_b.i hugemod_a.py hugemod_b.py hugemod_runme.py
rm -f imports_a.py imports_b.py mod_a.py mod_b.py multi_import_a.py
- rm -f multi_import_b.py packageoption_a.py packageoption_b.py packageoption_c.py
+ rm -f multi_import_b.py multi_import_d.py packageoption_a.py packageoption_b.py packageoption_c.py
+ rm -f template_typedef_cplx2.py python_runtime_data_builtin.py python_runtime_data_nobuiltin.py
hugemod_runme = hugemod$(SCRIPTPREFIX)
diff --git a/Examples/test-suite/python/README b/Examples/test-suite/python/README
index 71db759b5..402724c23 100644
--- a/Examples/test-suite/python/README
+++ b/Examples/test-suite/python/README
@@ -1,8 +1,9 @@
See ../README for common README file.
-Any testcases which have _runme.py (or _runme3.py for Python 3) appended after the testcase name will be detected and run.
+Any testcases which have _runme.py appended after the testcase name will be detected and run.
-If you intend to write a testcase for both Python 2.x and 3.x, do *not* directly put the _runme3.py in this directory. Just write Python 2.x's _runme.py testcase and it will be automatically converted to Python 3 code during test.
+The _runme.py files needs to work for both Python 2.x and 3.x.
-You can run make with PY3=y to run test case with Python 3.x, eg.
- $ make voidtest.cpptest PY3=y
+By default testcases are run with Python 3. You can run make with PY2=1 to run test case with Python 2, eg.
+
+ $ make voidtest.cpptest PY2=1
diff --git a/Examples/test-suite/python/abstract_basecast_runme.py b/Examples/test-suite/python/abstract_basecast_runme.py
new file mode 100644
index 000000000..4a3f4a9e1
--- /dev/null
+++ b/Examples/test-suite/python/abstract_basecast_runme.py
@@ -0,0 +1,15 @@
+from abstract_basecast import *
+
+def check(flag):
+ if not flag:
+ raise RuntimeError("Test failed")
+
+derived = DerivedClass()
+derived.g()
+check(isinstance(derived, BaseClass))
+check(isinstance(derived, DerivedClass))
+
+base = derived.f()
+base.g()
+check(isinstance(base, BaseClass))
+check(not isinstance(base, DerivedClass))
diff --git a/Examples/test-suite/python/argcargvtest_runme.py b/Examples/test-suite/python/argcargvtest_runme.py
index b0345746f..52d428b2d 100644
--- a/Examples/test-suite/python/argcargvtest_runme.py
+++ b/Examples/test-suite/python/argcargvtest_runme.py
@@ -6,12 +6,15 @@ if mainc(largs) != 3:
targs = ("hi", "hola")
if mainv(targs, 1) != "hola":
- print(mainv(targs, 1))
raise RuntimeError("bad main typemap")
targs = ("hi", "hola")
+if mainv(targs, 0) != "hi":
+ raise RuntimeError("bad main typemap")
if mainv(targs, 1) != "hola":
raise RuntimeError("bad main typemap")
+if mainv(targs, 2) != "<<NULL>>":
+ raise RuntimeError("bad main typemap")
try:
error = 0
@@ -24,3 +27,28 @@ if error:
initializeApp(largs)
+
+# Check that an empty array works.
+empty_args = []
+if mainc(empty_args) != 0:
+ raise RuntimeError("bad main typemap")
+if mainv(empty_args, 0) != "<<NULL>>":
+ raise RuntimeError("bad main typemap")
+empty_tuple = ()
+if mainc(empty_tuple) != 0:
+ raise RuntimeError("bad main typemap")
+if mainv(empty_tuple, 0) != "<<NULL>>":
+ raise RuntimeError("bad main typemap")
+
+# Check that empty strings are handled.
+empty_string = ["hello", "", "world"]
+if mainc(empty_string) != 3:
+ raise RuntimeError("bad main typemap")
+if mainv(empty_string, 0) != "hello":
+ raise RuntimeError("bad main typemap")
+if mainv(empty_string, 1) != "":
+ raise RuntimeError("bad main typemap")
+if mainv(empty_string, 2) != "world":
+ raise RuntimeError("bad main typemap")
+if mainv(empty_string, 3) != "<<NULL>>":
+ raise RuntimeError("bad main typemap")
diff --git a/Examples/test-suite/python/array_member_runme.py b/Examples/test-suite/python/array_member_runme.py
index de6e0f3e7..2708a6f37 100644
--- a/Examples/test-suite/python/array_member_runme.py
+++ b/Examples/test-suite/python/array_member_runme.py
@@ -5,7 +5,7 @@ f.data = cvar.global_data
for i in range(0, 8):
if get_value(f.data, i) != get_value(cvar.global_data, i):
- raise RuntimeError, "Bad array assignment"
+ raise RuntimeError("Bad array assignment")
for i in range(0, 8):
@@ -15,4 +15,4 @@ cvar.global_data = f.data
for i in range(0, 8):
if get_value(f.data, i) != get_value(cvar.global_data, i):
- raise RuntimeError, "Bad array assignment"
+ raise RuntimeError("Bad array assignment")
diff --git a/Examples/test-suite/python/autodoc_runme.py b/Examples/test-suite/python/autodoc_runme.py
index 6002d49fe..18330f76f 100644
--- a/Examples/test-suite/python/autodoc_runme.py
+++ b/Examples/test-suite/python/autodoc_runme.py
@@ -63,16 +63,8 @@ check(inspect.getdoc(A.func3default),
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"
@@ -82,24 +74,6 @@ check(inspect.getdoc(A.func2static),
"arg2: short\n"
"hello: int tuple[2]\n"
"f: double")
-check(inspect.getdoc(_autodoc.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_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"
@@ -109,24 +83,6 @@ check(inspect.getdoc(A.func3static),
"arg2: short\n"
"hello: int tuple[2]\n"
"f: double")
-check(inspect.getdoc(_autodoc.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_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"
@@ -141,7 +97,7 @@ check(inspect.getdoc(A.variable_d),
"variable_d : int"
)
-# Check the low-level functions (not present when using -builtin except for the static ones)
+# Check the low-level functions (not present when using -builtin)
if not is_python_builtin():
check(inspect.getdoc(_autodoc.A_funk), "just a string.")
check(inspect.getdoc(_autodoc.A_func0),
@@ -184,6 +140,28 @@ if not is_python_builtin():
"arg3: short\n"
"hello: int tuple[2]\n"
"f: double")
+ check(inspect.getdoc(_autodoc.A_func0static),
+ "A_func0static(e, arg2, hello, f=2) -> int")
+ check(inspect.getdoc(_autodoc.A_func1static),
+ "A_func1static(A e, short arg2, Tuple hello, double f=2) -> int")
+ check(inspect.getdoc(_autodoc.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(_autodoc.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(_autodoc.A_variable_a_set), "A_variable_a_set(self, variable_a)")
check(inspect.getdoc(_autodoc.A_variable_a_get), "A_variable_a_get(self) -> int" )
check(inspect.getdoc(_autodoc.A_variable_b_set), "A_variable_b_set(A self, int variable_b)")
@@ -279,3 +257,5 @@ check(inspect.getdoc(process3), "process3(int _from, int _in, int var) -> int")
check(inspect.getdoc(process4), "process4(int _from=0, int _in=1, int var=2) -> int")
check(inspect.getdoc(process_complex_defval), "process_complex_defval(val=PROCESS_DEFAULT_VALUE, factor=some_type(-1)) -> int")
+
+check(inspect.getdoc(a_structure.__init__), "__init__(a_structure self) -> a_structure", None, skip)
diff --git a/Examples/test-suite/python/callback_runme.py b/Examples/test-suite/python/callback_runme.py
index de8a372f6..93883e064 100644
--- a/Examples/test-suite/python/callback_runme.py
+++ b/Examples/test-suite/python/callback_runme.py
@@ -1,10 +1,13 @@
import _callback
from callback import *
+# callbacks are implemented by modifying docstrings, useful for debugging:
+# print("A.bar doc: {}".format(A.bar.__doc__))
+
if foo(2) != 2:
raise RuntimeError
-if A_bar(2) != 4:
+if A.bar(2) != 4:
raise RuntimeError
if foobar(3, _callback.foo) != foo(3):
@@ -13,11 +16,7 @@ if foobar(3, _callback.foo) != foo(3):
if foobar(3, foo) != foo(3):
raise RuntimeError
-# Needs some more work for -builtin
-# if foobar(3, A.bar) != A.bar(3):
-# raise RuntimeError
-
-if foobar(3, A_bar) != A_bar(3):
+if foobar(3, A.bar) != A.bar(3):
raise RuntimeError
if foobar(3, foof) != foof(3):
diff --git a/Examples/test-suite/python/catches_strings_runme.py b/Examples/test-suite/python/catches_strings_runme.py
new file mode 100644
index 000000000..95b55a264
--- /dev/null
+++ b/Examples/test-suite/python/catches_strings_runme.py
@@ -0,0 +1,21 @@
+from catches_strings import *
+
+exception_thrown = False
+try:
+ StringsThrower.charstring()
+except RuntimeError as e:
+ if "charstring message" not in str(e):
+ raise RuntimeError("incorrect exception message:" + str(e))
+ exception_thrown = True
+if not exception_thrown:
+ raise RuntimeError("Should have thrown an exception")
+
+exception_thrown = False
+try:
+ StringsThrower.stdstring()
+except RuntimeError as e:
+ if "stdstring message" not in str(e):
+ raise RuntimeError("incorrect exception message:" + str(e))
+ exception_thrown = True
+if not exception_thrown:
+ raise RuntimeError("Should have thrown an exception")
diff --git a/Examples/test-suite/python/ccomplextest_runme.py b/Examples/test-suite/python/ccomplextest_runme.py
new file mode 100644
index 000000000..63a663f50
--- /dev/null
+++ b/Examples/test-suite/python/ccomplextest_runme.py
@@ -0,0 +1,22 @@
+import ccomplextest
+
+a = complex(-1, 2)
+
+if ccomplextest.has_c99_complex():
+ if ccomplextest.Conj(a) != a.conjugate():
+ raise RuntimeError("bad complex mapping")
+
+ if ccomplextest.Conjf(a) != a.conjugate():
+ raise RuntimeError("bad complex mapping")
+
+ if ccomplextest.Conj2(a) != a.conjugate():
+ raise RuntimeError("bad complex mapping")
+
+ if ccomplextest.Conjf2(a) != a.conjugate():
+ raise RuntimeError("bad complex mapping")
+
+ if ccomplextest.Conj3(a) != a.conjugate():
+ raise RuntimeError("bad complex mapping")
+
+ if ccomplextest.Conjf3(a) != a.conjugate():
+ raise RuntimeError("bad complex mapping")
diff --git a/Examples/test-suite/python/char_binary_runme.py b/Examples/test-suite/python/char_binary_runme.py
index 0425fe1c9..0f1629f32 100644
--- a/Examples/test-suite/python/char_binary_runme.py
+++ b/Examples/test-suite/python/char_binary_runme.py
@@ -2,16 +2,14 @@ from char_binary import *
t = Test()
if t.strlen("hile") != 4:
- print t.strlen("hile")
- raise RuntimeError, "bad multi-arg typemap"
+ raise RuntimeError("bad multi-arg typemap {}".format(t.strlen("hile")))
if t.ustrlen("hile") != 4:
- print t.ustrlen("hile")
- raise RuntimeError, "bad multi-arg typemap"
+ raise RuntimeError("bad multi-arg typemap {}".format(t.ustrlen("hile")))
if t.strlen("hil\0") != 4:
- raise RuntimeError, "bad multi-arg typemap"
+ raise RuntimeError("bad multi-arg typemap")
if t.ustrlen("hil\0") != 4:
- raise RuntimeError, "bad multi-arg typemap"
+ raise RuntimeError("bad multi-arg typemap")
#
# creating a raw char*
@@ -25,18 +23,16 @@ pchar_setitem(pc, 4, 0)
if t.strlen(pc) != 4:
- raise RuntimeError, "bad multi-arg typemap"
+ raise RuntimeError("bad multi-arg typemap")
if t.ustrlen(pc) != 4:
- raise RuntimeError, "bad multi-arg typemap"
+ raise RuntimeError("bad multi-arg typemap")
cvar.var_pchar = pc
if cvar.var_pchar != "hola":
- print cvar.var_pchar
- raise RuntimeError, "bad pointer case"
+ raise RuntimeError("bad pointer case {}".format(cvar.var_pchar))
cvar.var_namet = pc
-# if cvar.var_namet != "hola\0":
if cvar.var_namet != "hola":
- raise RuntimeError, "bad pointer case"
+ raise RuntimeError("bad pointer case")
delete_pchar(pc)
diff --git a/Examples/test-suite/python/complextest_runme.py b/Examples/test-suite/python/complextest_runme.py
index 5cfc7ccab..1b9ad6629 100644
--- a/Examples/test-suite/python/complextest_runme.py
+++ b/Examples/test-suite/python/complextest_runme.py
@@ -3,17 +3,16 @@ import complextest
a = complex(-1, 2)
if complextest.Conj(a) != a.conjugate():
- raise RuntimeError, "bad complex mapping"
+ raise RuntimeError("bad complex mapping")
if complextest.Conjf(a) != a.conjugate():
- raise RuntimeError, "bad complex mapping"
+ raise RuntimeError("bad complex mapping")
if complextest.Conj2(a) != a.conjugate():
- raise RuntimeError, "bad complex mapping"
+ raise RuntimeError("bad complex mapping")
if complextest.Conjf2(a) != a.conjugate():
- raise RuntimeError, "bad complex mapping"
-
+ raise RuntimeError("bad complex mapping")
v = (complex(1, 2), complex(2, 3), complex(4, 3), 1)
@@ -27,4 +26,4 @@ p = complextest.ComplexPair()
p.z1 = complex(0, 1)
p.z2 = complex(0, -1)
if complextest.Conj(p.z2) != p.z1:
- raise RuntimeError, "bad complex mapping"
+ raise RuntimeError("bad complex mapping")
diff --git a/Examples/test-suite/python/constover_runme.py b/Examples/test-suite/python/constover_runme.py
index 2d28a55cc..0c03967f6 100644
--- a/Examples/test-suite/python/constover_runme.py
+++ b/Examples/test-suite/python/constover_runme.py
@@ -4,33 +4,26 @@ error = 0
p = constover.test("test")
if p != "test":
- print "test failed!"
- error = 1
+ raise RuntimeError("test failed!")
p = constover.test_pconst("test")
if p != "test_pconst":
- print "test_pconst failed!"
- error = 1
+ raise RuntimeError("test_pconst failed!")
f = constover.Foo()
p = f.test("test")
if p != "test":
- print "member-test failed!"
- error = 1
+ raise RuntimeError("member-test failed!")
p = f.test_pconst("test")
if p != "test_pconst":
- print "member-test_pconst failed!"
- error = 1
+ raise RuntimeError("member-test_pconst failed!")
p = f.test_constm("test")
if p != "test_constmethod":
- print "member-test_constm failed!"
- error = 1
+ raise RuntimeError("member-test_constm failed!")
p = f.test_pconstm("test")
if p != "test_pconstmethod":
- print "member-test_pconstm failed!"
- error = 1
+ raise RuntimeError("member-test_pconstm failed!")
-sys.exit(error)
diff --git a/Examples/test-suite/python/constructor_copy_non_const_runme.py b/Examples/test-suite/python/constructor_copy_non_const_runme.py
new file mode 100644
index 000000000..7a29d8973
--- /dev/null
+++ b/Examples/test-suite/python/constructor_copy_non_const_runme.py
@@ -0,0 +1,13 @@
+from constructor_copy_non_const import *
+
+ccb2 = CCBase2(CCBase2())
+ccd = CCDerived(CCDerived())
+ccmd = CCMoreDerived(CCMoreDerived())
+ccmd2 = CCMoreDerived2(CCMoreDerived2())
+ccmmd2 = CCMoreMoreDerived2(CCMoreMoreDerived2())
+
+# no copy ctor CCProtectedBase2
+ccd = CCProtectedDerived(CCProtectedDerived())
+ccmd = CCProtectedMoreDerived(CCProtectedMoreDerived())
+ccmd2 = CCProtectedMoreDerived2(CCProtectedMoreDerived2())
+ccmmd2 = CCProtectedMoreMoreDerived2(CCProtectedMoreMoreDerived2())
diff --git a/Examples/test-suite/python/contract_runme.py b/Examples/test-suite/python/contract_runme.py
index cd75a51d2..3194b6ac7 100644
--- a/Examples/test-suite/python/contract_runme.py
+++ b/Examples/test-suite/python/contract_runme.py
@@ -2,141 +2,141 @@ import contract
contract.test_preassert(1, 2)
try:
- contract.test_preassert(-1)
- print "Failed! Preassertions are broken"
-except:
+ contract.test_preassert(-1, 3)
+ raise Exception("Failed! Preassertions are broken")
+except RuntimeError:
pass
contract.test_postassert(3)
try:
contract.test_postassert(-3)
- print "Failed! Postassertions are broken"
-except:
+ raise Exception("Failed! Postassertions are broken")
+except RuntimeError:
pass
contract.test_prepost(2, 3)
contract.test_prepost(5, -4)
try:
contract.test_prepost(-3, 4)
- print "Failed! Preassertions are broken"
-except:
+ raise Exception("Failed! Preassertions are broken")
+except RuntimeError:
pass
try:
contract.test_prepost(4, -10)
- print "Failed! Postassertions are broken"
+ raise Exception("Failed! Postassertions are broken")
-except:
+except RuntimeError:
pass
f = contract.Foo()
f.test_preassert(4, 5)
try:
f.test_preassert(-2, 3)
- print "Failed! Method preassertion."
-except:
+ raise Exception("Failed! Method preassertion.")
+except RuntimeError:
pass
f.test_postassert(4)
try:
f.test_postassert(-4)
- print "Failed! Method postassertion"
-except:
+ raise Exception("Failed! Method postassertion")
+except RuntimeError:
pass
f.test_prepost(3, 4)
f.test_prepost(4, -3)
try:
f.test_prepost(-4, 2)
- print "Failed! Method preassertion."
-except:
+ raise Exception("Failed! Method preassertion.")
+except RuntimeError:
pass
try:
f.test_prepost(4, -10)
- print "Failed! Method postassertion."
-except:
+ raise Exception("Failed! Method postassertion.")
+except RuntimeError:
pass
-contract.Foo_stest_prepost(4, 0)
+contract.Foo.stest_prepost(4, 0)
try:
- contract.Foo_stest_prepost(-4, 2)
- print "Failed! Static method preassertion"
-except:
+ contract.Foo.stest_prepost(-4, 2)
+ raise Exception("Failed! Static method preassertion")
+except RuntimeError:
pass
try:
- contract.Foo_stest_prepost(4, -10)
- print "Failed! Static method posteassertion"
-except:
+ contract.Foo.stest_prepost(4, -10)
+ raise Exception("Failed! Static method posteassertion")
+except RuntimeError:
pass
b = contract.Bar()
try:
b.test_prepost(2, -4)
- print "Failed! Inherited preassertion."
-except:
+ raise Exception("Failed! Inherited preassertion.")
+except RuntimeError:
pass
d = contract.D()
try:
d.foo(-1, 1, 1, 1, 1)
- print "Failed! Inherited preassertion (D)."
-except:
+ raise Exception("Failed! Inherited preassertion (D).")
+except RuntimeError:
pass
try:
d.foo(1, -1, 1, 1, 1)
- print "Failed! Inherited preassertion (D)."
-except:
+ raise Exception("Failed! Inherited preassertion (D).")
+except RuntimeError:
pass
try:
d.foo(1, 1, -1, 1, 1)
- print "Failed! Inherited preassertion (D)."
-except:
+ raise Exception("Failed! Inherited preassertion (D).")
+except RuntimeError:
pass
try:
d.foo(1, 1, 1, -1, 1)
- print "Failed! Inherited preassertion (D)."
-except:
+ raise Exception("Failed! Inherited preassertion (D).")
+except RuntimeError:
pass
try:
d.foo(1, 1, 1, 1, -1)
- print "Failed! Inherited preassertion (D)."
-except:
+ raise Exception("Failed! Inherited preassertion (D).")
+except RuntimeError:
pass
try:
d.bar(-1, 1, 1, 1, 1)
- print "Failed! Inherited preassertion (D)."
-except:
+ raise Exception("Failed! Inherited preassertion (D).")
+except RuntimeError:
pass
try:
d.bar(1, -1, 1, 1, 1)
- print "Failed! Inherited preassertion (D)."
-except:
+ raise Exception("Failed! Inherited preassertion (D).")
+except RuntimeError:
pass
try:
d.bar(1, 1, -1, 1, 1)
- print "Failed! Inherited preassertion (D)."
-except:
+ raise Exception("Failed! Inherited preassertion (D).")
+except RuntimeError:
pass
try:
d.bar(1, 1, 1, -1, 1)
- print "Failed! Inherited preassertion (D)."
-except:
+ raise Exception("Failed! Inherited preassertion (D).")
+except RuntimeError:
pass
try:
d.bar(1, 1, 1, 1, -1)
- print "Failed! Inherited preassertion (D)."
-except:
+ raise Exception("Failed! Inherited preassertion (D).")
+except RuntimeError:
pass
# Namespace
my = contract.myClass(1)
try:
my = contract.myClass(0)
- print "Failed! constructor preassertion"
-except:
+ raise Exception("Failed! constructor preassertion")
+except RuntimeError:
pass
diff --git a/Examples/test-suite/python/copyctor_runme.py b/Examples/test-suite/python/copyctor_runme.py
new file mode 100644
index 000000000..3a16fc2b4
--- /dev/null
+++ b/Examples/test-suite/python/copyctor_runme.py
@@ -0,0 +1,13 @@
+from copyctor import *
+
+bar = Bar()
+bar = Bar(bar)
+
+foo = Foo()
+foo = Foo(bar)
+
+car = Car()
+
+hoo = Hoo()
+hoo = Hoo(bar)
+hoo = Hoo(car)
diff --git a/Examples/test-suite/python/cpp11_alternate_function_syntax_runme.py b/Examples/test-suite/python/cpp11_alternate_function_syntax_runme.py
index cc7b5cd91..e46a4772f 100644
--- a/Examples/test-suite/python/cpp11_alternate_function_syntax_runme.py
+++ b/Examples/test-suite/python/cpp11_alternate_function_syntax_runme.py
@@ -4,20 +4,20 @@ a = cpp11_alternate_function_syntax.SomeStruct()
res = a.addNormal(4, 5)
if res != 9:
- raise RuntimeError, ("SomeStruct::addNormal(4,5) returns ", res, " should be 9.")
+ raise RuntimeError("SomeStruct::addNormal(4,5) returns ", res, " should be 9.")
res = a.addAlternate(4, 5)
if res != 9:
- raise RuntimeError, ("SomeStruct::addAlternate(4,5) returns ", res, " should be 9.")
+ raise RuntimeError("SomeStruct::addAlternate(4,5) returns ", res, " should be 9.")
res = a.addAlternateConst(4, 5)
if res != 9:
- raise RuntimeError, ("SomeStruct::addAlternateConst(4,5) returns ", res, " should be 9.")
+ raise RuntimeError("SomeStruct::addAlternateConst(4,5) returns ", res, " should be 9.")
res = a.addAlternateNoExcept(4, 5)
if res != 9:
- raise RuntimeError, ("SomeStruct::addAlternateNoExcept(4,5) returns ", res, " should be 9.")
+ raise RuntimeError("SomeStruct::addAlternateNoExcept(4,5) returns ", res, " should be 9.")
res = a.addAlternateConstNoExcept(4, 5)
if res != 9:
- raise RuntimeError, ("SomeStruct::addAlternateConstNoExcept(4,5) returns ", res, " should be 9.")
+ raise RuntimeError("SomeStruct::addAlternateConstNoExcept(4,5) returns ", res, " should be 9.")
diff --git a/Examples/test-suite/python/cpp11_decltype_runme.py b/Examples/test-suite/python/cpp11_decltype_runme.py
index 1650d9004..b5792d148 100644
--- a/Examples/test-suite/python/cpp11_decltype_runme.py
+++ b/Examples/test-suite/python/cpp11_decltype_runme.py
@@ -3,16 +3,30 @@ import cpp11_decltype
a = cpp11_decltype.A()
a.i = 5
if a.i != 5:
- raise RuntimeError, "Assignment to a.i failed."
+ raise RuntimeError("Assignment to a.i failed.")
a.j = 10
if a.j != 10:
- raise RuntimeError, "Assignment to a.j failed."
+ raise RuntimeError("Assignment to a.j failed.")
-b = a.foo(5)
-if b != 10:
- raise RuntimeError, "foo(5) should return 10."
+n = a.get_number(5)
+if n != 10:
+ raise RuntimeError("get_number(5) should return 10.")
-b = a.foo(6)
-if b != 0:
- raise RuntimeError, "foo(6) should return 0."
+n = a.get_number(6)
+if n != 0:
+ raise RuntimeError("get_number(6) should return 0.")
+
+b = cpp11_decltype.B()
+
+if b.a != False:
+ raise RuntimeError("b.a should be False")
+
+if b.b != True:
+ raise RuntimeError("b.b should be True")
+
+if b.negate(True) != False:
+ raise RuntimeError("b.negate(True) should return False")
+
+if b.negate(False) != True:
+ raise RuntimeError("b.negate(False) should return True")
diff --git a/Examples/test-suite/python/cpp11_director_using_constructor_runme.py b/Examples/test-suite/python/cpp11_director_using_constructor_runme.py
new file mode 100644
index 000000000..84238a281
--- /dev/null
+++ b/Examples/test-suite/python/cpp11_director_using_constructor_runme.py
@@ -0,0 +1,145 @@
+from cpp11_director_using_constructor import *
+
+
+# Public base constructors
+a = PublicDerived1(0, "hi").meth()
+a = PublicDerived2().meth()
+a = PublicDerived2(0, "hi").meth()
+a = PublicDerived3().meth()
+a = PublicDerived3(0, "hi").meth()
+a = PublicDerived4().meth()
+a = PublicDerived5().meth()
+
+# Protected base constructors
+# Cannot test most of these as the constructors are protected
+ProtectedDerived5()
+
+# Mix of public and overloaded constructors
+MixedDerived1a(0, "hi").meth()
+MixedDerived1a().meth()
+MixedDerived1b(0, "hi").meth()
+MixedDerived1b().meth()
+
+MixedDerived2a(0, "hi").meth()
+MixedDerived2a().meth()
+MixedDerived2b(0, "hi").meth()
+MixedDerived2b().meth()
+
+MixedDerived2c(0, "hi").meth()
+MixedDerived2c().meth()
+MixedDerived2c(0).meth()
+
+MixedDerived2d(0, "hi").meth()
+MixedDerived2d().meth()
+MixedDerived2d(0).meth()
+
+MixedDerived3a(0, "hi").meth()
+MixedDerived3a().meth()
+MixedDerived3b(0, "hi").meth()
+MixedDerived3b().meth()
+
+MixedDerived3c(0, "hi").meth()
+MixedDerived3c().meth()
+MixedDerived3c(0).meth()
+
+MixedDerived3d(0, "hi").meth()
+MixedDerived3d().meth()
+MixedDerived3d(0).meth()
+
+MixedDerived4a(0, "hi").meth()
+MixedDerived4a().meth()
+MixedDerived4b(0, "hi").meth()
+MixedDerived4b().meth()
+
+MixedDerived4c().meth()
+MixedDerived4c(0).meth()
+
+MixedDerived4d().meth()
+MixedDerived4d(0).meth()
+
+MixedDerived4e().meth()
+
+MixedDerived4f().meth()
+
+# Mix of protected base constructors and overloading
+ProotDerived1a().meth()
+
+ProotDerived1b(0, "hi").meth()
+ProotDerived1b().meth()
+
+ProotDerived1c(0, "hi").meth()
+ProotDerived1c().meth()
+
+ProotDerived1d(0).meth()
+ProotDerived1d().meth()
+
+ProotDerived1e(0).meth()
+ProotDerived1e().meth()
+
+ProotDerived2a(0, "hi").meth()
+
+ProotDerived2b(0, "hi").meth()
+
+ProotDerived2c(0, "hi").meth()
+ProotDerived2c().meth()
+
+ProotDerived2d(0, "hi").meth()
+ProotDerived2d().meth()
+
+ProotDerived2e(0, "hi").meth()
+ProotDerived2e().meth()
+
+ProotDerived2f(0, "hi").meth()
+ProotDerived2f().meth()
+ProotDerived2f(0).meth()
+
+# Deeper inheritance chain
+db3 = DeepBase3(11)
+db3 = DeepBase3(11, 22)
+db3 = DeepBase3(11, 22, 33)
+dbp3 = DeepProtectedBase3(11, 22, 33)
+
+# Missing base
+HiddenDerived1()
+
+# Templates and public base constructors (derive from non-template)
+TemplatePublicDerived1Int(0, "hi").meth()
+TemplatePublicDerived2Int().meth()
+TemplatePublicDerived2Int(0, "hi").meth()
+TemplatePublicDerived3Int().meth()
+TemplatePublicDerived3Int(0, "hi").meth()
+TemplatePublicDerived4Int().meth()
+TemplatePublicDerived5Int().meth()
+
+# Templates and public base constructors (derive from template)
+TemplPublicDerived1Int(0, "hi").meth()
+TemplPublicDerived2Int().meth()
+TemplPublicDerived2Int(0, "hi").meth()
+TemplPublicDerived3Int().meth()
+TemplPublicDerived3Int(0, "hi").meth()
+TemplPublicDerived4Int().meth()
+TemplPublicDerived5Int().meth()
+TemplPublicDerived6Int(0, "hi").meth()
+TemplPublicDerived6Int().meth()
+
+# Templated constructors (public)
+tcb = TemplateConstructor1Base(0, "hi")
+tcb = TemplateConstructor1Base("hi", "hi")
+tcb = TemplateConstructor1Base(11.1, "hi")
+tcb.normal_method()
+tcb.template_method(0, "hi")
+tcb.template_method("hey", "ho")
+
+tcd1 = TemplateConstructor1Derived(0, "hi")
+tcd1 = TemplateConstructor1Derived("hi", "hi")
+tcd1 = TemplateConstructor1Derived(11.1, "hi")
+# Not the best test as these are also in the base class, (should use introspection to check)
+tcd1.normal_method()
+tcd1.template_method(0, "hi")
+tcd1.template_method("hey", "ho")
+
+# Templated constructors (protected)
+tcd2 = TemplateConstructor2Derived()
+tcd2.normal_method()
+tcd2.template_method(0, "hi")
+tcd2.template_method("hey", "ho")
diff --git a/Examples/test-suite/python/cpp11_final_class_runme.py b/Examples/test-suite/python/cpp11_final_class_runme.py
new file mode 100644
index 000000000..54e289043
--- /dev/null
+++ b/Examples/test-suite/python/cpp11_final_class_runme.py
@@ -0,0 +1,65 @@
+from cpp11_final_class import *
+
+fc1 = FinalClass1()
+fc1.method1()
+
+fc2 = FinalClass2()
+fc2.method2()
+
+fc3 = FinalClass3()
+fc3.method3()
+
+fc4 = FinalClass4()
+fc4.method4()
+fc4final = cvar.final
+cvar.final.method4()
+
+fc5 = FinalClass5()
+fc5.method5()
+fc5.final_member_var.finalmethod()
+fc5final = fc5.get_final_member()
+fc5final.finalmethod()
+fc5final = fc5.get_final_member2()
+fc5final.finalmethod()
+
+fc6 = FinalClass6()
+fc6.method6()
+fc6.final()
+
+o = override()
+o.omethod();
+
+y = Y()
+fv4 = FinalVar4()
+yy = fv4.final
+
+fv5 = FinalVar5()
+yy = fv5.final
+
+fv6 = FinalVar6()
+yy = fv6.final
+
+fv7 = FinalVar7()
+yy = fv7.final
+
+fv8 = FinalVar8()
+yy = fv8.final
+
+fv9 = FinalVar9()
+yy = fv9.final
+
+fv10 = FinalVar10()
+fv10.b10(y)
+
+# Removed due to Visual C++ compiler limitations
+# fv11 = FinalVar11()
+# fv11.a11(y)
+#
+# fe1 = FinalEnum1()
+# fe1.enum_in(FinalEnum1.final)
+#
+# fe2 = FinalEnum2()
+# fe2f = fe2.final
+
+s3f = Space3_final()
+s3f.fmethod();
diff --git a/Examples/test-suite/python/cpp11_hash_tables_runme.py b/Examples/test-suite/python/cpp11_hash_tables_runme.py
index 7b772ff9a..3e7be49d0 100644
--- a/Examples/test-suite/python/cpp11_hash_tables_runme.py
+++ b/Examples/test-suite/python/cpp11_hash_tables_runme.py
@@ -10,14 +10,14 @@ for x in [cpp11_hash_tables.MapIntInt({1:7}),
cpp11_hash_tables.UnorderedMultiMapIntInt({1:7})
]:
- swig_assert_equal([(k, v) for k, v in x.iteritems()], [(1, 7)])
- swig_assert_equal(x.keys(), [1])
- swig_assert_equal(x.values(), [7])
- swig_assert_equal(x.items(), [(1, 7)])
+ swig_assert_equal([(k, v) for k, v in x.items()], [(1, 7)])
+ swig_assert_equal(list(x.keys()), [1])
+ swig_assert_equal(list(x.values()), [7])
+ swig_assert_equal(list(x.items()), [(1, 7)])
swig_assert_equal([k for k in x], [1])
- swig_assert_equal([i for i in x.iterkeys()], [1])
- swig_assert_equal([i for i in x.itervalues()], [7])
- swig_assert_equal([i for i in x.iteritems()], [(1, 7)])
+ swig_assert_equal([i for i in x.keys()], [1])
+ swig_assert_equal([i for i in x.values()], [7])
+ swig_assert_equal([i for i in x.items()], [(1, 7)])
swig_assert_equal(x[1], 7)
swig_assert_equal(2 in x, False)
@@ -33,7 +33,7 @@ for x in [cpp11_hash_tables.MapIntInt({1:7}),
for x in [cpp11_hash_tables.MultiMapIntInt({1:7}),
cpp11_hash_tables.UnorderedMultiMapIntInt({1:7})]:
x[1] = 9
- swig_assert_equal(sorted([v for k, v in x.iteritems()]), [7, 9])
+ swig_assert_equal(sorted([v for k, v in x.items()]), [7, 9])
swig_assert_equal(len(x), 2)
for x in [cpp11_hash_tables.SetInt([1]),
diff --git a/Examples/test-suite/python/cpp11_inheriting_constructors_runme.py b/Examples/test-suite/python/cpp11_inheriting_constructors_runme.py
new file mode 100644
index 000000000..28fb52dbb
--- /dev/null
+++ b/Examples/test-suite/python/cpp11_inheriting_constructors_runme.py
@@ -0,0 +1,11 @@
+from cpp11_inheriting_constructors import *
+
+# Constructor inheritance via using declaration
+d = DerivedClass(10)
+if d.retrieveValue() != 10:
+ raise RuntimeError("retrieveValue() failed");
+
+# Member initialization at the site of the declaration
+s = SomeClass()
+if s.value != 5:
+ raise RuntimeError("s.value failed");
diff --git a/Examples/test-suite/python/cpp11_move_only_runme.py b/Examples/test-suite/python/cpp11_move_only_runme.py
new file mode 100644
index 000000000..9727f3fcc
--- /dev/null
+++ b/Examples/test-suite/python/cpp11_move_only_runme.py
@@ -0,0 +1,27 @@
+from cpp11_move_only import *
+
+# Output
+Counter.reset_counts()
+mo = MoveOnly.create()
+del mo
+Counter.check_counts(1, 0, 0, 2, 0, 3)
+
+Counter.reset_counts()
+mo = MovableCopyable.create()
+del mo
+Counter.check_counts(2, 1, 0, 0, 1, 3)
+
+# Move semantics not used
+Counter.reset_counts()
+mo = MovableCopyable.createConst()
+del mo
+Counter.check_counts(2, 1, 1, 0, 0, 3)
+
+# Input
+Counter.reset_counts()
+mo = MovableCopyable(222)
+Counter.check_counts(1, 0, 0, 0, 0, 0)
+MovableCopyable.take(mo)
+Counter.check_counts(2, 0, 1, 1, 0, 2)
+del mo
+Counter.check_counts(2, 0, 1, 1, 0, 3)
diff --git a/Examples/test-suite/python/cpp11_move_typemaps_runme.py b/Examples/test-suite/python/cpp11_move_typemaps_runme.py
new file mode 100644
index 000000000..e4cf06c53
--- /dev/null
+++ b/Examples/test-suite/python/cpp11_move_typemaps_runme.py
@@ -0,0 +1,29 @@
+from cpp11_move_typemaps import *
+
+Counter.reset_counts()
+mo = MoveOnly(111)
+Counter.check_counts(1, 0, 0, 0, 0, 0)
+MoveOnly.take(mo)
+Counter.check_counts(1, 0, 0, 1, 0, 2)
+del mo
+Counter.check_counts(1, 0, 0, 1, 0, 2)
+
+Counter.reset_counts()
+mo = MovableCopyable(111)
+Counter.check_counts(1, 0, 0, 0, 0, 0)
+MovableCopyable.take(mo)
+Counter.check_counts(1, 0, 0, 1, 0, 2)
+del mo
+Counter.check_counts(1, 0, 0, 1, 0, 2)
+
+mo = MoveOnly(222)
+MoveOnly.take(mo)
+exception_thrown = False
+try:
+ MoveOnly.take(mo)
+except RuntimeError as e:
+ if "cannot release ownership as memory is not owned" not in str(e):
+ raise RuntimeError("incorrect exception message:" + str(e))
+ exception_thrown = True
+if not exception_thrown:
+ raise RuntimeError("Should have thrown 'Cannot release ownership as memory is not owned' error")
diff --git a/Examples/test-suite/python/cpp11_null_pointer_constant_runme.py b/Examples/test-suite/python/cpp11_null_pointer_constant_runme.py
index 54a8fe0eb..c39760344 100644
--- a/Examples/test-suite/python/cpp11_null_pointer_constant_runme.py
+++ b/Examples/test-suite/python/cpp11_null_pointer_constant_runme.py
@@ -3,15 +3,15 @@ import cpp11_null_pointer_constant
a = cpp11_null_pointer_constant.A()
if a._myA != None:
- raise RuntimeError, (
+ raise RuntimeError(
"cpp11_null_pointer_constant: _myA should be None, but is ", a._myA)
b = cpp11_null_pointer_constant.A()
if a._myA != b._myA:
- raise RuntimeError, (
+ raise RuntimeError(
"cpp11_null_pointer_constant: a._myA should be the same as b._myA, but ", a._myA, "!=", b._myA)
a._myA = cpp11_null_pointer_constant.A()
if a._myA == None:
- raise RuntimeError, (
- "cpp11_null_pointer_constant: _myA should be object, but is None")
+ raise RuntimeError((
+ "cpp11_null_pointer_constant: _myA should be object, but is None"))
diff --git a/Examples/test-suite/python/cpp11_raw_string_literals_runme.py b/Examples/test-suite/python/cpp11_raw_string_literals_runme.py
index 6a587b860..196bd4ec4 100644
--- a/Examples/test-suite/python/cpp11_raw_string_literals_runme.py
+++ b/Examples/test-suite/python/cpp11_raw_string_literals_runme.py
@@ -34,19 +34,19 @@ if cvar.aa != "Wide string":
raise RuntimeError
if cvar.bb != "UTF-8 string":
- raise RuntimeError, cvar.wide
+ raise RuntimeError(cvar.wide)
if cvar.xx != ")I'm an \"ascii\" \\ string.":
- raise RuntimeError, cvar.xx
+ raise RuntimeError(cvar.xx)
if cvar.ee != ")I'm an \"ascii\" \\ string.":
- raise RuntimeError, cvar.ee
+ raise RuntimeError(cvar.ee)
if cvar.ff != "I'm a \"raw wide\" \\ string.":
- raise RuntimeError, cvar.ff
+ raise RuntimeError(cvar.ff)
if cvar.gg != "I'm a \"raw UTF-8\" \\ string.":
- raise RuntimeError, cvar.gg
+ raise RuntimeError(cvar.gg)
def check(got, expected):
@@ -65,11 +65,11 @@ documentation
comment""")
check(inspect.getdoc(RawStringDoc.YY), """Single line "raw string" documentation comment""")
check(inspect.getdoc(RawStringDoc.ZZ),
-"""Documentation comment
+r"""Documentation comment
as a "raw string"
on multiple lines including a \ backslash""")
-check(mm, """)I'm an "ascii" \ string constant with multiple
+check(mm, r""")I'm an "ascii" \ string constant with multiple
lines.""")
diff --git a/Examples/test-suite/python/cpp11_result_of_runme.py b/Examples/test-suite/python/cpp11_result_of_runme.py
index 4469efd81..691d2a2d8 100644
--- a/Examples/test-suite/python/cpp11_result_of_runme.py
+++ b/Examples/test-suite/python/cpp11_result_of_runme.py
@@ -2,10 +2,10 @@ import cpp11_result_of
result = cpp11_result_of.test_result(cpp11_result_of.SQUARE, 3.0)
if result != 9.0:
- raise RuntimeError, "test_result(square, 3.0) is not 9.0. Got: " + str(
- result)
+ raise RuntimeError("test_result(square, 3.0) is not 9.0. Got: " + str(
+ result))
result = cpp11_result_of.test_result_alternative1(cpp11_result_of.SQUARE, 3.0)
if result != 9.0:
- raise RuntimeError, "test_result_alternative1(square, 3.0) is not 9.0. Got: " + str(
- result)
+ raise RuntimeError("test_result_alternative1(square, 3.0) is not 9.0. Got: " + str(
+ result))
diff --git a/Examples/test-suite/python/cpp11_rvalue_reference_move_runme.py b/Examples/test-suite/python/cpp11_rvalue_reference_move_runme.py
new file mode 100644
index 000000000..43e586f9a
--- /dev/null
+++ b/Examples/test-suite/python/cpp11_rvalue_reference_move_runme.py
@@ -0,0 +1,69 @@
+from cpp11_rvalue_reference_move import *
+
+# Function containing rvalue reference parameter
+Counter.reset_counts()
+mo = MovableCopyable(222)
+Counter.check_counts(1, 0, 0, 0, 0, 0)
+MovableCopyable.movein(mo)
+Counter.check_counts(1, 0, 0, 1, 0, 2)
+if not MovableCopyable.is_nullptr(mo):
+ raise RuntimeError("is_nullptr check")
+del mo
+Counter.check_counts(1, 0, 0, 1, 0, 2)
+
+# Move constructor test
+Counter.reset_counts()
+mo = MovableCopyable(222)
+Counter.check_counts(1, 0, 0, 0, 0, 0)
+mo_moved = MovableCopyable(mo)
+Counter.check_counts(1, 0, 0, 1, 0, 1)
+if not MovableCopyable.is_nullptr(mo):
+ raise RuntimeError("is_nullptr check")
+del mo
+Counter.check_counts(1, 0, 0, 1, 0, 1)
+del mo_moved
+Counter.check_counts(1, 0, 0, 1, 0, 2)
+
+# Move assignment operator test
+Counter.reset_counts()
+mo111 = MovableCopyable(111)
+mo222 = MovableCopyable(222)
+Counter.check_counts(2, 0, 0, 0, 0, 0)
+mo111.MoveAssign(mo222)
+Counter.check_counts(2, 0, 0, 0, 1, 1)
+if not MovableCopyable.is_nullptr(mo222):
+ raise RuntimeError("is_nullptr check")
+del mo222
+Counter.check_counts(2, 0, 0, 0, 1, 1)
+del mo111
+Counter.check_counts(2, 0, 0, 0, 1, 2)
+
+# null check
+Counter.reset_counts()
+exception_thrown = False
+try:
+ MovableCopyable.movein(None)
+except ValueError as e:
+ if "invalid null reference" not in str(e):
+ raise RuntimeError("incorrect exception message:" + str(e))
+ exception_thrown = True
+if not exception_thrown:
+ raise RuntimeError("Should have thrown null error")
+Counter.check_counts(0, 0, 0, 0, 0, 0)
+
+# output
+Counter.reset_counts()
+mc = MovableCopyable.moveout(1234)
+Counter.check_counts(2, 0, 0, 0, 1, 1)
+MovableCopyable.check_numbers_match(mc, 1234)
+
+exception_thrown = False
+try:
+ MovableCopyable.movein(mc)
+except RuntimeError as e:
+ if "cannot release ownership as memory is not owned" not in str(e):
+ raise RuntimeError("incorrect exception message:" + str(e))
+ exception_thrown = True
+if not exception_thrown:
+ raise RuntimeError("Should have thrown 'Cannot release ownership as memory is not owned' error")
+Counter.check_counts(2, 0, 0, 0, 1, 1)
diff --git a/Examples/test-suite/python/cpp11_rvalue_reference_runme.py b/Examples/test-suite/python/cpp11_rvalue_reference_runme.py
index c1cd3bf26..fad8b76d6 100644
--- a/Examples/test-suite/python/cpp11_rvalue_reference_runme.py
+++ b/Examples/test-suite/python/cpp11_rvalue_reference_runme.py
@@ -4,24 +4,24 @@ a = cpp11_rvalue_reference.A()
a.setAcopy(5)
if a.getAcopy() != 5:
- raise RunTimeError, ("int A::getAcopy() value is ",
+ raise RuntimeError("int A::getAcopy() value is ",
a.getAcopy(), " should be 5")
ptr = a.getAptr()
a.setAptr(ptr)
if a.getAcopy() != 5:
- raise RunTimeError, ("after A::setAptr(): int A::getAcopy() value is ", a.getAcopy(
+ raise RuntimeError("after A::setAptr(): int A::getAcopy() value is ", a.getAcopy(
), " should be 5")
a.setAref(ptr)
if a.getAcopy() != 5:
- raise RunTimeError, ("after A::setAref(): int A::getAcopy() value is ", a.getAcopy(
+ raise RuntimeError("after A::setAref(): int A::getAcopy() value is ", a.getAcopy(
), " should be 5")
rvalueref = a.getAmove()
-a.setAmove(rvalueref)
+a.setAref(rvalueref)
if a.getAcopy() != 5:
- raise RunTimeError, ("after A::setAmove(): int A::getAcopy() value is ", a.getAcopy(
+ raise RuntimeError("after A::setAmove(): int A::getAcopy() value is ", a.getAcopy(
), " should be 5")
diff --git a/Examples/test-suite/python/cpp11_shared_ptr_template_upcast_runme.py b/Examples/test-suite/python/cpp11_shared_ptr_template_upcast_runme.py
new file mode 100644
index 000000000..08a95c2ce
--- /dev/null
+++ b/Examples/test-suite/python/cpp11_shared_ptr_template_upcast_runme.py
@@ -0,0 +1,5 @@
+from cpp11_shared_ptr_template_upcast import *
+
+pd = MakePrintableDerived(20)
+pd.GetResult()
+pd.GetFormatted()
diff --git a/Examples/test-suite/python/cpp11_shared_ptr_upcast_runme.py b/Examples/test-suite/python/cpp11_shared_ptr_upcast_runme.py
new file mode 100644
index 000000000..08546a45e
--- /dev/null
+++ b/Examples/test-suite/python/cpp11_shared_ptr_upcast_runme.py
@@ -0,0 +1,63 @@
+from cpp11_shared_ptr_upcast import *
+
+# This is a port from the Ruby equivalent test and some tests ported from
+# Examples/test-suite/ruby/cpp11_shared_ptr_upcast_runme.rb are not working and commented out with:
+# not working:
+
+def swig_assert_equal_simple(expected, got):
+ if expected != got:
+ raise RuntimeError("Expected: {}. Got: {}")
+
+# non-overloaded
+swig_assert_equal_simple(7, derived_num1(Derived(7)))
+swig_assert_equal_simple(7, derived_num2([Derived(7)]))
+swig_assert_equal_simple(7, derived_num3({0: Derived(7)}))
+
+swig_assert_equal_simple(-1, base_num1(Derived(7)))
+swig_assert_equal_simple(-1, base_num2([Derived(7)]))
+swig_assert_equal_simple(-1, base_num3({0: Derived(7)}))
+
+swig_assert_equal_simple(999, derived_num1(None))
+# not working: swig_assert_equal_simple(999, derived_num2([None]))
+# not working: swig_assert_equal_simple(999, derived_num3({0: None}))
+
+swig_assert_equal_simple(999, base_num1(None))
+# not working: swig_assert_equal_simple(999, base_num2([None]))
+# not working: swig_assert_equal_simple(999, base_num3({0: None}))
+
+# overloaded
+swig_assert_equal_simple(7, derived_num(Derived(7)))
+swig_assert_equal_simple(7, derived_num([Derived(7)]))
+swig_assert_equal_simple(7, derived_num({0: Derived(7)}))
+
+swig_assert_equal_simple(-1, base_num(Derived(7)))
+swig_assert_equal_simple(-1, base_num([Derived(7)]))
+swig_assert_equal_simple(-1, base_num({0: Derived(7)}))
+
+# ptr to shared_ptr
+swig_assert_equal_simple(7, derived2_num1(Derived2(7)))
+swig_assert_equal_simple(7, derived2_num2([Derived2(7)]))
+swig_assert_equal_simple(7, derived2_num3({0: Derived2(7)}))
+
+swig_assert_equal_simple(-1, base2_num1(Derived2(7)))
+
+# not working: try:
+# not working: # Upcast for pointers to shared_ptr in this generic framework has not been implemented
+# not working: swig_assert_equal_simple(-1, base2_num2([Derived2(7)]))
+# not working: raise RuntimeError, "Failed to catch TypeError"
+# not working: except TypeError:
+# not working: pass
+# not working: try:
+# not working: # Upcast for pointers to shared_ptr in this generic framework has not been implemented
+# not working: swig_assert_equal_simple(-1, base2_num3({0: Derived2(7)}))
+# not working: raise RuntimeError, "Failed to catch TypeError"
+# not working: except TypeError:
+# not working: pass
+
+swig_assert_equal_simple(888, derived2_num1(None))
+swig_assert_equal_simple(999, derived2_num2([None])) # although 888 would be more consistent
+swig_assert_equal_simple(999, derived2_num3({0: None})) # although 888 would be more consistent
+
+swig_assert_equal_simple(888, base2_num1(None))
+swig_assert_equal_simple(999, base2_num2([None])) # although 888 would be more consistent
+swig_assert_equal_simple(999, base2_num3({0: None})) # although 888 would be more consistent
diff --git a/Examples/test-suite/python/cpp11_std_array_runme.py b/Examples/test-suite/python/cpp11_std_array_runme.py
index e5e7373dd..dbf9bcee3 100644
--- a/Examples/test-suite/python/cpp11_std_array_runme.py
+++ b/Examples/test-suite/python/cpp11_std_array_runme.py
@@ -3,7 +3,7 @@ import sys
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):
@@ -26,8 +26,8 @@ def steps_exception(swigarray, i, j, step):
a = swigarray[i::step]
else:
a = swigarray[i:j:step]
- raise RuntimeError, "swigarray[" + str(i) + ":" + str(j) + ":" + str(step) + "] missed steps exception for " + str(list(swigarray))
- except ValueError, e:
+ raise RuntimeError("swigarray[" + str(i) + ":" + str(j) + ":" + str(step) + "] missed steps exception for " + str(list(swigarray)))
+ except ValueError as e:
# print("exception: {}".format(e))
pass
@@ -43,16 +43,24 @@ def del_exception(swigarray, i, j, step):
del swigarray[i::step]
else:
del swigarray[i:j:step]
- raise RuntimeError, "swigarray[" + str(i) + ":" + str(j) + ":" + str(step) + "] missed del exception for " + str(list(swigarray))
- except ValueError, e:
+ raise RuntimeError("swigarray[" + str(i) + ":" + str(j) + ":" + str(step) + "] missed del exception for " + str(list(swigarray)))
+ except ValueError as e:
# print("exception: {}".format(e))
pass
def setslice_exception(swigarray, newval):
try:
swigarray[::] = newval
- raise RuntimeError, "swigarray[::] = " + str(newval) + " missed set exception for swigarray:" + str(list(swigarray))
- except TypeError, e:
+ raise RuntimeError("swigarray[::] = " + str(newval) + " missed set exception for swigarray:" + str(list(swigarray)))
+ except TypeError as e:
+# print("exception: {}".format(e))
+ pass
+
+def overload_type_exception(pythonlist):
+ try:
+ overloadFunc(pythonlist)
+ raise RuntimeError("overloadFunc({}) missed raising TypeError exception".format(pythonlist))
+ except TypeError as e:
# print("exception: {}".format(e))
pass
@@ -161,3 +169,21 @@ compare_containers(ai, [90, 80, 70, 60, 50, 40])
# fill
ai.fill(111)
compare_containers(ai, [111, 111, 111, 111, 111, 111])
+
+# Overloading
+newarray = overloadFunc([9, 8, 7, 6, 5, 4])
+compare_containers(newarray, [900, 800, 700, 600, 500, 400])
+
+ai = ArrayInt6([9, 8, 7, 6, 5, 4])
+newarray = overloadFunc([9, 8, 7, 6, 5, 4])
+compare_containers(newarray, [900, 800, 700, 600, 500, 400])
+
+overloadFunc(1, 2)
+overload_type_exception([1, 2, 3, 4, 5, "6"])
+overload_type_exception([1, 2, 3, 4, 5])
+overload_type_exception([1, 2, 3, 4, 5, 6, 7])
+
+# Construct from Python set
+myset = {11, 12, 13, 14, 15, 16}
+ai = ArrayInt6(myset)
+compare_containers(ai, list(myset))
diff --git a/Examples/test-suite/python/cpp11_std_unique_ptr_runme.py b/Examples/test-suite/python/cpp11_std_unique_ptr_runme.py
new file mode 100644
index 000000000..9548fc28a
--- /dev/null
+++ b/Examples/test-suite/python/cpp11_std_unique_ptr_runme.py
@@ -0,0 +1,109 @@
+from cpp11_std_unique_ptr import *
+
+def checkCount(expected_count):
+ actual_count = Klass.getTotal_count()
+ if (actual_count != expected_count):
+ raise RuntimeError("Counts incorrect, expected:" + expected_count + " actual:" + actual_count)
+
+# Test raw pointer handling involving virtual inheritance
+kini = KlassInheritance("KlassInheritanceInput")
+checkCount(1)
+s = useKlassRawPtr(kini)
+if s != "KlassInheritanceInput":
+ raise RuntimeError("Incorrect string: " + s)
+del kini
+checkCount(0)
+
+
+# unique_ptr as input
+kin = Klass("KlassInput")
+checkCount(1)
+s = takeKlassUniquePtr(kin)
+checkCount(0)
+if kin.thisown:
+ raise RuntimeError("thisown should be false")
+if s != "KlassInput":
+ raise RuntimeError("Incorrect string: " + s)
+if not is_nullptr(kin):
+ raise RuntimeError("is_nullptr failed")
+del kin # Should not fail, even though already deleted
+checkCount(0)
+
+kin = Klass("KlassInput")
+checkCount(1)
+s = takeKlassUniquePtr(kin)
+checkCount(0)
+if kin.thisown:
+ raise RuntimeError("thisown should be false")
+if s != "KlassInput":
+ raise RuntimeError("Incorrect string: " + s)
+if not is_nullptr(kin):
+ raise RuntimeError("is_nullptr failed")
+exception_thrown = False
+try:
+ s = takeKlassUniquePtr(kin)
+except RuntimeError as e:
+ if "cannot release ownership as memory is not owned" not in str(e):
+ raise RuntimeError("incorrect exception message");
+ exception_thrown = True
+if not exception_thrown:
+ raise RuntimeError("double usage of takeKlassUniquePtr should have been an error")
+del kin # Should not fail, even though already deleted
+checkCount(0)
+
+kin = Klass("KlassInput")
+exception_thrown = False
+notowned = get_not_owned_ptr(kin)
+try:
+ takeKlassUniquePtr(notowned)
+except RuntimeError as e:
+ exception_thrown = True
+if not exception_thrown:
+ raise RuntimeError("Should have thrown 'Cannot release ownership as memory is not owned' error")
+checkCount(1)
+del kin
+checkCount(0)
+
+kini = KlassInheritance("KlassInheritanceInput")
+checkCount(1)
+s = takeKlassUniquePtr(kini)
+checkCount(0)
+if kini.thisown:
+ raise RuntimeError("thisown should be false")
+if s != "KlassInheritanceInput":
+ raise RuntimeError("Incorrect string: " + s)
+if not is_nullptr(kini):
+ raise RuntimeError("is_nullptr failed")
+del kini # Should not fail, even though already deleted
+checkCount(0)
+
+takeKlassUniquePtr(None)
+takeKlassUniquePtr(make_null())
+checkCount(0)
+
+# overloaded parameters
+if overloadTest() != 0:
+ raise RuntimeError("overloadTest failed")
+if overloadTest(None) != 1:
+ raise RuntimeError("overloadTest failed")
+if overloadTest(Klass("over")) != 1:
+ raise RuntimeError("overloadTest failed")
+checkCount(0);
+
+
+# unique_ptr as output
+k1 = makeKlassUniquePtr("first")
+k2 = makeKlassUniquePtr("second")
+checkCount(2)
+
+del k1
+checkCount(1)
+
+if k2.getLabel() != "second":
+ raise "wrong object label"
+
+del k2
+checkCount(0)
+
+if (makeNullUniquePtr() != None):
+ raise RuntimeError("null failure")
diff --git a/Examples/test-suite/python/cpp11_template_explicit_runme.py b/Examples/test-suite/python/cpp11_template_explicit_runme.py
new file mode 100644
index 000000000..dacfb74c8
--- /dev/null
+++ b/Examples/test-suite/python/cpp11_template_explicit_runme.py
@@ -0,0 +1,15 @@
+import cpp11_template_explicit
+
+def swig_assert_isinstance(a, b):
+ if not isinstance(a, b):
+ raise RuntimeError(str(a) + " not an instance of " + str(b))
+
+# Call variants of the same templated function
+t1 = cpp11_template_explicit.my_templated_function_int (1,1.0)
+t2 = cpp11_template_explicit.my_templated_function_A (2,2.0)
+t3 = cpp11_template_explicit.my_templated_function_TemperInt(3,3.0)
+
+# Check return types
+swig_assert_isinstance(t1,int)
+swig_assert_isinstance(t2,cpp11_template_explicit.A)
+swig_assert_isinstance(t3,cpp11_template_explicit.TemperInt)
diff --git a/Examples/test-suite/python/cpp11_uniform_initialization_runme.py b/Examples/test-suite/python/cpp11_uniform_initialization_runme.py
index ecb468ccb..b01557a6f 100644
--- a/Examples/test-suite/python/cpp11_uniform_initialization_runme.py
+++ b/Examples/test-suite/python/cpp11_uniform_initialization_runme.py
@@ -9,13 +9,13 @@ if var2.getX() != 2:
m = cpp11_uniform_initialization.MoreInit()
if m.charptr != None:
- raise RuntimeError, m.charptr
+ raise RuntimeError(m.charptr)
m.charptr = "hello sir"
if m.charptr != "hello sir":
- raise RuntimeError, m.charptr
+ raise RuntimeError(m.charptr)
if m.more1(m.vi) != 15:
- raise RuntimeError, m.vi
+ raise RuntimeError(m.vi)
if m.more1([-1, 1, 2]) != 2:
- raise RuntimeError, m.vi
+ raise RuntimeError(m.vi)
if m.more1() != 10:
raise RuntimeError
diff --git a/Examples/test-suite/python/cpp11_using_constructor_runme.py b/Examples/test-suite/python/cpp11_using_constructor_runme.py
new file mode 100644
index 000000000..06f8f9af2
--- /dev/null
+++ b/Examples/test-suite/python/cpp11_using_constructor_runme.py
@@ -0,0 +1,145 @@
+from cpp11_using_constructor import *
+
+
+# Public base constructors
+a = PublicDerived1(0, "hi").meth()
+a = PublicDerived2().meth()
+a = PublicDerived2(0, "hi").meth()
+a = PublicDerived3().meth()
+a = PublicDerived3(0, "hi").meth()
+a = PublicDerived4().meth()
+a = PublicDerived5().meth()
+
+# Protected base constructors
+# Cannot test most of these as the constructors are protected
+ProtectedDerived5()
+
+# Mix of public and overloaded constructors
+MixedDerived1a(0, "hi").meth()
+MixedDerived1a().meth()
+MixedDerived1b(0, "hi").meth()
+MixedDerived1b().meth()
+
+MixedDerived2a(0, "hi").meth()
+MixedDerived2a().meth()
+MixedDerived2b(0, "hi").meth()
+MixedDerived2b().meth()
+
+MixedDerived2c(0, "hi").meth()
+MixedDerived2c().meth()
+MixedDerived2c(0).meth()
+
+MixedDerived2d(0, "hi").meth()
+MixedDerived2d().meth()
+MixedDerived2d(0).meth()
+
+MixedDerived3a(0, "hi").meth()
+MixedDerived3a().meth()
+MixedDerived3b(0, "hi").meth()
+MixedDerived3b().meth()
+
+MixedDerived3c(0, "hi").meth()
+MixedDerived3c().meth()
+MixedDerived3c(0).meth()
+
+MixedDerived3d(0, "hi").meth()
+MixedDerived3d().meth()
+MixedDerived3d(0).meth()
+
+MixedDerived4a(0, "hi").meth()
+MixedDerived4a().meth()
+MixedDerived4b(0, "hi").meth()
+MixedDerived4b().meth()
+
+MixedDerived4c().meth()
+MixedDerived4c(0).meth()
+
+MixedDerived4d().meth()
+MixedDerived4d(0).meth()
+
+MixedDerived4e().meth()
+
+MixedDerived4f().meth()
+
+# Mix of protected base constructors and overloading
+ProotDerived1a().meth()
+
+ProotDerived1b(0, "hi").meth()
+ProotDerived1b().meth()
+
+ProotDerived1c(0, "hi").meth()
+ProotDerived1c().meth()
+
+ProotDerived1d(0).meth()
+ProotDerived1d().meth()
+
+ProotDerived1e(0).meth()
+ProotDerived1e().meth()
+
+ProotDerived2a(0, "hi").meth()
+
+ProotDerived2b(0, "hi").meth()
+
+ProotDerived2c(0, "hi").meth()
+ProotDerived2c().meth()
+
+ProotDerived2d(0, "hi").meth()
+ProotDerived2d().meth()
+
+ProotDerived2e(0, "hi").meth()
+ProotDerived2e().meth()
+
+ProotDerived2f(0, "hi").meth()
+ProotDerived2f().meth()
+ProotDerived2f(0).meth()
+
+# Deeper inheritance chain
+db3 = DeepBase3(11)
+db3 = DeepBase3(11, 22)
+db3 = DeepBase3(11, 22, 33)
+dbp3 = DeepProtectedBase3(11, 22, 33)
+
+# Missing base
+HiddenDerived1()
+
+# Templates and public base constructors (derive from non-template)
+TemplatePublicDerived1Int(0, "hi").meth()
+TemplatePublicDerived2Int().meth()
+TemplatePublicDerived2Int(0, "hi").meth()
+TemplatePublicDerived3Int().meth()
+TemplatePublicDerived3Int(0, "hi").meth()
+TemplatePublicDerived4Int().meth()
+TemplatePublicDerived5Int().meth()
+
+# Templates and public base constructors (derive from template)
+TemplPublicDerived1Int(0, "hi").meth()
+TemplPublicDerived2Int().meth()
+TemplPublicDerived2Int(0, "hi").meth()
+TemplPublicDerived3Int().meth()
+TemplPublicDerived3Int(0, "hi").meth()
+TemplPublicDerived4Int().meth()
+TemplPublicDerived5Int().meth()
+TemplPublicDerived6Int(0, "hi").meth()
+TemplPublicDerived6Int().meth()
+
+# Templated constructors (public)
+tcb = TemplateConstructor1Base(0, "hi")
+tcb = TemplateConstructor1Base("hi", "hi")
+tcb = TemplateConstructor1Base(11.1, "hi")
+tcb.normal_method()
+tcb.template_method(0, "hi")
+tcb.template_method("hey", "ho")
+
+tcd1 = TemplateConstructor1Derived(0, "hi")
+tcd1 = TemplateConstructor1Derived("hi", "hi")
+tcd1 = TemplateConstructor1Derived(11.1, "hi")
+# Not the best test as these are also in the base class, (should use introspection to check)
+tcd1.normal_method()
+tcd1.template_method(0, "hi")
+tcd1.template_method("hey", "ho")
+
+# Templated constructors (protected)
+tcd2 = TemplateConstructor2Derived()
+tcd2.normal_method()
+tcd2.template_method(0, "hi")
+tcd2.template_method("hey", "ho")
diff --git a/Examples/test-suite/python/cpp11_variadic_function_templates_runme.py b/Examples/test-suite/python/cpp11_variadic_function_templates_runme.py
new file mode 100644
index 000000000..ae1febb46
--- /dev/null
+++ b/Examples/test-suite/python/cpp11_variadic_function_templates_runme.py
@@ -0,0 +1,20 @@
+from cpp11_variadic_function_templates import *
+
+ec = EmplaceContainer()
+ec.emplace(A())
+ec.emplace(A(), B())
+ec.emplace(A(), B(), C())
+ec.emplace(A(), B(), C(), D())
+
+def check(expected, got):
+ if expected != got:
+ raise RuntimeError("failed: {} != {}".format(expected, got))
+
+a = A()
+b = B()
+c = C()
+check(variadicmix1(), 20)
+check(variadicmix1(a), 20)
+check(variadicmix1(a, b), 10)
+check(variadicmix1(a, b, c), 20)
+check(variadicmix1(11, 22), 10)
diff --git a/Examples/test-suite/python/cpp11_variadic_templates_runme.py b/Examples/test-suite/python/cpp11_variadic_templates_runme.py
new file mode 100644
index 000000000..ac1474346
--- /dev/null
+++ b/Examples/test-suite/python/cpp11_variadic_templates_runme.py
@@ -0,0 +1,158 @@
+from cpp11_variadic_templates import *
+
+ma = MultiArgs1()
+
+# SizeOf testing
+so0 = SizeOf0()
+if so0.size != 0:
+ raise RuntimeError("so0.size")
+so1 = SizeOf1()
+if so1.size != 1:
+ raise RuntimeError("so1.size")
+so2 = SizeOf2()
+if so2.size != 2:
+ raise RuntimeError("so2.size")
+so3 = SizeOf3()
+if so3.size != 3:
+ raise RuntimeError("so3.size")
+
+a = A()
+b = B()
+c = C()
+d = D()
+
+# MultiInherit0
+mi0 = MultiInherit0()
+mi0.MultiInstanceMethod()
+MultiInherit0.MultiStaticMethod()
+mi0.InstanceMethod()
+MultiInherit0.StaticMethod()
+
+# MultiInherit1
+mi1 = MultiInherit1(a)
+if mi1.a != 100:
+ raise RuntimeError("fail mi1.a")
+mi1.MultiInstanceMethod(a)
+MultiInherit1.MultiStaticMethod(a)
+mi1.InstanceMethod()
+MultiInherit1.StaticMethod()
+
+# MultiInherit2
+mi2 = MultiInherit2(a, b)
+if mi2.a != 100:
+ raise RuntimeError("fail mi2.a")
+if mi2.b != 200:
+ raise RuntimeError("fail mi2.b")
+mi2.MultiInstanceMethod(a, b)
+MultiInherit2.MultiStaticMethod(a, b)
+mi2.InstanceMethod()
+MultiInherit2.StaticMethod()
+
+# MultiInherit3
+mi3 = MultiInherit3(a, b, c)
+if mi3.a != 100:
+ raise RuntimeError("fail mi3.a")
+if mi3.b != 200:
+ raise RuntimeError("fail mi3.b")
+if mi3.c != 300:
+ raise RuntimeError("fail mi3.c")
+mi3.MultiInstanceMethod(a, b, c)
+MultiInherit3.MultiStaticMethod(a, b, c)
+mi3.InstanceMethod()
+MultiInherit3.StaticMethod()
+
+# NumerousInherit0
+num = 123
+ni0 = NumerousInherit0(num)
+ni0.NumerousInstanceMethod(num)
+NumerousInherit0.NumerousStaticMethod(num)
+ni0.InstanceMethod()
+NumerousInherit0.StaticMethod()
+
+# NumerousInherit1
+ni1 = NumerousInherit1(num, a)
+if ni1.a != 100:
+ raise RuntimeError("fail ni1.a")
+ni1.NumerousInstanceMethod(num, a)
+NumerousInherit1.NumerousStaticMethod(num, a)
+ni1.InstanceMethod()
+NumerousInherit1.StaticMethod()
+
+# NumerousInherit2
+ni2 = NumerousInherit2(num, a, b)
+if ni2.a != 100:
+ raise RuntimeError("fail ni2.a")
+if ni2.b != 200:
+ raise RuntimeError("fail ni2.b")
+ni2.NumerousInstanceMethod(num, a, b)
+NumerousInherit2.NumerousStaticMethod(num, a, b)
+ni2.InstanceMethod()
+NumerousInherit2.StaticMethod()
+
+# NumerousInherit3
+ni3 = NumerousInherit3(num, a, b, c)
+if ni3.a != 100:
+ raise RuntimeError("fail ni3.a")
+if ni3.b != 200:
+ raise RuntimeError("fail ni3.b")
+if ni3.c != 300:
+ raise RuntimeError("fail ni3.c")
+ni3.NumerousInstanceMethod(num, a, b, c)
+NumerousInherit3.NumerousStaticMethod(num, a, b, c)
+ni3.InstanceMethod()
+NumerousInherit3.StaticMethod()
+
+LotsInherit1
+lots1 = LotsInherit1(a)
+if lots1.a != 100:
+ raise RuntimeError("fail lots1.a")
+lots1.LotsInstanceMethod(a)
+LotsInherit1.LotsStaticMethod(a)
+lots1.InstanceMethod()
+LotsInherit1.StaticMethod()
+
+# LotsInherit2
+lots2 = LotsInherit2(a, b)
+if lots2.a != 100:
+ raise RuntimeError("fail lots2.a")
+if lots2.b != 200:
+ raise RuntimeError("fail lots2.b")
+lots2.LotsInstanceMethod(a, b)
+LotsInherit2.LotsStaticMethod(a, b)
+lots2.InstanceMethod()
+LotsInherit2.StaticMethod()
+
+# LotsInherit3
+lots3 = LotsInherit3(a, b, c)
+if lots3.a != 100:
+ raise RuntimeError("fail lots3.a")
+if lots3.b != 200:
+ raise RuntimeError("fail lots3.b")
+if lots3.c != 300:
+ raise RuntimeError("fail lots3.c")
+lots3.LotsInstanceMethod(a, b, c)
+LotsInherit3.LotsStaticMethod(a, b, c)
+lots3.InstanceMethod()
+LotsInherit3.StaticMethod()
+
+# LotsInherit4
+lots4 = LotsInherit4(a, b, c, d)
+if lots4.a != 100:
+ raise RuntimeError("fail lots4.a")
+if lots4.b != 200:
+ raise RuntimeError("fail lots4.b")
+if lots4.c != 300:
+ raise RuntimeError("fail lots4.c")
+if lots4.d != 400:
+ raise RuntimeError("fail lots4.c")
+lots4.LotsInstanceMethod(a, b, c, d)
+LotsInherit4.LotsStaticMethod(a, b, c, d)
+lots4.InstanceMethod()
+LotsInherit4.StaticMethod()
+
+# PlainStruct
+ps = PlainStruct()
+ps.PlainStructParms0()
+ps.PlainStructParms1(a)
+ps.PlainStructParms2(a, b)
+ps.PlainStructParms3(a, b, c)
diff --git a/Examples/test-suite/python/cpp14_auto_return_type_runme.py b/Examples/test-suite/python/cpp14_auto_return_type_runme.py
new file mode 100644
index 000000000..5efa0e512
--- /dev/null
+++ b/Examples/test-suite/python/cpp14_auto_return_type_runme.py
@@ -0,0 +1,10 @@
+from cpp14_auto_return_type import *
+
+sc = va_static_cast()
+if sc != 42:
+ raise RuntimeError("va_static_cast fail {}".format(sc))
+
+x = X()
+a = x.a()
+if a != "a string":
+ raise RuntimeError("x.a fail {}".format(a))
diff --git a/Examples/test-suite/python/cpp14_binary_integer_literals_runme.py b/Examples/test-suite/python/cpp14_binary_integer_literals_runme.py
index 8274ec6b5..ee308aa39 100644
--- a/Examples/test-suite/python/cpp14_binary_integer_literals_runme.py
+++ b/Examples/test-suite/python/cpp14_binary_integer_literals_runme.py
@@ -14,3 +14,12 @@ if cvar.b4 != 4:
if cvar.b5 != 5:
raise RuntimeError
+
+if b6 != 6:
+ raise RuntimeError
+
+if b7 != 7:
+ raise RuntimeError
+
+if b8 != 8:
+ raise RuntimeError
diff --git a/Examples/test-suite/python/cpp17_director_string_view_runme.py b/Examples/test-suite/python/cpp17_director_string_view_runme.py
new file mode 100644
index 000000000..f9791b376
--- /dev/null
+++ b/Examples/test-suite/python/cpp17_director_string_view_runme.py
@@ -0,0 +1,34 @@
+from cpp17_director_string_view import *
+
+
+class B(A):
+
+ def __init__(self, string):
+ A.__init__(self, string)
+
+ def get_first(self):
+ # Since std::string_view contains a pointer into a string, the string
+ # cannot be a temporary in order to avoid undefined behaviour.
+ self.cached_string = A.get_first(self) + " world!"
+ return self.cached_string
+
+ def process_text(self, string):
+ A.process_text(self, string)
+ self.smem = "hello"
+
+
+b = B("hello")
+
+if b.get(0) != "hello":
+ raise RuntimeError("b.get(0): {}".format(b.get(0)))
+
+if b.get_first() != "hello world!":
+ raise RuntimeError("b.get_first(): {}".format(b.get_first()))
+
+if b.call_get_first() != "hello world!":
+ raise RuntimeError("b.call_get_first(): {}".format(b.call_get_first()))
+
+b.call_process_func()
+
+if b.smem != "hello":
+ raise RuntimeError("smem: {}".format(smem))
diff --git a/Examples/test-suite/python/cpp17_std_filesystem_runme.py b/Examples/test-suite/python/cpp17_std_filesystem_runme.py
new file mode 100644
index 000000000..2192ac1a8
--- /dev/null
+++ b/Examples/test-suite/python/cpp17_std_filesystem_runme.py
@@ -0,0 +1,64 @@
+import pathlib
+
+from cpp17_std_filesystem import *
+
+
+def check_flag(flag):
+ if not flag:
+ raise RuntimeError("Check failed")
+
+
+def format_msg(p, p2):
+ return "'{p}' != '{p2}', repr(p)={r}, repr(p2)={r2}".format(p=p, p2=p2, r=repr(p), r2=repr(p2))
+
+
+def check(p, p2):
+ assert p == p2, format_msg(p, p2)
+
+
+# Test the output typemap. The wrapped C++ functions
+# makePath is expected to return a std::filesystem::path object
+# (see li_std_filesystem.i). The output typemap should be in place to
+# convert this std::filesystem::path object into a pathlib.Path object.
+path = makePath("foo")
+check_flag(isinstance(path, pathlib.Path))
+check(str(path), "foo")
+
+pathConstRef = makePathConstRef("foo")
+check_flag(isinstance(pathConstRef, pathlib.Path))
+check(str(pathConstRef), "foo")
+
+# Each of these should return a reference to a wrapped
+# std::filesystem::path object.
+pathPtr = makePathPtr("foo")
+check_flag(not isinstance(pathPtr, pathlib.Path))
+
+pathRef = makePathRef("foo")
+check_flag(not isinstance(pathRef, pathlib.Path))
+
+# Now test various input typemaps. Each of the wrapped C++ functions
+# (pathToStr, pathConstRefToStr) is expecting an argument of a
+# different type (see li_std_filesystem.i). Typemaps should be in place to
+# convert this pathlib.Path into the expected argument type.
+check(pathToStr(path), "foo")
+check(pathConstRefToStr(path), "foo")
+
+# Similarly, each of the input typemaps should know what to do with a string.
+check(pathToStr("foo"), "foo")
+check(pathConstRefToStr("foo"), "foo")
+
+# Similarly, each of the input typemaps should know what to do with a std::filesystem::path instance.
+check(pathToStr(pathPtr), "foo")
+check(pathConstRefToStr(pathPtr), "foo")
+
+specialPath = pathlib.Path("/家/屋")
+roundTripped = roundTrip(specialPath)
+roundTrippedSquared = roundTrip(roundTripped)
+lines = []
+if specialPath != roundTripped:
+ lines.append("specialPath, roundTripped: " + format_msg(specialPath, roundTripped))
+if roundTripped != roundTrippedSquared:
+ lines.append("roundTripped, roundTrippedSquared: " + format_msg(roundTripped, roundTrippedSquared))
+if specialPath != roundTrippedSquared:
+ lines.append("specialPath, roundTrippedSquared: " + format_msg(specialPath, roundTrippedSquared))
+assert not lines, "\n".join(lines)
diff --git a/Examples/test-suite/python/cpp17_string_view_runme.py b/Examples/test-suite/python/cpp17_string_view_runme.py
new file mode 100644
index 000000000..0f1be15e4
--- /dev/null
+++ b/Examples/test-suite/python/cpp17_string_view_runme.py
@@ -0,0 +1,51 @@
+import cpp17_string_view
+
+import sys
+if sys.version_info[0:1] < (3, 0):
+ # string_view.i only supported for Python3
+ sys.exit(0)
+
+# Checking expected use of %typemap(in) std::string_view {}
+cpp17_string_view.test_value("Fee")
+
+# Checking expected result of %typemap(out) std::string_view {}
+if cpp17_string_view.test_value("Fi") != "Fi":
+ raise RuntimeError("Test 1: "+cpp17_string_view.test_value("Fi"))
+
+# Checking expected use of %typemap(in) const std::string_view & {}
+cpp17_string_view.test_const_reference("Fo")
+
+# Checking expected result of %typemap(out) const std.string_view& {}
+if cpp17_string_view.test_const_reference("Fum") != "Fum":
+ raise RuntimeError("Test 3")
+
+# Input and output typemaps for pointers and non-const references to
+# std::string_view are *not* supported; the following tests confirm
+# that none of these cases are slipping through.
+
+stringPtr = cpp17_string_view.test_pointer_out()
+
+cpp17_string_view.test_pointer(stringPtr)
+
+stringPtr = cpp17_string_view.test_const_pointer_out()
+
+cpp17_string_view.test_const_pointer(stringPtr)
+
+stringPtr = cpp17_string_view.test_reference_out()
+
+cpp17_string_view.test_reference(stringPtr)
+
+# Global variables
+s = "initial string"
+if cpp17_string_view.ConstGlobalString != "const global string":
+ raise RuntimeError("ConstGlobalString test")
+
+# Member variables
+myStructure = cpp17_string_view.Structure()
+if myStructure.ConstMemberString != "const member string":
+ raise RuntimeError("ConstMemberString test")
+
+if cpp17_string_view.Structure.ConstStaticMemberString != "const static member string":
+ raise RuntimeError("ConstStaticMemberString test")
+
+cpp17_string_view.test_const_reference_returning_void("foo")
diff --git a/Examples/test-suite/python/cpp20_spaceship_operator_runme.py b/Examples/test-suite/python/cpp20_spaceship_operator_runme.py
new file mode 100644
index 000000000..f13fd48f6
--- /dev/null
+++ b/Examples/test-suite/python/cpp20_spaceship_operator_runme.py
@@ -0,0 +1,19 @@
+from cpp20_spaceship_operator import *
+
+def check_equal(a, b):
+ if a != b:
+ raise RuntimeError("{} is not equal to {}".format(a, b))
+
+check_equal(ALIEN, 1)
+check_equal(SPACE, 1)
+check_equal(COMET, 1)
+check_equal(cvar.v, 42)
+
+x = A(1)
+y = A(2)
+
+check_equal(spaceship(x, y) < 0, True)
+check_equal(spaceship(x, x), 0)
+check_equal(spaceship(y, x) > 0, True)
+
+check_equal(f(), 42)
diff --git a/Examples/test-suite/python/cpp_enum_runme.py b/Examples/test-suite/python/cpp_enum_runme.py
index 5f1e91c97..910d378e4 100644
--- a/Examples/test-suite/python/cpp_enum_runme.py
+++ b/Examples/test-suite/python/cpp_enum_runme.py
@@ -3,21 +3,17 @@ import cpp_enum
f = cpp_enum.Foo()
if f.hola != f.Hello:
- print f.hola
- raise RuntimeError
+ raise RuntimeError("f.hola: {}".format(f.hola))
f.hola = f.Hi
if f.hola != f.Hi:
- print f.hola
- raise RuntimeError
+ raise RuntimeError("f.hola: {}".format(f.hola))
f.hola = f.Hello
if f.hola != f.Hello:
- print f.hola
- raise RuntimeError
+ raise RuntimeError("f.hola: {}".format(f.hola))
cpp_enum.cvar.hi = cpp_enum.Hello
if cpp_enum.cvar.hi != cpp_enum.Hello:
- print cpp_enum.cvar.hi
- raise RuntimeError
+ raise RuntimeError("cpp_enum.cvar.hi: {}".format(cpp_enum.cvar.hi))
diff --git a/Examples/test-suite/python/cpp_parameters_runme.py b/Examples/test-suite/python/cpp_parameters_runme.py
new file mode 100644
index 000000000..99d14ad74
--- /dev/null
+++ b/Examples/test-suite/python/cpp_parameters_runme.py
@@ -0,0 +1,296 @@
+from cpp_parameters import *
+
+# Testing correct and incorrect parameter counts being passed (kwargs and non-kwargs)
+# Note that the implementation depends a lot on whether zero, one, two or more args are being wrapped
+
+def is_python_fastproxy():
+ """Return True if SWIG is generating Python code using -fastproxy."""
+ import cpp_parameters
+ # Note: _swig_new_instance_method is only generated when using -fastproxy
+ return hasattr(cpp_parameters, "_swig_new_instance_method")
+
+# Zero parameters expected
+x = Zero()
+try:
+ x = Zero(z=0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+try:
+ x = Zero(0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+
+try:
+ x.zero(z=0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+try:
+ x.zero(0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+
+try:
+ Zero.stat_zero(z=0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+try:
+ Zero.stat_zero(0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+
+try:
+ global_zero(z=0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+try:
+ global_zero(0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+
+# One mandatory parameter expected
+x = One(1)
+try:
+ x = One(a=1, z=0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+try:
+ x = One(1, 0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+
+try:
+ x.one(a=1, z=0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+try:
+ x.one(1, 0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+
+try:
+ One.stat_one(a=1, z=0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+try:
+ One.stat_one(1, 0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+
+try:
+ global_one(a=1, z=0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+try:
+ global_one(1, 0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+
+# Two mandatory parameters expected
+x = Two(1, 2)
+try:
+ x = Two(a=1, b=2, z=0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+try:
+ x = Two(1, 2, 0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+
+try:
+ x.two(a=1, b=2, z=0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+try:
+ x.two(1, 2, 0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+
+try:
+ Two.stat_two(a=1, b=2, z=0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+try:
+ Two.stat_two(1, 2, 0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+
+try:
+ global_two(a=1, b=2, z=0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+try:
+ global_two(1, 2, 0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+
+# Single optional parameter expected
+x = Single(1)
+try:
+ x = Single(a=1, z=0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+try:
+ x = Single(1, 0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+
+try:
+ x.single(a=1, z=0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+try:
+ x.single(1, 0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+
+try:
+ Single.stat_single(a=1, z=0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+try:
+ Single.stat_single(1, 0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+
+try:
+ global_single(a=1, z=0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+try:
+ global_single(1, 0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+
+# Test that -builtin option throws TypeError if kwargs are used even when they look like they should work, kwargs are not supported unless using -keyword.
+# Also same for -fastproxy option except that kwargs are supported by default for constructors. TODO: Fix inconsistency.
+
+if is_python_builtin() or is_python_fastproxy():
+ # One mandatory parameter in API
+ x = One(1)
+ if is_python_fastproxy():
+ x = One(a=1)
+ else:
+ try:
+ x = One(a=1)
+ raise RuntimeError("Missed throw")
+ except TypeError:
+ pass
+ try:
+ x.one(a=1)
+ raise RuntimeError("Missed throw")
+ except TypeError:
+ pass
+ try:
+ One.stat_one(a=1)
+ raise RuntimeError("Missed throw")
+ except TypeError:
+ pass
+ try:
+ global_one(a=1)
+ raise RuntimeError("Missed throw")
+ except TypeError:
+ pass
+
+ # Two mandatory parameters in API
+ x = Two(1, 2)
+ if is_python_fastproxy():
+ x = Two(a=1, b=2)
+ else:
+ try:
+ x = Two(a=1, b=2)
+ raise RuntimeError("Missed throw")
+ except TypeError:
+ pass
+ try:
+ x.two(a=1, b=2)
+ raise RuntimeError("Missed throw")
+ except TypeError:
+ pass
+ try:
+ Two.stat_two(a=1, b=2)
+ raise RuntimeError("Missed throw")
+ except TypeError:
+ pass
+ try:
+ global_two(a=1, b=2)
+ raise RuntimeError("Missed throw")
+ except TypeError:
+ pass
+
+ # Single optional parameter in API
+ x = Single(1)
+ if is_python_fastproxy():
+ x = Single(a=1)
+ else:
+ try:
+ x = Single(a=1)
+ raise RuntimeError("Missed throw")
+ except TypeError:
+ pass
+ try:
+ x.single(a=1)
+ raise RuntimeError("Missed throw")
+ except TypeError:
+ pass
+ try:
+ Single.stat_single(a=1)
+ raise RuntimeError("Missed throw")
+ except TypeError:
+ pass
+ try:
+ global_single(a=1)
+ raise RuntimeError("Missed throw")
+ except TypeError:
+ pass
+
+else:
+ # Non-builtin should work as expected
+ # One mandatory parameter in API
+ x = One(a=1)
+ x.one(a=1)
+ One.stat_one(a=1)
+ global_one(a=1)
+
+ # Two mandatory parameters in API
+ x = Two(a=1, b=2)
+ x.two(a=1, b=2)
+ Two.stat_two(a=1, b=2)
+ global_two(a=1, b=2)
+
+ # Single optional parameter in API
+ x = Single(a=1)
+ x.single(a=1)
+ Single.stat_single(a=1)
+ global_single(a=1)
diff --git a/Examples/test-suite/python/default_args_runme.py b/Examples/test-suite/python/default_args_runme.py
index 14ef8c594..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:
@@ -108,48 +108,34 @@ def run(module_name):
if Klass_inc().val != 0:
raise RuntimeError("Klass::inc failed")
- tricky_failure = False
tricky = default_args.TrickyInPython()
if tricky.value_m1(10) != -1:
- print "trickyvalue_m1 failed"
- tricky_failure = True
+ raise RuntimeError("trickyvalue_m1 failed")
if tricky.value_m1(10, 10) != 10:
- print "trickyvalue_m1 failed"
- tricky_failure = True
+ raise RuntimeError("trickyvalue_m1 failed")
if tricky.value_0xabcdef(10) != 0xabcdef:
- print "trickyvalue_0xabcdef failed"
- tricky_failure = True
+ raise RuntimeError("trickyvalue_0xabcdef failed")
if tricky.value_0644(10) != 420:
- print "trickyvalue_0644 failed"
- tricky_failure = True
+ raise RuntimeError("trickyvalue_0644 failed")
if tricky.value_perm(10) != 420:
- print "trickyvalue_perm failed"
- tricky_failure = True
+ raise RuntimeError("trickyvalue_perm failed")
if tricky.value_m01(10) != -1:
- print "trickyvalue_m01 failed"
- tricky_failure = True
+ raise RuntimeError("trickyvalue_m01 failed")
if not tricky.booltest2():
- print "booltest2 failed"
- tricky_failure = True
+ raise RuntimeError("booltest2 failed")
if tricky.max_32bit_int1() != 0x7FFFFFFF:
- print "max_32bit_int1 failed"
- tricky_failure = True
+ raise RuntimeError("max_32bit_int1 failed")
if tricky.min_32bit_int1() != -2147483648:
- print "min_32bit_int1 failed"
- tricky_failure = True
+ raise RuntimeError("min_32bit_int1 failed")
if tricky.max_32bit_int2() != 0x7FFFFFFF:
- print "max_32bit_int2 failed"
- tricky_failure = True
+ raise RuntimeError("max_32bit_int2 failed")
tricky.too_big_32bit_int1()
tricky.too_small_32bit_int1()
tricky.too_big_32bit_int2()
tricky.too_small_32bit_int2()
- if tricky_failure:
- raise RuntimeError
-
default_args.seek()
default_args.seek(10)
diff --git a/Examples/test-suite/python/default_constructor_runme.py b/Examples/test-suite/python/default_constructor_runme.py
index 1e877adda..2943dc960 100644
--- a/Examples/test-suite/python/default_constructor_runme.py
+++ b/Examples/test-suite/python/default_constructor_runme.py
@@ -16,24 +16,24 @@ dc.delete_AA(aa)
try:
b = dc.new_B()
- print "Whoa. new_BB created."
-except:
+ raise RuntimeError("Whoa. new_BB created.")
+except TypeError:
pass
del_b = dc.delete_B
try:
bb = dc.new_BB()
- print "Whoa. new_BB created."
-except:
+ raise RuntimeError("Whoa. new_BB created.")
+except AttributeError:
pass
del_bb = dc.delete_BB
try:
c = dc.new_C()
- print "Whoa. new_C created."
-except:
+ raise RuntimeError("Whoa. new_C created.")
+except AttributeError:
pass
del_c = dc.delete_C
@@ -43,24 +43,24 @@ dc.delete_CC(cc)
try:
d = dc.new_D()
- print "Whoa. new_D created"
-except:
+ raise RuntimeError("Whoa. new_D created")
+except AttributeError:
pass
del_d = dc.delete_D
try:
dd = dc.new_DD()
- print "Whoa. new_DD created"
-except:
+ raise RuntimeError("Whoa. new_DD created")
+except AttributeError:
pass
dd = dc.delete_DD
try:
ad = dc.new_AD()
- print "Whoa. new_AD created"
-except:
+ raise RuntimeError("Whoa. new_AD created")
+except AttributeError:
pass
del_ad = dc.delete_AD
@@ -73,8 +73,8 @@ dc.delete_EE(ee)
try:
eb = dc.new_EB()
- print "Whoa. new_EB created"
-except:
+ raise RuntimeError("Whoa. new_EB created")
+except AttributeError:
pass
del_eb = dc.delete_EB
@@ -83,7 +83,7 @@ f = dc.new_F()
try:
del_f = dc.delete_F
- print "Whoa. delete_F created"
+ raise RuntimeError("Whoa. delete_F created")
except AttributeError:
pass
@@ -93,7 +93,7 @@ g = dc.new_G()
try:
del_g = dc.delete_G
- print "Whoa. delete_G created"
+ raise RuntimeError("Whoa. delete_G created")
except AttributeError:
pass
diff --git a/Examples/test-suite/python/director_abstract_runme.py b/Examples/test-suite/python/director_abstract_runme.py
index 333b75fe5..fbc54808e 100644
--- a/Examples/test-suite/python/director_abstract_runme.py
+++ b/Examples/test-suite/python/director_abstract_runme.py
@@ -13,10 +13,10 @@ class MyFoo(director_abstract.Foo):
a = MyFoo()
if a.ping() != "MyFoo::ping()":
- raise RuntimeError, a.ping()
+ raise RuntimeError(a.ping())
if a.pong() != "Foo::pong();MyFoo::ping()":
- raise RuntimeError, a.pong()
+ raise RuntimeError(a.pong())
class MyExample1(director_abstract.Example1):
@@ -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_alternating_runme.py b/Examples/test-suite/python/director_alternating_runme.py
index a93ffec34..dc85351b5 100644
--- a/Examples/test-suite/python/director_alternating_runme.py
+++ b/Examples/test-suite/python/director_alternating_runme.py
@@ -2,4 +2,4 @@ from director_alternating import *
id = getBar().id()
if id != idFromGetBar():
- raise RuntimeError, "Got wrong id: " + str(id)
+ raise RuntimeError("Got wrong id: " + str(id))
diff --git a/Examples/test-suite/python/director_basic_runme.py b/Examples/test-suite/python/director_basic_runme.py
index 6564c95a2..2d07c3ad5 100644
--- a/Examples/test-suite/python/director_basic_runme.py
+++ b/Examples/test-suite/python/director_basic_runme.py
@@ -10,18 +10,18 @@ class PyFoo(director_basic.Foo):
a = PyFoo()
if a.ping() != "PyFoo::ping()":
- raise RuntimeError, a.ping()
+ raise RuntimeError(a.ping())
if a.pong() != "Foo::pong();PyFoo::ping()":
- raise RuntimeError, a.pong()
+ raise RuntimeError(a.pong())
b = director_basic.Foo()
if b.ping() != "Foo::ping()":
- raise RuntimeError, b.ping()
+ raise RuntimeError(b.ping())
if b.pong() != "Foo::pong();Foo::ping()":
- raise RuntimeError, b.pong()
+ raise RuntimeError(b.pong())
a = director_basic.A1(1)
@@ -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_comparison_operators_runme.py b/Examples/test-suite/python/director_comparison_operators_runme.py
new file mode 100644
index 000000000..e9bf9438d
--- /dev/null
+++ b/Examples/test-suite/python/director_comparison_operators_runme.py
@@ -0,0 +1,11 @@
+import director_comparison_operators
+
+
+class PyFoo(director_comparison_operators.Foo):
+ pass
+
+
+a = PyFoo()
+
+if a.test() != "a=1,b=2":
+ raise RuntimeError(a.test())
diff --git a/Examples/test-suite/python/director_detect_runme.py b/Examples/test-suite/python/director_detect_runme.py
index 345051982..b9c73eb45 100644
--- a/Examples/test-suite/python/director_detect_runme.py
+++ b/Examples/test-suite/python/director_detect_runme.py
@@ -35,4 +35,4 @@ c = b.clone()
vc = c.get_value()
if (v != 3) or (b.val != 5) or (vc != 6):
- raise RuntimeError, "Bad virtual detection"
+ raise RuntimeError("Bad virtual detection")
diff --git a/Examples/test-suite/python/director_exception_runme.py b/Examples/test-suite/python/director_exception_runme.py
index 06856f30a..458983c6a 100644
--- a/Examples/test-suite/python/director_exception_runme.py
+++ b/Examples/test-suite/python/director_exception_runme.py
@@ -10,7 +10,7 @@ class MyException(Exception):
class MyFoo(Foo):
def ping(self):
- raise NotImplementedError, "MyFoo::ping() EXCEPTION"
+ raise NotImplementedError("MyFoo::ping() EXCEPTION")
class MyFoo2(Foo):
@@ -28,74 +28,58 @@ class MyFoo3(Foo):
class MyFoo4(Foo):
def ping(self, *args):
- print(type("bad", "call")) # throws TypeError message: type() takes 1 or 3 arguments
+ t = type("bad", "call") # throws TypeError message: type() takes 1 or 3 arguments
return "Foo4.ping"
# Check that the NotImplementedError raised by MyFoo.ping() is returned by
# MyFoo.pong().
-ok = 0
a = MyFoo()
b = launder(a)
try:
b.pong()
-except NotImplementedError, e:
- if str(e) == "MyFoo::ping() EXCEPTION":
- ok = 1
- else:
- print "Unexpected error message: %s" % str(e)
-except:
+ raise RuntimeError("Exception was not thrown")
+except NotImplementedError as e:
+ if not str(e) == "MyFoo::ping() EXCEPTION":
+ raise RuntimeError("Unexpected error message: %s" % str(e))
+except TypeError:
pass
-if not ok:
- raise RuntimeError
# Check that the director returns the appropriate TypeError if the return type
# is wrong.
-ok = 0
a = MyFoo2()
b = launder(a)
try:
b.pong()
-except TypeError, e:
+ raise RuntimeError("Exception was not thrown")
+except TypeError as e:
# fastdispatch mode adds on Additional Information to the exception message - just check the main exception message exists
- if str(e).startswith("SWIG director type mismatch in output value of type 'std::string'"):
- ok = 1
- else:
- print "Unexpected error message: %s" % str(e)
-if not ok:
- raise RuntimeError
+ if not str(e).startswith("SWIG director type mismatch in output value of type 'std::string'"):
+ raise RuntimeError("Unexpected error message: %s" % str(e))
# Check that the director can return an exception which requires two arguments
# to the constructor, without mangling it.
-ok = 0
a = MyFoo3()
b = launder(a)
try:
b.pong()
-except MyException, e:
- if e.msg == "foobar":
- ok = 1
- else:
- print "Unexpected error message: %s" % str(e)
-if not ok:
- raise RuntimeError
+ raise RuntimeError("Exception was not thrown")
+except MyException as e:
+ if e.msg != "foobar":
+ raise RuntimeError("Unexpected error message: %s" % str(e))
# Check that the director returns the appropriate TypeError thrown in a director method
-ok = 0
a = MyFoo4()
b = launder(a)
try:
b.pong()
+ raise RuntimeError("Exception was not thrown")
except TypeError as e:
- if str(e).startswith("type() takes 1 or 3 arguments"):
- ok = 1
- else:
- print "Unexpected error message: %s" % str(e)
-if not ok:
- raise RuntimeError
+ if not str(e).startswith("type() takes 1 or 3 arguments"):
+ raise RuntimeError("Unexpected error message: %s" % str(e))
# This is expected to fail with -builtin option
diff --git a/Examples/test-suite/python/director_extend_runme.py b/Examples/test-suite/python/director_extend_runme.py
index a5aad8245..870443d1f 100644
--- a/Examples/test-suite/python/director_extend_runme.py
+++ b/Examples/test-suite/python/director_extend_runme.py
@@ -17,6 +17,6 @@ class MyObject(SpObject):
m = MyObject()
if m.dummy() != 666:
- raise RuntimeError, "1st call"
+ raise RuntimeError("1st call")
if m.dummy() != 666: # Locked system
- raise RuntimeError, "2nd call"
+ raise RuntimeError("2nd call")
diff --git a/Examples/test-suite/python/director_frob_runme.py b/Examples/test-suite/python/director_frob_runme.py
index 0ef4ad900..6c8fcad06 100644
--- a/Examples/test-suite/python/director_frob_runme.py
+++ b/Examples/test-suite/python/director_frob_runme.py
@@ -4,4 +4,4 @@ foo = Bravo()
s = foo.abs_method()
if s != "Bravo::abs_method()":
- raise RuntimeError, s
+ raise RuntimeError(s)
diff --git a/Examples/test-suite/python/director_multiple_inheritance_runme.py b/Examples/test-suite/python/director_multiple_inheritance_runme.py
new file mode 100644
index 000000000..8c8ea0bf6
--- /dev/null
+++ b/Examples/test-suite/python/director_multiple_inheritance_runme.py
@@ -0,0 +1,36 @@
+import director_multiple_inheritance as st
+
+class TestBCD(st.B, st.C, st.D):
+ def __init__(self):
+ st.B.__init__(self)
+ st.C.__init__(self)
+ st.D.__init__(self)
+
+class TestBDC(st.B, st.C, st.D):
+ def __init__(self):
+ st.B.__init__(self)
+ st.D.__init__(self)
+ st.C.__init__(self)
+
+class TestCBD(st.B, st.C, st.D):
+ def __init__(self):
+ st.C.__init__(self)
+ st.B.__init__(self)
+ st.D.__init__(self)
+
+def dotest(test):
+ e = st.E()
+ if e.testE(test) != 5:
+ raise RuntimeError(e.testE(test))
+
+ f = st.F()
+ if f.testF(test) != 6:
+ raise RuntimeError(f.testF(test))
+
+ t = st.T()
+ if t.testT(test) != 20:
+ raise RuntimeError(t.testT(test))
+
+dotest(TestBCD())
+dotest(TestCBD())
+dotest(TestBDC())
diff --git a/Examples/test-suite/python/director_nested_runme.py b/Examples/test-suite/python/director_nested_runme.py
index f3d973630..24216f9dd 100644
--- a/Examples/test-suite/python/director_nested_runme.py
+++ b/Examples/test-suite/python/director_nested_runme.py
@@ -14,7 +14,7 @@ class A(FooBar_int):
a = A()
if a.step() != "Bar::step;Foo::advance;Bar::do_advance;A::do_step;":
- raise RuntimeError, "Bad A virtual resolution"
+ raise RuntimeError("Bad A virtual resolution")
class B(FooBar_int):
@@ -34,7 +34,7 @@ class B(FooBar_int):
b = B()
if b.step() != "Bar::step;Foo::advance;B::do_advance;B::do_step;":
- raise RuntimeError, "Bad B virtual resolution"
+ raise RuntimeError("Bad B virtual resolution")
class C(FooBar_int):
@@ -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/director_pass_by_value_runme.py b/Examples/test-suite/python/director_pass_by_value_runme.py
index 7744db962..9dbd64ad6 100644
--- a/Examples/test-suite/python/director_pass_by_value_runme.py
+++ b/Examples/test-suite/python/director_pass_by_value_runme.py
@@ -8,6 +8,8 @@ class director_pass_by_value_Derived(director_pass_by_value.DirectorPassByValueA
# bug was the passByVal global object was destroyed after the call to virtualMethod had finished.
director_pass_by_value.Caller().call_virtualMethod(director_pass_by_value_Derived())
+if director_pass_by_value.has_cplusplus11():
+ director_pass_by_value.Counter.check_counts(1, 0, 0, 1, 0, 1) # check move constructor called and just one destructor
ret = passByVal.getVal();
if ret != 0x12345678:
raise RuntimeError("Bad return value, got " + hex(ret))
diff --git a/Examples/test-suite/python/director_profile_runme.py b/Examples/test-suite/python/director_profile_runme.py
index 035007c61..7c269c3f7 100644
--- a/Examples/test-suite/python/director_profile_runme.py
+++ b/Examples/test-suite/python/director_profile_runme.py
@@ -38,4 +38,4 @@ while i:
a = fi(a) # 20
i -= 1
-print a
+print("a: {}".format(a))
diff --git a/Examples/test-suite/python/director_property_runme.py b/Examples/test-suite/python/director_property_runme.py
index 5d713c27f..2fa41968c 100644
--- a/Examples/test-suite/python/director_property_runme.py
+++ b/Examples/test-suite/python/director_property_runme.py
@@ -14,6 +14,43 @@ foo.setA("BLABLA")
if foo.getA() != "BLABLA":
raise RuntimeError
+# test property addition in PyFoo
+if foo.a != "BLABLA":
+ raise RuntimeError
+
foo.a = "BIBI"
if foo.a != "BIBI":
raise RuntimeError
+if foo.getA() != "BIBI":
+ raise RuntimeError
+
+
+
+class MyFoo(director_property.Foo):
+ def setA(self, a):
+ director_property.Foo.setA(self, a + " set from MyFoo")
+ def setAByRef(self, a):
+ director_property.Foo.setA(self, a + " setAByRef from MyFoo")
+
+a = MyFoo()
+if (a.getA() != ""):
+ raise RuntimeError("Test failed")
+a.setA("Hello")
+if (a.getA() != "Hello set from MyFoo"):
+ raise RuntimeError("Test failed")
+a.setAByRef("Hello")
+if (a.getA() != "Hello setAByRef from MyFoo"):
+ raise RuntimeError("Test failed")
+del a
+
+a_original = MyFoo()
+a = director_property.Foo.get_self(a_original)
+if (a.getA() != ""):
+ raise RuntimeError("Test failed")
+a.setA("Hello")
+if (a.getA() != "Hello set from MyFoo"):
+ raise RuntimeError("Test failed")
+a.setAByRef("Hello")
+if (a.getA() != "Hello setAByRef from MyFoo"):
+ raise RuntimeError("Test failed")
+del a
diff --git a/Examples/test-suite/python/director_protected_runme.py b/Examples/test-suite/python/director_protected_runme.py
index c3118a7c0..94eab69a6 100644
--- a/Examples/test-suite/python/director_protected_runme.py
+++ b/Examples/test-suite/python/director_protected_runme.py
@@ -35,7 +35,7 @@ try:
raise RuntimeError
pass
except:
- raise RuntimeError, "bad FooBar::used"
+ raise RuntimeError("bad FooBar::used")
try:
s = fb2.used()
@@ -43,7 +43,7 @@ try:
raise RuntimeError
pass
except:
- raise RuntimeError, "bad FooBar2::used"
+ raise RuntimeError("bad FooBar2::used")
try:
s = b.pong()
@@ -51,7 +51,7 @@ try:
raise RuntimeError
pass
except:
- raise RuntimeError, "bad Bar::pong"
+ raise RuntimeError("bad Bar::pong")
try:
s = f.pong()
@@ -59,7 +59,7 @@ try:
raise RuntimeError
pass
except:
- raise RuntimeError, " bad Foo::pong"
+ raise RuntimeError(" bad Foo::pong")
try:
s = fb.pong()
@@ -67,7 +67,7 @@ try:
raise RuntimeError
pass
except:
- raise RuntimeError, " bad FooBar::pong"
+ raise RuntimeError(" bad FooBar::pong")
protected = 1
try:
@@ -76,7 +76,7 @@ try:
except:
pass
if not protected:
- raise RuntimeError, "Foo::ping is protected"
+ raise RuntimeError("Foo::ping is protected")
protected = 1
try:
@@ -85,7 +85,7 @@ try:
except:
pass
if not protected:
- raise RuntimeError, "Foo::ping is protected"
+ raise RuntimeError("Foo::ping is protected")
protected = 1
@@ -95,7 +95,7 @@ try:
except:
pass
if not protected:
- raise RuntimeError, "FooBar::pang is protected"
+ raise RuntimeError("FooBar::pang is protected")
protected = 1
@@ -105,7 +105,7 @@ try:
except:
pass
if not protected:
- raise RuntimeError, "Bar::cheer is protected"
+ raise RuntimeError("Bar::cheer is protected")
protected = 1
try:
@@ -114,19 +114,19 @@ try:
except:
pass
if not protected:
- raise RuntimeError, "Foo::cheer is protected"
+ raise RuntimeError("Foo::cheer is protected")
if fb3.cheer() != "FooBar3::cheer();":
- raise RuntimeError, "bad fb3::cheer"
+ raise RuntimeError("bad fb3::cheer")
if fb2.callping() != "FooBar2::ping();":
- raise RuntimeError, "bad fb2.callping"
+ raise RuntimeError("bad fb2.callping")
if fb2.callcheer() != "FooBar2::pang();Bar::pong();Foo::pong();FooBar2::ping();":
- raise RuntimeError, "bad fb2.callcheer"
+ raise RuntimeError("bad fb2.callcheer")
if fb3.callping() != "Bar::ping();":
- raise RuntimeError, "bad fb3.callping"
+ raise RuntimeError("bad fb3.callping")
if fb3.callcheer() != "FooBar3::cheer();":
- raise RuntimeError, "bad fb3.callcheer"
+ raise RuntimeError("bad fb3.callcheer")
diff --git a/Examples/test-suite/python/director_smartptr_runme.py b/Examples/test-suite/python/director_smartptr_runme.py
index 23e22d0fb..b4cbafe32 100644
--- a/Examples/test-suite/python/director_smartptr_runme.py
+++ b/Examples/test-suite/python/director_smartptr_runme.py
@@ -31,7 +31,7 @@ class director_smartptr_MyBarFooDerived(FooDerived):
def check(got, expected):
if (got != expected):
- raise RuntimeError, "Failed, got: " + got + " expected: " + expected
+ raise RuntimeError("Failed, got: " + got + " expected: " + expected)
fooBar = FooBar()
diff --git a/Examples/test-suite/python/director_string_runme.py b/Examples/test-suite/python/director_string_runme.py
index dcd47d647..74d2edb7b 100644
--- a/Examples/test-suite/python/director_string_runme.py
+++ b/Examples/test-suite/python/director_string_runme.py
@@ -16,14 +16,16 @@ class B(A):
b = B("hello")
-b.get(0)
+if b.get(0) != "hello":
+ raise RuntimeError("b.get(0): {}".format(b.get(0)))
+
if b.get_first() != "hello world!":
- print b.get_first()
- raise RuntimeError
+ raise RuntimeError("b.get_first(): {}".format(b.get_first()))
+if b.call_get_first() != "hello world!":
+ raise RuntimeError("b.call_get_first(): {}".format(b.call_get_first()))
b.call_process_func()
if b.smem != "hello":
- print smem
- raise RuntimeError
+ raise RuntimeError("smem: {}".format(smem))
diff --git a/Examples/test-suite/python/director_thread_runme.py b/Examples/test-suite/python/director_thread_runme.py
index 4fcf3bfd1..21a8ce1b0 100644
--- a/Examples/test-suite/python/director_thread_runme.py
+++ b/Examples/test-suite/python/director_thread_runme.py
@@ -14,7 +14,6 @@ d = Derived()
d.run()
if d.val >= 0:
- print d.val
- raise RuntimeError
+ raise RuntimeError("d.val: {}".format(d.val))
d.stop()
diff --git a/Examples/test-suite/python/director_unroll_runme.py b/Examples/test-suite/python/director_unroll_runme.py
index 60bc05585..ea602d8e2 100644
--- a/Examples/test-suite/python/director_unroll_runme.py
+++ b/Examples/test-suite/python/director_unroll_runme.py
@@ -16,5 +16,4 @@ c = b.get()
if not (a.this == c.this):
- print a, c
- raise RuntimeError
+ raise RuntimeError("{} {}".format(a, c))
diff --git a/Examples/test-suite/python/director_wstring_runme.py b/Examples/test-suite/python/director_wstring_runme.py
index 242b27582..659cf1854 100644
--- a/Examples/test-suite/python/director_wstring_runme.py
+++ b/Examples/test-suite/python/director_wstring_runme.py
@@ -7,22 +7,36 @@ class B(A):
A.__init__(self, string)
def get_first(self):
- return A.get_first(self) + u" world!"
+ return A.get_first(self) + " world!"
- def process_text(self, string):
- self.smem = u"hello"
+ def process_text(self, s):
+ self.smem = s
+ def process_wstring_text(self, s):
+ self.smem = s + " (wstring)"
-b = B(u"hello")
+ def process_wstring_ref_text(self, s):
+ self.smem = s + " (wstring ref)"
+
+
+b = B("hello")
b.get(0)
-if b.get_first() != u"hello world!":
- print b.get_first()
- raise RuntimeError
+if b.get_first() != "hello world!":
+ raise RuntimeError("b.get_first(): {}".format(b.get_first()))
b.call_process_func()
-if b.smem != u"hello":
- print smem
- raise RuntimeError
+if b.smem != "hello":
+ raise RuntimeError("smem: {}".format(smem))
+
+b.call_process_wstring_func()
+
+if b.smem != "hello (wstring)":
+ raise RuntimeError("smem: {}".format(smem))
+
+b.call_process_wstring_ref_func()
+
+if b.smem != "hello (wstring ref)":
+ raise RuntimeError("smem: {}".format(smem))
diff --git a/Examples/test-suite/python/doxygen_autodoc_docstring_runme.py b/Examples/test-suite/python/doxygen_autodoc_docstring_runme.py
new file mode 100644
index 000000000..9780516b9
--- /dev/null
+++ b/Examples/test-suite/python/doxygen_autodoc_docstring_runme.py
@@ -0,0 +1,44 @@
+from doxygen_autodoc_docstring import *
+import inspect
+import string
+import os
+import sys
+import comment_verifier
+
+# documentation from autogenerated 'feature:autodoc'
+comment_verifier.check(inspect.getdoc(ClassWithoutDoxygenComment),
+ "::ClassWithoutDoxygenComment" if is_python_builtin() else "Proxy of C++ ClassWithoutDoxygenComment class.")
+comment_verifier.check(inspect.getdoc(functionWithoutDoxygenComment),
+ "functionWithoutDoxygenComment(int number)")
+
+# documentation from doxygen comments
+comment_verifier.check(inspect.getdoc(ClassWithDoxygenComment),
+ "Class doxygen comment")
+comment_verifier.check(inspect.getdoc(functionWithDoxygenComment),
+ "Function doxygen comment")
+
+# documentation from 'feature:docstring'
+comment_verifier.check(inspect.getdoc(ClassWithDocString),
+ "Class doc from docstring")
+comment_verifier.check(inspect.getdoc(functionWithDocString),
+ "functionWithDocString(int number)\n"
+ "Function doc from docstring")
+
+# documentation from 'feature:docstring' + autodoc (overriding doxycomment)
+comment_verifier.check(inspect.getdoc(ClassWithDocStringAndDoxygenComment),
+ "Class doc from docstring overriding doxycomment")
+comment_verifier.check(inspect.getdoc(functionWithDocStringAndDoxygenComment),
+ "functionWithDocStringAndDoxygenComment(int number)\n"
+ "Function doc from docstring overriding doxycomment")
+
+# documentation from 'feature:docstring' (overriding doxycomment)
+comment_verifier.check(inspect.getdoc(ClassWithDocStringAndDoxygenCommentNoAutodoc),
+ "Class doc from docstring overriding doxycomment (no autodoc)")
+comment_verifier.check(inspect.getdoc(functionWithDocStringAndDoxygenCommentNoAutodoc),
+ "Function doc from docstring overriding doxycomment (no autodoc)")
+
+# documentation from doxygen comments (2) no autodoc feature present
+comment_verifier.check(inspect.getdoc(ClassWithDoxygenComment2),
+ "Class doxygen comment 2")
+comment_verifier.check(inspect.getdoc(functionWithDoxygenComment2),
+ "Function doxygen comment 2")
diff --git a/Examples/test-suite/python/doxygen_basic_translate_runme.py b/Examples/test-suite/python/doxygen_basic_translate_runme.py
index 9ef8dbd52..4cd500178 100644
--- a/Examples/test-suite/python/doxygen_basic_translate_runme.py
+++ b/Examples/test-suite/python/doxygen_basic_translate_runme.py
@@ -60,7 +60,7 @@ comment_verifier.check(inspect.getdoc(doxygen_basic_translate.function5),
comment_verifier.check(inspect.getdoc(doxygen_basic_translate.function6),
"""\
Test for default args
-:type a: int
+:type a: int, optional
:param a: Some parameter, default is 42"""
)
comment_verifier.check(inspect.getdoc(doxygen_basic_translate.function7),
@@ -70,6 +70,16 @@ Test for a parameter with difficult type
:type a: :py:class:`Shape`
:param a: Very strange param"""
)
+comment_verifier.check(inspect.getdoc(doxygen_basic_translate.function8),
+ """\
+Test variadic function
+:param ...: extra args"""
+)
+comment_verifier.check(inspect.getdoc(doxygen_basic_translate.function9),
+ """\
+Test unnamed argument
+:param baz: Description of baz"""
+)
comment_verifier.check(inspect.getdoc(doxygen_basic_translate.Atan2),
"""\
diff --git a/Examples/test-suite/python/doxygen_basic_translate_style2_runme.py b/Examples/test-suite/python/doxygen_basic_translate_style2_runme.py
index b75045d59..a24f5defc 100644
--- a/Examples/test-suite/python/doxygen_basic_translate_style2_runme.py
+++ b/Examples/test-suite/python/doxygen_basic_translate_style2_runme.py
@@ -58,7 +58,7 @@ comment_verifier.check(inspect.getdoc(doxygen_basic_translate_style2.function5),
comment_verifier.check(inspect.getdoc(doxygen_basic_translate_style2.function6),
"""\
Test for default args
-:type a: int
+:type a: int, optional
:param a: Some parameter, default is 42"""
)
comment_verifier.check(inspect.getdoc(doxygen_basic_translate_style2.function7),
diff --git a/Examples/test-suite/python/doxygen_basic_translate_style3_runme.py b/Examples/test-suite/python/doxygen_basic_translate_style3_runme.py
new file mode 100644
index 000000000..687270351
--- /dev/null
+++ b/Examples/test-suite/python/doxygen_basic_translate_style3_runme.py
@@ -0,0 +1,82 @@
+import doxygen_basic_translate_style3
+import inspect
+import string
+import sys
+import comment_verifier
+
+comment_verifier.check(inspect.getdoc(doxygen_basic_translate_style3.function),
+ """\
+Brief description.
+
+The comment text.
+
+Author: Some author
+
+:rtype: int
+:return: Some number
+
+See also: function2"""
+)
+comment_verifier.check(inspect.getdoc(doxygen_basic_translate_style3.function2),
+ """\
+A test of a very very very very very very very very very very very very very very very very
+very very very very very long comment string."""
+)
+comment_verifier.check(inspect.getdoc(doxygen_basic_translate_style3.function3),
+ """*Overload 1:*
+A test for overloaded functions
+This is function **one**
+
+|
+
+*Overload 2:*
+A test for overloaded functions
+This is function **two**"""
+)
+comment_verifier.check(inspect.getdoc(doxygen_basic_translate_style3.function4),
+ """\
+A test of some mixed tag usage
+If: CONDITION {
+This *code* fragment shows us something .
+Title: Minuses:
+* it\'s senseless
+* it\'s stupid
+* it\'s null
+
+Warning: This may not work as expected
+
+.. code-block:: c++
+
+ int main() { while(true); }
+
+ int testBlankLine() {}
+}"""
+)
+comment_verifier.check(inspect.getdoc(doxygen_basic_translate_style3.function5),
+ """This is a post comment."""
+)
+comment_verifier.check(inspect.getdoc(doxygen_basic_translate_style3.function6),
+ """\
+Test for default args
+:type a: int, optional
+:param a: Some parameter, default is 42"""
+)
+comment_verifier.check(inspect.getdoc(doxygen_basic_translate_style3.function7),
+ """\
+Test for a parameter with difficult type
+(mostly for python)
+:type a: :py:class:`Shape`
+:param a: Very strange param"""
+)
+
+comment_verifier.check(inspect.getdoc(doxygen_basic_translate_style3.Atan2),
+ """\
+Multiple parameters test.
+
+:type y: float
+:param y: Vertical coordinate.
+:type x: float
+:param x: Horizontal coordinate.
+:rtype: float
+:return: Arc tangent of ``y/x``."""
+)
diff --git a/Examples/test-suite/python/doxygen_code_blocks_runme.py b/Examples/test-suite/python/doxygen_code_blocks_runme.py
new file mode 100644
index 000000000..46a0a3d84
--- /dev/null
+++ b/Examples/test-suite/python/doxygen_code_blocks_runme.py
@@ -0,0 +1,58 @@
+import doxygen_code_blocks
+import inspect
+import string
+import sys
+import comment_verifier
+
+comment_verifier.check(inspect.getdoc(doxygen_code_blocks.function),
+ """\
+Test for code blocks
+
+.. code-block:: c++
+
+ simple code block
+
+More advanced usage with C++ characters:
+
+.. code-block:: c++
+
+ std::vector<int> first; // empty vector of ints
+ std::vector<int> second (4,100); // four ints with value 100
+ std::vector<int> third (second.begin(),second.end()); // iterating through second
+ std::vector<int> fourth (third); // a copy of third
+ // the iterator constructor can also be used to construct from arrays:
+ int myints[] = {16,2,77,29};
+ std::vector<int> fifth (myints, myints + sizeof(myints) / sizeof(int) );
+
+ std::cout << "The contents of fifth are:";
+ for (std::vector<int>::iterator it = fifth.begin(); it != fifth.end(); ++it)
+ std::cout << ' ' << *it;
+ std::cout << '\\n';
+
+A code block for C:
+
+.. code-block:: c
+
+ printf("hello world");
+
+A code block for Java:
+
+.. code-block:: java
+
+ public class HelloWorld {
+ public static void main(String[] args) {
+ // Prints "Hello, World" to the terminal window.
+ System.out.println("Hello, World");
+ }
+ }
+
+A code block for python:
+
+.. code-block:: python
+
+ print('hello world')
+
+A python doctest example:
+
+>>> 1 + 1
+2""")
diff --git a/Examples/test-suite/python/doxygen_misc_constructs_runme.py b/Examples/test-suite/python/doxygen_misc_constructs_runme.py
index 11aa53ba3..44f607fee 100644
--- a/Examples/test-suite/python/doxygen_misc_constructs_runme.py
+++ b/Examples/test-suite/python/doxygen_misc_constructs_runme.py
@@ -12,7 +12,7 @@ comment_verifier.check(inspect.getdoc(doxygen_misc_constructs.getAddress),
:param fileName: name of the file, where the source line is located
:type line: int
:param line: line number
-:type isGetSize: boolean
+:type isGetSize: boolean, optional
:param isGetSize: if set, for every object location both address and size are returned
Connection::getId() """)
@@ -131,3 +131,13 @@ Spaces at the start of line should be taken into account:
:type fileName: string
:param fileName: name of the log file"""
);
+
+comment_verifier.check(inspect.getdoc(doxygen_misc_constructs.doc_ends_with_quote),
+ r'''This doc comment ends with a quote: "and that's ok"'''
+);
+
+comment_verifier.check(inspect.getdoc(doxygen_misc_constructs.doc_with_triple_quotes),
+ r'''This comment contains embedded triple-quoted string:
+
+ """How quaint"""'''
+);
diff --git a/Examples/test-suite/python/doxygen_translate_all_tags_runme.py b/Examples/test-suite/python/doxygen_translate_all_tags_runme.py
index df1c0eba5..e884cf9ef 100644
--- a/Examples/test-suite/python/doxygen_translate_all_tags_runme.py
+++ b/Examples/test-suite/python/doxygen_translate_all_tags_runme.py
@@ -82,7 +82,7 @@ r"""Comment for **func03()**.
*italicword*
-emphazedWord
+*emphazedWord*
@@ -175,7 +175,7 @@ This will only appear in LATeX
-someMember Some description follows
+someMember Some description follows with text after
@@ -196,7 +196,7 @@ is the note!
This is an overloaded member function, provided for convenience.
It differs from the above function only in what argument(s) it accepts.
-someword
+``someword``
@@ -209,7 +209,13 @@ Maybe even multiline
:type a: int
-:param a: the first param""")
+:param a: the first param
+:type b: int, in
+:param b: parameter with intent(in)
+:type c: int, out
+:param c: parameter with intent(out)
+:type d: int, in/out
+:param d: parameter with intent(in,out)""")
comment_verifier.check(inspect.getdoc(doxygen_translate_all_tags.func08),
r"""Text after anchor.
diff --git a/Examples/test-suite/python/doxygen_translate_runme.py b/Examples/test-suite/python/doxygen_translate_runme.py
index d698ba873..a62df4a1d 100644
--- a/Examples/test-suite/python/doxygen_translate_runme.py
+++ b/Examples/test-suite/python/doxygen_translate_runme.py
@@ -58,6 +58,7 @@ If not: SOMECONDITION {
}
Image: testImage.bmp("Hello, world!")
+Image: "test image.jpg"("Test jpeg")
@@ -80,7 +81,7 @@ is the note!
This is an overloaded member function, provided for convenience.
It differs from the above function only in what argument(s) it accepts.
-someword
+``someword``
diff --git a/Examples/test-suite/python/dynamic_cast_runme.py b/Examples/test-suite/python/dynamic_cast_runme.py
index 59e86d34c..ae080833b 100644
--- a/Examples/test-suite/python/dynamic_cast_runme.py
+++ b/Examples/test-suite/python/dynamic_cast_runme.py
@@ -8,4 +8,4 @@ y = b.blah()
a = dynamic_cast.do_test(y)
if a != "Bar::test":
- print "Failed!!"
+ raise RuntimeError("Failed!!")
diff --git a/Examples/test-suite/python/exception_order_runme.py b/Examples/test-suite/python/exception_order_runme.py
index c53521e3e..5c1529999 100644
--- a/Examples/test-suite/python/exception_order_runme.py
+++ b/Examples/test-suite/python/exception_order_runme.py
@@ -9,36 +9,35 @@ a = A()
try:
a.foo()
-except E1, e:
+except E1 as e:
pass
except:
- raise RuntimeError, "bad exception order"
+ raise RuntimeError("bad exception order")
try:
a.bar()
-except E2, e:
+except E2 as e:
pass
except:
- raise RuntimeError, "bad exception order"
+ raise RuntimeError("bad exception order")
try:
a.foobar()
-except RuntimeError, e:
+except RuntimeError as e:
if e.args[0] != "postcatch unknown":
- print "bad exception order",
- raise RuntimeError, e.args
+ raise RuntimeError("bad exception order {}".format(e.args))
try:
a.barfoo(1)
-except E1, e:
+except E1 as e:
pass
except:
- raise RuntimeError, "bad exception order"
+ raise RuntimeError("bad exception order")
try:
a.barfoo(2)
-except E2, e:
+except E2 as e:
pass
except:
- raise RuntimeError, "bad exception order"
+ raise RuntimeError("bad exception order")
diff --git a/Examples/test-suite/python/extern_c_runme.py b/Examples/test-suite/python/extern_c_runme.py
index 91a218a87..c30509d07 100644
--- a/Examples/test-suite/python/extern_c_runme.py
+++ b/Examples/test-suite/python/extern_c_runme.py
@@ -1,3 +1,10 @@
import extern_c
+def check(flag):
+ if not flag:
+ raise RuntimeError("Test failed")
+
extern_c.RealFunction(2)
+check(extern_c.cvar.int2 == 123)
+check(extern_c.cvar.int3 == 456)
+check(extern_c.cvar.int4 == 789)
diff --git a/Examples/test-suite/python/final_c_runme.py b/Examples/test-suite/python/final_c_runme.py
new file mode 100644
index 000000000..9ef4ded62
--- /dev/null
+++ b/Examples/test-suite/python/final_c_runme.py
@@ -0,0 +1,6 @@
+import final_c
+
+final_c.init()
+f = final_c.cvar.final
+if (f.yval != 123):
+ raise RuntimeError("f.yval fail")
diff --git a/Examples/test-suite/python/friends_operator_overloading_runme.py b/Examples/test-suite/python/friends_operator_overloading_runme.py
new file mode 100644
index 000000000..2b0975537
--- /dev/null
+++ b/Examples/test-suite/python/friends_operator_overloading_runme.py
@@ -0,0 +1,41 @@
+import friends_operator_overloading
+
+friends_operator_overloading.sanity_checker_ShiftA()
+friends_operator_overloading.sanity_checker_ShiftB()
+
+sa1 = friends_operator_overloading.ShiftA(200)
+sa2 = friends_operator_overloading.ShiftA(1000)
+sb1 = friends_operator_overloading.ShiftB(200)
+sb2 = friends_operator_overloading.ShiftB(1000)
+
+# Shift operator via members
+sa3 = sa2 << sa1
+val = sa3.getVal()
+if val != 800:
+ raise RuntimeError("Wrong val: {}".format(val))
+
+sa4 = sa2 << 300
+val = sa4.getVal()
+if val != 700:
+ raise RuntimeError("Wrong val: {}".format(val))
+
+sb3 = sb2 << sb1
+val = sb3.getVal()
+if val != 800:
+ raise RuntimeError("Wrong val: {}".format(val))
+
+sb4 = sb2 << 300
+val = sb4.getVal()
+if val != 700:
+ raise RuntimeError("Wrong val: {}".format(val))
+
+# Shift operator via global wrapper
+shift = friends_operator_overloading.__lshift__(sa2, sa1)
+val = shift.getVal()
+if val != 800:
+ raise RuntimeError("Wrong val: {}".format(val))
+
+shift = friends_operator_overloading.__lshift__(sb2, sb1)
+val = shift.getVal()
+if val != 800:
+ raise RuntimeError("Wrong val: {}".format(val))
diff --git a/Examples/test-suite/python/friends_runme.py b/Examples/test-suite/python/friends_runme.py
index 2d377fdd1..29a385b9b 100644
--- a/Examples/test-suite/python/friends_runme.py
+++ b/Examples/test-suite/python/friends_runme.py
@@ -1,5 +1,9 @@
import friends
+def check_equal(a, b):
+ if a != b:
+ raise RuntimeError("Not equal {} != {}".format(a, b))
+
a = friends.A(2)
if friends.get_val1(a) != 2:
@@ -19,7 +23,7 @@ b = friends.B(3)
if friends.mix(a, b) != 5:
raise RuntimeError
-di = friends.D_d(2)
+di = friends.D_i(2)
dd = friends.D_d(3.3)
# incredible template overloading working just fine
@@ -35,3 +39,19 @@ if friends.get_val1(di) != 4:
raise RuntimeError
if friends.get_val1(dd) != 1.3:
raise RuntimeError
+
+if friends.chum_blah() != 1234:
+ raise RuntimeError("failed")
+if friends.mate_blah() != 4321:
+ raise RuntimeError("failed")
+
+foe = friends.Foe(111)
+check_equal(friends.friend_definition(), 10)
+check_equal(friends.friend_declaration(), 11)
+check_equal(friends.friend_args_definition(foe), 111)
+check_equal(friends.friend_args_declaration(foe), 111)
+
+check_equal(friends.friend_definition_compiler(), 20)
+check_equal(friends.friend_declaration_compiler(), 21)
+check_equal(friends.friend_args_definition_compiler(foe), 111)
+check_equal(friends.friend_args_declaration_compiler(foe), 111)
diff --git a/Examples/test-suite/python/fvirtual_runme.py b/Examples/test-suite/python/fvirtual_runme.py
index 99f5dc6b0..fe211b441 100644
--- a/Examples/test-suite/python/fvirtual_runme.py
+++ b/Examples/test-suite/python/fvirtual_runme.py
@@ -5,4 +5,4 @@ n = Node()
i = sw.addChild(n)
if i != 2:
- raise RuntimeError, "addChild"
+ raise RuntimeError("addChild")
diff --git a/Examples/test-suite/python/global_functions_runme.py b/Examples/test-suite/python/global_functions_runme.py
index f411261b6..4aab1b082 100644
--- a/Examples/test-suite/python/global_functions_runme.py
+++ b/Examples/test-suite/python/global_functions_runme.py
@@ -11,7 +11,7 @@ check(global_two(2, 2), 4)
fail = True
try:
global_void(1)
-except TypeError, e:
+except TypeError as e:
fail = False
if fail:
raise RuntimeError("argument count check failed")
@@ -19,7 +19,7 @@ if fail:
fail = True
try:
global_one()
-except TypeError, e:
+except TypeError as e:
fail = False
if fail:
raise RuntimeError("argument count check failed")
@@ -27,7 +27,7 @@ if fail:
fail = True
try:
global_one(2, 2)
-except TypeError, e:
+except TypeError as e:
fail = False
if fail:
@@ -36,7 +36,7 @@ if fail:
fail = True
try:
global_two(1)
-except TypeError, e:
+except TypeError as e:
fail = False
if fail:
@@ -45,7 +45,7 @@ if fail:
fail = True
try:
global_two(3, 3, 3)
-except TypeError, e:
+except TypeError as e:
fail = False
if fail:
diff --git a/Examples/test-suite/python/global_vars_runme.py b/Examples/test-suite/python/global_vars_runme.py
index 3ef0b494f..015519ec8 100644
--- a/Examples/test-suite/python/global_vars_runme.py
+++ b/Examples/test-suite/python/global_vars_runme.py
@@ -20,7 +20,7 @@ if x != 9876:
fail = True
try:
global_vars.cvar.notexist = "something"
-except AttributeError, e:
+except AttributeError as e:
fail = False
if fail:
raise RuntimeError("AttributeError should have been thrown")
@@ -28,7 +28,7 @@ if fail:
fail = True
try:
g = global_vars.cvar.notexist
-except AttributeError, e:
+except AttributeError as e:
fail = False
if fail:
raise RuntimeError("AttributeError should have been thrown")
diff --git a/Examples/test-suite/python/ignore_parameter_runme.py b/Examples/test-suite/python/ignore_parameter_runme.py
index 2b5c21235..0f40f96c8 100644
--- a/Examples/test-suite/python/ignore_parameter_runme.py
+++ b/Examples/test-suite/python/ignore_parameter_runme.py
@@ -16,6 +16,7 @@ check(car.astonmartin("foo", 1), 101)
check(car.bugatti("bar", 2), 8.8)
check(car.lamborghini(), 101)
check(car.maseratti(289), 289)
+check(car.audi(), 8.8) # Typemap overrides default argument
MiniCooper(200, 0)
MorrisMinor("baz", 0)
diff --git a/Examples/test-suite/python/import_stl_runme.py b/Examples/test-suite/python/import_stl_runme.py
index 69fe812b9..d0efbd083 100644
--- a/Examples/test-suite/python/import_stl_runme.py
+++ b/Examples/test-suite/python/import_stl_runme.py
@@ -3,4 +3,4 @@ import import_stl_a
v_new = import_stl_b.process_vector([1, 2, 3])
if v_new != (1, 2, 3, 4):
- raise RuntimeError, v_new
+ raise RuntimeError(v_new)
diff --git a/Examples/test-suite/python/inctest_runme.py b/Examples/test-suite/python/inctest_runme.py
index fa3492932..c2746560d 100644
--- a/Examples/test-suite/python/inctest_runme.py
+++ b/Examples/test-suite/python/inctest_runme.py
@@ -1,31 +1,21 @@
import inctest
-error = 0
try:
a = inctest.A()
except:
- print "didn't find A"
- print "therefore, I didn't include 'testdir/subdir1/hello.i'"
- error = 1
+ raise RuntimeError("didn't find A, therefore, I didn't include 'testdir/subdir1/hello.i'")
pass
try:
b = inctest.B()
except:
- print "didn't find B"
- print "therefore, I didn't include 'testdir/subdir2/hello.i'"
- error = 1
+ raise RuntimeError("didn't find B, therefore, I didn't include 'testdir/subdir2/hello.i'")
pass
-if error == 1:
- raise RuntimeError
-
# Check the import in subdirectory worked
if inctest.importtest1(5) != 15:
- print "import test 1 failed"
- raise RuntimeError
+ raise RuntimeError("import test 1 failed")
if inctest.importtest2("black") != "white":
- print "import test 2 failed"
- raise RuntimeError
+ raise RuntimeError("import test 2 failed")
diff --git a/Examples/test-suite/python/inherit_missing_runme.py b/Examples/test-suite/python/inherit_missing_runme.py
index 044c166fb..57a245e44 100644
--- a/Examples/test-suite/python/inherit_missing_runme.py
+++ b/Examples/test-suite/python/inherit_missing_runme.py
@@ -6,14 +6,14 @@ c = inherit_missing.Spam()
x = inherit_missing.do_blah(a)
if x != "Foo::blah":
- print "Whoa! Bad return", x
+ raise RuntimeError("Whoa! Bad return {}".format(x))
x = inherit_missing.do_blah(b)
if x != "Bar::blah":
- print "Whoa! Bad return", x
+ raise RuntimeError("Whoa! Bad return {}".format(x))
x = inherit_missing.do_blah(c)
if x != "Spam::blah":
- print "Whoa! Bad return", x
+ raise RuntimeError("Whoa! Bad return {}".format(x))
inherit_missing.delete_Foo(a)
diff --git a/Examples/test-suite/python/inplaceadd_runme.py b/Examples/test-suite/python/inplaceadd_runme.py
index 7f292cbb5..3d5a1fd40 100644
--- a/Examples/test-suite/python/inplaceadd_runme.py
+++ b/Examples/test-suite/python/inplaceadd_runme.py
@@ -3,8 +3,7 @@ a = inplaceadd.A(7)
a += 5
if a.val != 12:
- print a.val
- raise RuntimeError
+ raise RuntimeError("a.val: {}".format(a.val))
a -= 5
if a.val != 7:
diff --git a/Examples/test-suite/python/kwargs_feature_runme.py b/Examples/test-suite/python/kwargs_feature_runme.py
index a2d4731ab..677c9ebd8 100644
--- a/Examples/test-suite/python/kwargs_feature_runme.py
+++ b/Examples/test-suite/python/kwargs_feature_runme.py
@@ -15,13 +15,16 @@ 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 Foo.statfoo_onearg(x=4) != 8:
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 +34,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
@@ -79,3 +82,61 @@ if rfoo(n=11, x=22) != -11:
if rfoo(x=11, n=22) != 11:
raise RuntimeError
+
+# Extended constructors
+e = Extending0()
+e = Extending1(one=1)
+e = Extending1(1)
+e = Extending2(1, "two")
+e = Extending2(1, two="two")
+e = Extending2(two="two", one=1)
+e = ExtendingOptArgs1()
+e = ExtendingOptArgs1(1)
+e = ExtendingOptArgs2(one=1)
+e = ExtendingOptArgs2()
+e = ExtendingOptArgs2(one=1)
+e = ExtendingOptArgs2(two="two")
+e = ExtendingOptArgs2(two="two", one=1)
+
+# Invalid kwargs test
+h = Hello()
+try:
+ h = Hello(nonexistent=10)
+ raise RuntimeError("missed exception")
+except TypeError as e:
+ pass
+
+f = Foo(1)
+f = Foo(a=1)
+try:
+ f = Foo(nonexistent=10)
+ raise RuntimeError("missed exception")
+except TypeError as e:
+ pass
+
+try:
+ f = Foo(a=1, nonexistent=10)
+ raise RuntimeError("missed exception")
+except TypeError as e:
+ pass
+
+try:
+ f = Foo(1, nonexistent=10)
+ raise RuntimeError("missed exception")
+except TypeError as e:
+ pass
+
+# Varargs
+f = VarargConstructor(fmt="Ciao")
+f.vararg_method(fmt="Bonjour")
+try:
+ f = VarargConstructor(nonexistent="Ciao")
+ raise RuntimeError("missed exception")
+except TypeError as e:
+ pass
+
+try:
+ f.vararg_method(nonexistent="Bonjour")
+ raise RuntimeError("missed exception")
+except TypeError as e:
+ pass
diff --git a/Examples/test-suite/python/langobj_runme.py b/Examples/test-suite/python/langobj_runme.py
index b32d5a18a..ce1c9cdf3 100644
--- a/Examples/test-suite/python/langobj_runme.py
+++ b/Examples/test-suite/python/langobj_runme.py
@@ -2,7 +2,7 @@ import sys
from langobj import *
-x = "hello"
+x = 256*256+1
rx = sys.getrefcount(x)
v = identity(x)
rv = sys.getrefcount(v)
diff --git a/Examples/test-suite/python/li_attribute_runme.py b/Examples/test-suite/python/li_attribute_runme.py
index 80e793618..d26bf0b68 100644
--- a/Examples/test-suite/python/li_attribute_runme.py
+++ b/Examples/test-suite/python/li_attribute_runme.py
@@ -8,12 +8,10 @@ if aa.a != 1:
raise RuntimeError
aa.a = 3
if aa.a != 3:
- print aa.a
- raise RuntimeError
+ raise RuntimeError("aa.a: {}".format(aa.a))
if aa.b != 2:
- print aa.b
- raise RuntimeError
+ raise RuntimeError("aa.b: {}".format(aa.b))
aa.b = 5
if aa.b != 5:
raise RuntimeError
@@ -47,6 +45,9 @@ myClass = li_attribute.MyClass()
myClass.Foo = myFoo
if myClass.Foo.x != 8:
raise RuntimeError
+myClass.Foo2 = myFoo
+if myClass.Foo2.x != 8:
+ raise RuntimeError
# class/struct attribute with get/set methods using return/pass by value
myClassVal = li_attribute.MyClassVal()
@@ -77,7 +78,7 @@ if myStringyClass.ReadOnlyString != "changed string":
try:
x = myFoo.does_not_exist
raise RuntimeError
-except AttributeError, e:
+except AttributeError as e:
if str(e).find("does_not_exist") == -1:
raise RuntimeError
diff --git a/Examples/test-suite/python/li_attribute_template_runme.py b/Examples/test-suite/python/li_attribute_template_runme.py
index d33b12309..f0a774995 100644
--- a/Examples/test-suite/python/li_attribute_template_runme.py
+++ b/Examples/test-suite/python/li_attribute_template_runme.py
@@ -7,8 +7,7 @@ chell = li_attribute_template.Cintint(1, 2, 3)
def rassert(what, master):
if what != master:
- print what
- raise RuntimeError
+ raise RuntimeError("what: {}".format(what))
# Testing primitive by value attribute
rassert(chell.a, 1)
diff --git a/Examples/test-suite/python/li_boost_shared_ptr_director_runme.py b/Examples/test-suite/python/li_boost_shared_ptr_director_runme.py
index 52868eacc..b4382ca1e 100644
--- a/Examples/test-suite/python/li_boost_shared_ptr_director_runme.py
+++ b/Examples/test-suite/python/li_boost_shared_ptr_director_runme.py
@@ -1,5 +1,9 @@
from li_boost_shared_ptr_director import *
+def swig_assert_equal(a, b):
+ if a != b:
+ raise RuntimeError(str(a) + " != " + str(b))
+
class Derived(Base):
def __init__(self, flag):
self.return_none = flag
@@ -59,22 +63,22 @@ class Derived(Base):
a = Derived(False)
b = Derived(True)
-assert call_ret_c_shared_ptr(a) == 1
-assert call_ret_c_shared_ptr(b) == -1
-assert call_ret_c_by_value(a) == 1
-
-assert call_take_c_by_value(a) == 5
-assert call_take_c_by_ref(a) == 6
-assert call_take_c_by_pointer(a) == 7
-assert call_take_c_by_pointer_ref(a) == 8
-assert call_take_c_shared_ptr_by_value(a) == 9
-assert call_take_c_shared_ptr_by_ref(a) == 10
-assert call_take_c_shared_ptr_by_pointer(a) == 11
-assert call_take_c_shared_ptr_by_pointer_ref(a) == 12
-
-assert call_take_c_by_pointer_with_null(a) == -2
-assert call_take_c_by_pointer_ref_with_null(a) == -3
-assert call_take_c_shared_ptr_by_value_with_null(a) == -4
-assert call_take_c_shared_ptr_by_ref_with_null(a) == -5
-assert call_take_c_shared_ptr_by_pointer_with_null(a) == -6
-assert call_take_c_shared_ptr_by_pointer_ref_with_null(a) == -7
+swig_assert_equal(call_ret_c_shared_ptr(a), 1)
+swig_assert_equal(call_ret_c_shared_ptr(b), -1)
+swig_assert_equal(call_ret_c_by_value(a), 1)
+
+swig_assert_equal(call_take_c_by_value(a), 5)
+swig_assert_equal(call_take_c_by_ref(a), 6)
+swig_assert_equal(call_take_c_by_pointer(a), 7)
+swig_assert_equal(call_take_c_by_pointer_ref(a), 8)
+swig_assert_equal(call_take_c_shared_ptr_by_value(a), 9)
+swig_assert_equal(call_take_c_shared_ptr_by_ref(a), 10)
+swig_assert_equal(call_take_c_shared_ptr_by_pointer(a), 11)
+swig_assert_equal(call_take_c_shared_ptr_by_pointer_ref(a), 12)
+
+swig_assert_equal(call_take_c_by_pointer_with_null(a), -2)
+swig_assert_equal(call_take_c_by_pointer_ref_with_null(a), -3)
+swig_assert_equal(call_take_c_shared_ptr_by_value_with_null(a), -4)
+swig_assert_equal(call_take_c_shared_ptr_by_ref_with_null(a), -5)
+swig_assert_equal(call_take_c_shared_ptr_by_pointer_with_null(a), -6)
+swig_assert_equal(call_take_c_shared_ptr_by_pointer_ref_with_null(a), -7)
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 c960625ad..bde79fd61 100644
--- a/Examples/test-suite/python/li_boost_shared_ptr_runme.py
+++ b/Examples/test-suite/python/li_boost_shared_ptr_runme.py
@@ -10,7 +10,7 @@ class li_boost_shared_ptr_runme:
def main(self):
if (debug):
- print "Started"
+ print("Started")
li_boost_shared_ptr.cvar.debug_shared = debug
@@ -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())
@@ -32,7 +32,7 @@ class li_boost_shared_ptr_runme:
"shared_ptr wrapper count=%s" % wrapper_count)
if (debug):
- print "Finished"
+ print("Finished")
def runtest(self):
# simple shared_ptr usage - created in C++
@@ -168,6 +168,19 @@ class li_boost_shared_ptr_runme:
except ValueError:
pass
+ # test null pointers emitted from C++
+ k = li_boost_shared_ptr.sp_pointer_null()
+ if (li_boost_shared_ptr.smartpointertest(k) != None):
+ raise RuntimeError("return was not null")
+
+ k = li_boost_shared_ptr.null_sp_pointer()
+ if (li_boost_shared_ptr.smartpointertest(k) != None):
+ raise RuntimeError("return was not null")
+
+ k = li_boost_shared_ptr.sp_value_null()
+ if (li_boost_shared_ptr.smartpointertest(k) != None):
+ raise RuntimeError("return was not null")
+
# $owner
k = li_boost_shared_ptr.pointerownertest()
val = k.getValue()
diff --git a/Examples/test-suite/python/li_constraints_runme.py b/Examples/test-suite/python/li_constraints_runme.py
new file mode 100644
index 000000000..72ba22d9a
--- /dev/null
+++ b/Examples/test-suite/python/li_constraints_runme.py
@@ -0,0 +1,54 @@
+import li_constraints
+
+def check_double(et, fn, f, val):
+ actual = True
+ proper = False
+ try:
+ fn(val)
+ except ValueError as e:
+ actual = False
+ proper = "Expected a " + f + " value." == "%s"%(e)
+ if actual:
+ if not et:
+ raise Exception("function '%s' with %d should perform an exception"%(f, val))
+ else:
+ if et:
+ raise Exception("function '%s' with %d should not perform an exception"%(f, val))
+ elif not proper:
+ raise Exception("function '%s' with %d should perform a proper exception"%(f, val))
+ pass
+
+nonnegative = lambda v : li_constraints.test_nonnegative(v)
+check_double(True, nonnegative, "non-negative", 10)
+check_double(True, nonnegative, "non-negative", 0)
+check_double(False, nonnegative, "non-negative", -10)
+
+nonpositive = lambda v : li_constraints.test_nonpositive(v)
+check_double(False, nonpositive, "non-positive", 10)
+check_double(True, nonpositive, "non-positive", 0)
+check_double(True, nonpositive, "non-positive", -10)
+
+positive = lambda v : li_constraints.test_positive(v)
+check_double(True, positive, "positive", 10)
+check_double(False, positive, "positive", 0)
+check_double(False, positive, "positive", -10)
+
+negative = lambda v : li_constraints.test_negative(v)
+check_double(False, negative, "negative", 10)
+check_double(False, negative, "negative", 0)
+check_double(True, negative, "negative", -10)
+
+nonzero = lambda v : li_constraints.test_nonzero(v)
+check_double(True, nonzero, "nonzero", 10)
+check_double(False, nonzero, "nonzero", 0)
+check_double(True, nonzero, "nonzero", -10)
+
+have_exception = False
+try:
+ li_constraints.test_nonnull(None)
+except ValueError as e:
+ have_exception = "Received a NULL pointer." == "%s"%(e)
+if not have_exception:
+ raise Exception("test_nonnull should perform exception with 'null' value")
+nonnull = li_constraints.get_nonnull()
+li_constraints.test_nonnull(nonnull)
diff --git a/Examples/test-suite/python/li_cstring_runme.py b/Examples/test-suite/python/li_cstring_runme.py
index b718f1352..d22fc261b 100644
--- a/Examples/test-suite/python/li_cstring_runme.py
+++ b/Examples/test-suite/python/li_cstring_runme.py
@@ -11,12 +11,10 @@ if test2() != " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^
raise RuntimeError
if test3("hello") != "hello-suffix":
- print test3("hello")
- raise RuntimeError
+ raise RuntimeError("test3(\"hello\")")
if test4("hello") != "hello-suffix":
- print test4("hello")
- raise RuntimeError
+ raise RuntimeError("test4(\"hello\")")
if test5(4) != "xxxx":
raise RuntimeError
diff --git a/Examples/test-suite/python/li_cwstring_runme.py b/Examples/test-suite/python/li_cwstring_runme.py
index 5dd7b9b20..9216445c6 100644
--- a/Examples/test-suite/python/li_cwstring_runme.py
+++ b/Examples/test-suite/python/li_cwstring_runme.py
@@ -1,28 +1,28 @@
from li_cwstring import *
-if count(u"ab\0ab\0ab\0", 0) != 3:
+if count("ab\0ab\0ab\0", 0) != 3:
raise RuntimeError
-if test1() != u"Hello World":
+if test1() != "Hello World":
raise RuntimeError
-if test2() != u" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_":
+if test2() != " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_":
raise RuntimeError
-if test3("hello") != u"hello-suffix":
+if test3("hello") != "hello-suffix":
raise RuntimeError
-if test4("hello") != u"hello-suffix":
+if test4("hello") != "hello-suffix":
raise RuntimeError
-if test5(4) != u"xxxx":
+if test5(4) != "xxxx":
raise RuntimeError
-if test6(10) != u"xxxxx":
+if test6(10) != "xxxxx":
raise RuntimeError
-if test7() != u"Hello world!":
+if test7() != "Hello world!":
raise RuntimeError
-if test8() != u" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_":
+if test8() != " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_":
raise RuntimeError
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_implicit_runme.py b/Examples/test-suite/python/li_implicit_runme.py
index d8dd0fdcc..5d5c6caa0 100644
--- a/Examples/test-suite/python/li_implicit_runme.py
+++ b/Examples/test-suite/python/li_implicit_runme.py
@@ -9,8 +9,8 @@ ad, get(ad)
ab, get(ab)
if get(ai) != get(1):
- raise RuntimeError, "bad implicit type"
+ raise RuntimeError("bad implicit type")
if get(ad) != get(2.0):
- raise RuntimeError, "bad implicit type"
+ raise RuntimeError("bad implicit type")
if get(ab) != get(b):
- raise RuntimeError, "bad implicit type"
+ raise RuntimeError("bad implicit type")
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..dd8893f40 100644
--- a/Examples/test-suite/python/li_std_auto_ptr_runme.py
+++ b/Examples/test-suite/python/li_std_auto_ptr_runme.py
@@ -1,17 +1,109 @@
from li_std_auto_ptr import *
+def checkCount(expected_count):
+ actual_count = Klass.getTotal_count()
+ if (actual_count != expected_count):
+ raise RuntimeError("Counts incorrect, expected:" + expected_count + " actual:" + actual_count)
+
+# Test raw pointer handling involving virtual inheritance
+kini = KlassInheritance("KlassInheritanceInput")
+checkCount(1)
+s = useKlassRawPtr(kini)
+if s != "KlassInheritanceInput":
+ raise RuntimeError("Incorrect string: " + s)
+del kini
+checkCount(0)
+
+
+# auto_ptr as input
+kin = Klass("KlassInput")
+checkCount(1)
+s = takeKlassAutoPtr(kin)
+checkCount(0)
+if kin.thisown:
+ raise RuntimeError("thisown should be false")
+if s != "KlassInput":
+ raise RuntimeError("Incorrect string: " + s)
+if not is_nullptr(kin):
+ raise RuntimeError("is_nullptr failed")
+del kin # Should not fail, even though already deleted
+checkCount(0)
+
+kin = Klass("KlassInput")
+checkCount(1)
+s = takeKlassAutoPtr(kin)
+checkCount(0)
+if kin.thisown:
+ raise RuntimeError("thisown should be false")
+if s != "KlassInput":
+ raise RuntimeError("Incorrect string: " + s)
+if not is_nullptr(kin):
+ raise RuntimeError("is_nullptr failed")
+exception_thrown = False
+try:
+ s = takeKlassAutoPtr(kin)
+except RuntimeError as e:
+ if "cannot release ownership as memory is not owned" not in str(e):
+ raise RuntimeError("incorrect exception message");
+ exception_thrown = True
+if not exception_thrown:
+ raise RuntimeError("double usage of takeKlassAutoPtr should have been an error")
+del kin # Should not fail, even though already deleted
+checkCount(0)
+
+kin = Klass("KlassInput")
+exception_thrown = False
+notowned = get_not_owned_ptr(kin)
+try:
+ takeKlassAutoPtr(notowned)
+except RuntimeError as e:
+ exception_thrown = True
+if not exception_thrown:
+ raise RuntimeError("Should have thrown 'Cannot release ownership as memory is not owned' error")
+checkCount(1)
+del kin
+checkCount(0)
+
+kini = KlassInheritance("KlassInheritanceInput")
+checkCount(1)
+s = takeKlassAutoPtr(kini)
+checkCount(0)
+if kini.thisown:
+ raise RuntimeError("thisown should be false")
+if s != "KlassInheritanceInput":
+ raise RuntimeError("Incorrect string: " + s)
+if not is_nullptr(kini):
+ raise RuntimeError("is_nullptr failed")
+del kini # Should not fail, even though already deleted
+checkCount(0)
+
+takeKlassAutoPtr(None)
+takeKlassAutoPtr(make_null())
+checkCount(0)
+
+# overloaded parameters
+if overloadTest() != 0:
+ raise RuntimeError("overloadTest failed")
+if overloadTest(None) != 1:
+ raise RuntimeError("overloadTest failed")
+if overloadTest(Klass("over")) != 1:
+ raise RuntimeError("overloadTest failed")
+checkCount(0);
+
+
+# auto_ptr as output
k1 = makeKlassAutoPtr("first")
k2 = makeKlassAutoPtr("second")
-if Klass_getTotal_count() != 2:
- raise "number of objects should be 2"
+checkCount(2)
del k1
-if Klass_getTotal_count() != 1:
- raise "number of objects should be 1"
+checkCount(1)
if k2.getLabel() != "second":
raise "wrong object label"
del k2
-if Klass_getTotal_count() != 0:
- raise "no objects should be left"
+checkCount(0)
+
+if (makeNullAutoPtr() != None):
+ raise RuntimeError("null failure")
diff --git a/Examples/test-suite/python/li_std_carray_runme.py b/Examples/test-suite/python/li_std_carray_runme.py
deleted file mode 100644
index 36eeaf173..000000000
--- a/Examples/test-suite/python/li_std_carray_runme.py
+++ /dev/null
@@ -1,39 +0,0 @@
-from li_std_carray import *
-
-
-v3 = Vector3()
-for i in range(0, len(v3)):
- v3[i] = i
-
-i = 0
-for d in v3:
- if d != i:
- raise RuntimeError
- i = i + 1
-
-
-m3 = Matrix3()
-
-for i in range(0, len(m3)):
- v3 = m3[i]
- for j in range(0, len(v3)):
- v3[j] = i + j
-
-i = 0
-for v3 in m3:
- j = 0
- for d in v3:
- if d != i + j:
- raise RuntimeError
- j = j + 1
- pass
- i = i + 1
- pass
-
-for i in range(0, len(m3)):
- for j in range(0, len(m3)):
- if m3[i][j] != i + j:
- raise RuntimeError
-
-da = Vector3((1, 2, 3))
-ma = Matrix3(((1, 2, 3), (4, 5, 6), (7, 8, 9)))
diff --git a/Examples/test-suite/python/li_std_containers_int_runme.py b/Examples/test-suite/python/li_std_containers_int_runme.py
index 941838a5f..13c76d3aa 100644
--- a/Examples/test-suite/python/li_std_containers_int_runme.py
+++ b/Examples/test-suite/python/li_std_containers_int_runme.py
@@ -6,7 +6,7 @@ import sys
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):
@@ -26,7 +26,7 @@ def compare_containers(pythonlist, swigvector, swiglist):
def container_insert_step(i, j, step, newval):
- ps = range(6)
+ ps = list(range(6))
iv = vector_int(ps)
il = list_int(ps)
@@ -43,9 +43,9 @@ def container_insert_step(i, j, step, newval):
else:
ps[i:j:step] = newval
ps_error = None
- except ValueError, e:
+ except ValueError as e:
ps_error = e
- except IndexError, e:
+ except IndexError as e:
ps_error = e
# std::vector<int>
@@ -61,9 +61,9 @@ def container_insert_step(i, j, step, newval):
else:
iv[i:j:step] = newval
iv_error = None
- except ValueError, e:
+ except ValueError as e:
iv_error = e
- except IndexError, e:
+ except IndexError as e:
iv_error = e
# std::list<int>
@@ -79,14 +79,14 @@ def container_insert_step(i, j, step, newval):
else:
il[i:j:step] = newval
il_error = None
- except ValueError, e:
+ except ValueError as e:
il_error = e
- except IndexError, e:
+ except IndexError as e:
il_error = e
if not((type(ps_error) == type(iv_error)) and (type(ps_error) == type(il_error))):
- raise RuntimeError, "ValueError exception not consistently thrown: " + \
- str(ps_error) + " " + str(iv_error) + " " + str(il_error)
+ raise RuntimeError("ValueError exception not consistently thrown: " + \
+ str(ps_error) + " " + str(iv_error) + " " + str(il_error))
compare_containers(ps, iv, il)
@@ -94,7 +94,7 @@ def container_insert_step(i, j, step, newval):
# Check std::vector and std::list delete behaves same as Python list
# delete including exceptions
def container_delete_step(i, j, step):
- ps = range(6)
+ ps = list(range(6))
iv = vector_int(ps)
il = list_int(ps)
@@ -111,9 +111,9 @@ def container_delete_step(i, j, step):
else:
del ps[i:j:step]
ps_error = None
- except ValueError, e:
+ except ValueError as e:
ps_error = e
- except IndexError, e:
+ except IndexError as e:
ps_error = e
# std::vector<int>
@@ -129,9 +129,9 @@ def container_delete_step(i, j, step):
else:
del iv[i:j:step]
iv_error = None
- except ValueError, e:
+ except ValueError as e:
iv_error = e
- except IndexError, e:
+ except IndexError as e:
iv_error = e
# std::list<int>
@@ -147,14 +147,14 @@ def container_delete_step(i, j, step):
else:
del il[i:j:step]
il_error = None
- except ValueError, e:
+ except ValueError as e:
il_error = e
- except IndexError, e:
+ except IndexError as e:
il_error = e
if not((type(ps_error) == type(iv_error)) and (type(ps_error) == type(il_error))):
- raise RuntimeError, "ValueError exception not consistently thrown: " + \
- str(ps_error) + " " + str(iv_error) + " " + str(il_error)
+ raise RuntimeError("ValueError exception not consistently thrown: " + \
+ str(ps_error) + " " + str(iv_error) + " " + str(il_error))
compare_containers(ps, iv, il)
@@ -252,7 +252,7 @@ for start in [-102, -100, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 10
for step in range(-7, 7):
container_delete_step(start, end, step)
-ps = range(6)
+ps = list(range(6))
iv = vector_int(ps)
il = list_int(ps)
del ps[:]
@@ -279,3 +279,9 @@ try:
raise RuntimeError("Zero step not caught")
except ValueError:
pass
+
+# Construct from set (Iterator protocol, not Sequence protocol)
+ps = {11, 22, 33}
+iv = vector_int(ps)
+il = vector_int(ps)
+compare_containers(list(ps), iv, il)
diff --git a/Examples/test-suite/python/li_std_map_runme.py b/Examples/test-suite/python/li_std_map_runme.py
index ac214dd45..0d9416e4e 100644
--- a/Examples/test-suite/python/li_std_map_runme.py
+++ b/Examples/test-suite/python/li_std_map_runme.py
@@ -25,8 +25,7 @@ for k in m:
for k in m:
if pm[k].this != m[k].this:
- print pm[k], m[k]
- raise RuntimeError
+ raise RuntimeError("Not equal {} {}".format(pm[k], m[k]))
m = {}
@@ -51,31 +50,43 @@ mii[1] = 2
if mii[1] != 2:
raise RuntimeError
-if mii.keys() != [1]:
+if list(mii.keys()) != [1]:
raise RuntimeError("keys")
-if mii.values() != [2]:
+if list(mii.values()) != [2]:
raise RuntimeError("values")
-if mii.items() != [(1, 2)]:
+if list(mii.items()) != [(1, 2)]:
raise RuntimeError("items")
if [k for k in mii] != [1]:
raise RuntimeError("iteration")
-if [i for i in mii.iterkeys()] != [1]:
+if [i for i in mii.keys()] != [1]:
raise RuntimeError("iterkeys")
-if [i for i in mii.itervalues()] != [2]:
+if [i for i in mii.values()] != [2]:
raise RuntimeError("itervalues")
-if [i for i in mii.iteritems()] != [(1, 2)]:
+if [i for i in mii.items()] != [(1, 2)]:
raise RuntimeError("iteritems")
+# map global variable
+li_std_map.populate(li_std_map.cvar.MyMap)
+li_std_map.cvar.MyMap["eeeeee"] = 6
+keys = " ".join([k for k in list(li_std_map.cvar.MyMap.keys())])
+if keys != "a aa zzz xxxx aaaaa eeeeee":
+ raise RuntimeError("Keys are wrong or in wrong order: " + keys)
+
+values = " ".join([str(v) for v in list(li_std_map.cvar.MyMap.values())])
+if values != "1 2 3 4 5 6":
+ raise RuntimeError("Values are wrong or in wrong order: " + values)
+
+
slmap = li_std_map.StringLengthNumberMap()
li_std_map.populate(slmap)
-keys = " ".join([k for k in slmap.keys()])
+keys = " ".join([k for k in list(slmap.keys())])
if keys != "a aa zzz xxxx aaaaa":
raise RuntimeError("Keys are wrong or in wrong order: " + keys)
-values = " ".join([str(v) for v in slmap.values()])
+values = " ".join([str(v) for v in list(slmap.values())])
if values != "1 2 3 4 5":
raise RuntimeError("Values are wrong or in wrong order: " + values)
diff --git a/Examples/test-suite/python/li_std_pair_runme.py b/Examples/test-suite/python/li_std_pair_runme.py
new file mode 100644
index 000000000..4150e5cc8
--- /dev/null
+++ b/Examples/test-suite/python/li_std_pair_runme.py
@@ -0,0 +1,47 @@
+from li_std_pair import *
+
+def check(flag):
+ if not flag:
+ raise RuntimeError("Check failed")
+
+intPair = makeIntPair(7, 6)
+check(isinstance(intPair, tuple))
+check(len(intPair) == 2)
+check(intPair[0] == 7)
+check(intPair[1] == 6)
+
+intPairConstRef = makeIntPairConstRef(7, 6)
+check(isinstance(intPairConstRef, tuple))
+check(intPairConstRef[0] == 7)
+check(intPairConstRef[1] == 6)
+
+#
+# Each of these should return a reference to a wrapped
+# std::pair<int, int> object (i.e. an IntPair instance).
+#
+intPairPtr = makeIntPairPtr(7, 6)
+check(isinstance(intPairPtr, IntPair))
+check(intPairPtr[0] == 7)
+check(intPairPtr[1] == 6)
+
+intPairRef = makeIntPairRef(7, 6)
+check(isinstance(intPairRef, IntPair))
+check(intPairRef[0] == 7)
+check(intPairRef[1] == 6)
+#
+# Now test various input typemaps. Each of the wrapped C++ functions
+# (product1, product2 and product3) is expecting an argument of a
+# different type (see li_std_pair.i). Typemaps should be in place to
+# convert this tuple into the expected argument type.
+#
+check(product1(intPair) == 42)
+check(product2(intPair) == 42)
+# check(product3(intPair) == 42) # TODO, if desirable to match Ruby wrappers behaviour. Requires equivalent to typemap(in) std::pair* in Lib/ruby/std_pair.i and further fixes to stop recursive calls to swig::asptr which this testcase shows. Plus further changes for any type of sequence type (including other STL containers) to be accepted by all methods taking an STL container to match Ruby behaviour.
+
+#
+# Similarly, each of the input typemaps should know what to do
+# with an IntPair instance.
+#
+check(product1(intPairPtr) == 42)
+check(product2(intPairPtr) == 42)
+check(product3(intPairPtr) == 42)
diff --git a/Examples/test-suite/python/li_std_set_runme.py b/Examples/test-suite/python/li_std_set_runme.py
index 5e5b72442..7618f7dc8 100644
--- a/Examples/test-suite/python/li_std_set_runme.py
+++ b/Examples/test-suite/python/li_std_set_runme.py
@@ -14,11 +14,11 @@ if sum != "abc":
raise RuntimeError
i = s.__iter__()
-if i.next() != "a":
+if next(i) != "a":
raise RuntimeError
-if i.next() != "b":
+if next(i) != "b":
raise RuntimeError
-if i.next() != "c":
+if next(i) != "c":
raise RuntimeError
@@ -26,7 +26,7 @@ b = s.begin()
e = s.end()
sum = ""
while (b != e):
- sum = sum + b.next()
+ sum = sum + next(b)
if sum != "abc":
raise RuntimeError
@@ -34,7 +34,7 @@ b = s.rbegin()
e = s.rend()
sum = ""
while (b != e):
- sum = sum + b.next()
+ sum = sum + next(b)
if sum != "cba":
raise RuntimeError
@@ -47,25 +47,25 @@ si.append(2)
si.append(3)
i = si.__iter__()
-if i.next() != 1:
+if next(i) != 1:
raise RuntimeError
-if i.next() != 2:
+if next(i) != 2:
raise RuntimeError
-if i.next() != 3:
+if next(i) != 3:
raise RuntimeError
if si[0] != 1:
raise RuntimeError
i = s.begin()
-i.next()
+next(i)
s.erase(i)
b = s.begin()
e = s.end()
sum = ""
while (b != e):
- sum = sum + b.next()
+ sum = sum + next(b)
if sum != "ac":
raise RuntimeError
@@ -92,3 +92,13 @@ for i in s:
if (len(sum) != 3 or (not 1 in sum) or (not "hello" in sum) or (not (1, 2) in sum)):
raise RuntimeError
+
+# Create from Python set
+s = set_string({"x", "y", "z"})
+sum = ""
+for i in s:
+ sum = sum + i
+
+if sum != "xyz":
+ raise RuntimeError
+
diff --git a/Examples/test-suite/python/li_std_stream_runme.py b/Examples/test-suite/python/li_std_stream_runme.py
index 08c308856..a4526f07b 100644
--- a/Examples/test-suite/python/li_std_stream_runme.py
+++ b/Examples/test-suite/python/li_std_stream_runme.py
@@ -9,5 +9,4 @@ o << a << " " << 2345 << " " << 1.435
if o.str() != "A class 2345 1.435":
- print "\"%s\"" % (o.str(),)
- raise RuntimeError
+ raise RuntimeError("str failed: \"%s\"".format(o.str()))
diff --git a/Examples/test-suite/python/li_std_string_extra_runme.py b/Examples/test-suite/python/li_std_string_extra_runme.py
index 087d92b19..71620e7fb 100644
--- a/Examples/test-suite/python/li_std_string_extra_runme.py
+++ b/Examples/test-suite/python/li_std_string_extra_runme.py
@@ -4,18 +4,22 @@ x = "hello"
if li_std_string_extra.test_ccvalue(x) != x:
- raise RuntimeError, "bad string mapping"
+ raise RuntimeError("bad string mapping")
if li_std_string_extra.test_cvalue(x) != x:
- raise RuntimeError, "bad string mapping"
+ raise RuntimeError("bad string mapping")
if li_std_string_extra.test_value(x) != x:
- print x, li_std_string_extra.test_value(x)
- raise RuntimeError, "bad string mapping"
+ raise RuntimeError("bad string mapping {} {}".format(x, li_std_string_extra.test_value(x)))
if li_std_string_extra.test_const_reference(x) != x:
- raise RuntimeError, "bad string mapping"
+ raise RuntimeError("bad string mapping")
+s = li_std_string_extra.string("1234567890")
+size = s.size()
+if size != 10:
+ raise "Incorrect size"
+s.shrink_to_fit()
s = li_std_string_extra.string("he")
#s += "ll"
@@ -23,45 +27,43 @@ s = li_std_string_extra.string("he")
s = s + "llo"
if s != x:
- print s, x
- raise RuntimeError, "bad string mapping"
+ raise RuntimeError("bad string mapping {} {}".format(s, x))
if s[1:4] != x[1:4]:
- raise RuntimeError, "bad string mapping"
+ raise RuntimeError("bad string mapping")
if li_std_string_extra.test_value(s) != x:
- raise RuntimeError, "bad string mapping"
+ raise RuntimeError("bad string mapping")
if li_std_string_extra.test_const_reference(s) != x:
- raise RuntimeError, "bad string mapping"
+ raise RuntimeError("bad string mapping")
a = li_std_string_extra.A(s)
if li_std_string_extra.test_value(a) != x:
- raise RuntimeError, "bad string mapping"
+ raise RuntimeError("bad string mapping")
if li_std_string_extra.test_const_reference(a) != x:
- raise RuntimeError, "bad string mapping"
+ raise RuntimeError("bad string mapping")
b = li_std_string_extra.string(" world")
s = a + b
if a + b != "hello world":
- print a + b
- raise RuntimeError, "bad string mapping"
+ raise RuntimeError("bad string mapping {}".format(a + b))
if a + " world" != "hello world":
- raise RuntimeError, "bad string mapping"
+ raise RuntimeError("bad string mapping")
# This is expected to fail with -builtin option
# Reverse operators not supported in builtin types
if not li_std_string_extra.is_python_builtin():
if "hello" + b != "hello world":
- raise RuntimeError, "bad string mapping"
+ raise RuntimeError("bad string mapping")
c = "hello" + b
if c.find_last_of("l") != 9:
- raise RuntimeError, "bad string mapping"
+ raise RuntimeError("bad string mapping")
s = "hello world"
@@ -69,33 +71,33 @@ b = li_std_string_extra.B("hi")
b.name = li_std_string_extra.string("hello")
if b.name != "hello":
- raise RuntimeError, "bad string mapping"
+ raise RuntimeError("bad string mapping")
b.a = li_std_string_extra.A("hello")
if b.a != "hello":
- raise RuntimeError, "bad string mapping"
+ raise RuntimeError("bad string mapping")
if li_std_string_extra.test_value_basic1(x) != x:
- raise RuntimeError, "bad string mapping"
+ raise RuntimeError("bad string mapping")
if li_std_string_extra.test_value_basic2(x) != x:
- raise RuntimeError, "bad string mapping"
+ raise RuntimeError("bad string mapping")
if li_std_string_extra.test_value_basic3(x) != x:
- raise RuntimeError, "bad string mapping"
+ raise RuntimeError("bad string mapping")
if li_std_string_extra.test_value_basic_overload(x) != x:
- raise RuntimeError, "bad overload string"
+ raise RuntimeError("bad overload string")
if li_std_string_extra.test_value_basic_overload(123) != "int":
- raise RuntimeError, "bad overload int"
+ raise RuntimeError("bad overload int")
try:
li_std_string_extra.test_value_basic_overload([x])
- raise RuntimeError, "should throw TypeError"
+ raise RuntimeError("should throw TypeError")
except TypeError as e:
if str(e).find("Possible C/C++ prototypes are:") == -1:
raise RuntimeError("Incorrect error message text:\n{}".format(e))
@@ -103,7 +105,7 @@ except TypeError as e:
try:
li_std_string_extra.test_value_basic_overload([123])
- raise RuntimeError, "should throw TypeError"
+ raise RuntimeError("should throw TypeError")
except TypeError as e:
if str(e).find("Possible C/C++ prototypes are:") == -1:
raise RuntimeError("Incorrect error message text:\n{}".format(e))
@@ -112,30 +114,30 @@ except TypeError as e:
# Global variables
s = "initial string"
if li_std_string_extra.cvar.GlobalString2 != "global string 2":
- raise RuntimeError, "GlobalString2 test 1"
+ raise RuntimeError("GlobalString2 test 1")
li_std_string_extra.cvar.GlobalString2 = s
if li_std_string_extra.cvar.GlobalString2 != s:
- raise RuntimeError, "GlobalString2 test 2"
+ raise RuntimeError("GlobalString2 test 2")
if li_std_string_extra.cvar.ConstGlobalString != "const global string":
- raise RuntimeError, "ConstGlobalString test"
+ raise RuntimeError("ConstGlobalString test")
# Member variables
myStructure = li_std_string_extra.Structure()
if myStructure.MemberString2 != "member string 2":
- raise RuntimeError, "MemberString2 test 1"
+ raise RuntimeError("MemberString2 test 1")
myStructure.MemberString2 = s
if myStructure.MemberString2 != s:
- raise RuntimeError, "MemberString2 test 2"
+ raise RuntimeError("MemberString2 test 2")
if myStructure.ConstMemberString != "const member string":
- raise RuntimeError, "ConstMemberString test"
+ raise RuntimeError("ConstMemberString test")
if li_std_string_extra.cvar.Structure_StaticMemberString2 != "static member string 2":
- raise RuntimeError, "StaticMemberString2 test 1"
+ raise RuntimeError("StaticMemberString2 test 1")
li_std_string_extra.cvar.Structure_StaticMemberString2 = s
if li_std_string_extra.cvar.Structure_StaticMemberString2 != s:
- raise RuntimeError, "StaticMemberString2 test 2"
+ raise RuntimeError("StaticMemberString2 test 2")
if li_std_string_extra.cvar.Structure_ConstStaticMemberString != "const static member string":
- raise RuntimeError, "ConstStaticMemberString test"
+ raise RuntimeError("ConstStaticMemberString test")
if li_std_string_extra.test_reference_input("hello") != "hello":
diff --git a/Examples/test-suite/python/li_std_vector_enum_runme.py b/Examples/test-suite/python/li_std_vector_enum_runme.py
index 318d1bff6..587f20b37 100644
--- a/Examples/test-suite/python/li_std_vector_enum_runme.py
+++ b/Examples/test-suite/python/li_std_vector_enum_runme.py
@@ -14,7 +14,7 @@ check(ev.nums[2], 30)
it = ev.nums.iterator()
v = it.value()
check(v, 10)
-it.next()
+next(it)
v = it.value()
check(v, 20)
diff --git a/Examples/test-suite/python/li_std_vector_extra_runme.py b/Examples/test-suite/python/li_std_vector_extra_runme.py
index 59e729a27..40444552b 100644
--- a/Examples/test-suite/python/li_std_vector_extra_runme.py
+++ b/Examples/test-suite/python/li_std_vector_extra_runme.py
@@ -23,20 +23,20 @@ bv[2] = bool(4)
bv[3] = bool(0)
if bv[0] != bv[2]:
- raise RuntimeError, "bad std::vector<bool> mapping"
+ raise RuntimeError("bad std::vector<bool> mapping")
b = B(5)
va = VecA([b, None, b, b])
if va[0].f(1) != 6:
- raise RuntimeError, "bad std::vector<A*> mapping"
+ raise RuntimeError("bad std::vector<A*> mapping")
if vecAptr(va) != 6:
- raise RuntimeError, "bad std::vector<A*> mapping"
+ raise RuntimeError("bad std::vector<A*> mapping")
b.val = 7
if va[3].f(1) != 8:
- raise RuntimeError, "bad std::vector<A*> mapping"
+ raise RuntimeError("bad std::vector<A*> mapping")
ip = PtrInt()
@@ -47,7 +47,7 @@ ArrInt_setitem(ap, 2, 123)
vi = IntPtrVector((ip, ap, None))
if ArrInt_getitem(vi[0], 0) != ArrInt_getitem(vi[1], 2):
- raise RuntimeError, "bad std::vector<int*> mapping"
+ raise RuntimeError("bad std::vector<int*> mapping")
delete_ArrInt(ap)
@@ -57,42 +57,42 @@ a = halfs([10, 8, 4, 3])
v = IntVector()
v[0:2] = [1, 2]
if v[0] != 1 or v[1] != 2:
- raise RuntimeError, "bad setslice"
+ raise RuntimeError("bad setslice")
if v[0:-1][0] != 1:
- raise RuntimeError, "bad getslice"
+ raise RuntimeError("bad getslice")
if v[0:-2].size() != 0:
- raise RuntimeError, "bad getslice"
+ raise RuntimeError("bad getslice")
v[0:1] = [2]
if v[0] != 2:
- raise RuntimeError, "bad setslice"
+ raise RuntimeError("bad setslice")
v[1:] = [3]
if v[1] != 3:
- raise RuntimeError, "bad setslice"
+ raise RuntimeError("bad setslice")
v[2:] = [3]
if v[2] != 3:
- raise RuntimeError, "bad setslice"
+ raise RuntimeError("bad setslice")
if v[0:][0] != v[0]:
- raise RuntimeError, "bad getslice"
+ raise RuntimeError("bad getslice")
del v[:]
if v.size() != 0:
- raise RuntimeError, "bad getslice"
+ raise RuntimeError("bad getslice")
del v[:]
if v.size() != 0:
- raise RuntimeError, "bad getslice"
+ raise RuntimeError("bad getslice")
v = vecStr(["hello ", "world"])
if v[0] != "hello world":
- raise RuntimeError, "bad std::string+std::vector"
+ raise RuntimeError("bad std::string+std::vector")
pv = pyvector([1, "hello", (1, 2)])
diff --git a/Examples/test-suite/python/li_std_vector_runme.py b/Examples/test-suite/python/li_std_vector_runme.py
index 71460519d..728fc3544 100644
--- a/Examples/test-suite/python/li_std_vector_runme.py
+++ b/Examples/test-suite/python/li_std_vector_runme.py
@@ -8,3 +8,27 @@ try:
raise RuntimeError("Using None should result in a TypeError")
except TypeError:
pass
+
+
+# Variables
+vh = VariableHolder()
+vector_append(vh.instance_variable, 10)
+if vh.instance_variable[0] != 10:
+ raise RuntimeError("instance_variable check")
+vh.instance_variable.clear()
+if len(vh.instance_variable) != 0:
+ raise RuntimeError("instance_variable clear")
+
+vector_append(cvar.VariableHolder_static_variable, 20)
+if cvar.VariableHolder_static_variable[0] != 20:
+ raise RuntimeError("static_variable check")
+cvar.VariableHolder_static_variable.clear()
+if len(cvar.VariableHolder_static_variable) != 0:
+ raise RuntimeError("static_variable clear")
+
+vector_append(cvar.global_variable, 30)
+if cvar.global_variable[0] != 30:
+ raise RuntimeError("global_variable check")
+cvar.global_variable.clear()
+if len(cvar.global_variable) != 0:
+ raise RuntimeError("global_variable clear")
diff --git a/Examples/test-suite/python/li_std_wstream_runme.py b/Examples/test-suite/python/li_std_wstream_runme.py
index 045645b61..0ecdddbf8 100644
--- a/Examples/test-suite/python/li_std_wstream_runme.py
+++ b/Examples/test-suite/python/li_std_wstream_runme.py
@@ -5,8 +5,7 @@ a = A()
o = wostringstream()
-o << a << u" " << 2345 << u" " << 1.435 << wends
+o << a << " " << 2345 << " " << 1.435 << wends
if o.str() != "A class 2345 1.435\0":
- print "\"%s\"" % (o.str(),)
- raise RuntimeError
+ raise RuntimeError("str failed: \"%s\"".format(o.str()))
diff --git a/Examples/test-suite/python/li_std_wstring_inherit_runme.py b/Examples/test-suite/python/li_std_wstring_inherit_runme.py
index 558914e7e..bd585890c 100644
--- a/Examples/test-suite/python/li_std_wstring_inherit_runme.py
+++ b/Examples/test-suite/python/li_std_wstring_inherit_runme.py
@@ -1,14 +1,13 @@
import li_std_wstring_inherit
import sys
-x = u"hello"
+x = "hello"
-s = li_std_wstring_inherit.wstring(u"he")
-s = s + u"llo"
+s = li_std_wstring_inherit.wstring("he")
+s = s + "llo"
if s != x:
- print s, x
- raise RuntimeError("bad string mapping")
+ raise RuntimeError("bad string mapping {} {}".format(s, x))
if s[1:4] != x[1:4]:
raise RuntimeError("bad string mapping")
@@ -34,12 +33,12 @@ if not li_std_wstring_inherit.is_python_builtin():
b = li_std_wstring_inherit.B("hi")
-b.name = li_std_wstring_inherit.wstring(u"hello")
+b.name = li_std_wstring_inherit.wstring("hello")
if b.name != "hello":
raise RuntimeError("bad string mapping")
b.a = li_std_wstring_inherit.A("hello")
-if b.a != u"hello":
+if b.a != "hello":
raise RuntimeError("bad string mapping")
diff --git a/Examples/test-suite/python/li_std_wstring_runme.py b/Examples/test-suite/python/li_std_wstring_runme.py
index c6210e2de..ca8dc3184 100644
--- a/Examples/test-suite/python/li_std_wstring_runme.py
+++ b/Examples/test-suite/python/li_std_wstring_runme.py
@@ -5,10 +5,10 @@ def check_equal(a, b):
if a != b:
raise RuntimeError("failed {} {}".format(a, b))
-h = u"h"
+h = "h"
check_equal(li_std_wstring.test_wcvalue(h), h)
-x = u"abc"
+x = "abc"
check_equal(li_std_wstring.test_ccvalue(x), x)
check_equal(li_std_wstring.test_cvalue(x), x)
@@ -54,6 +54,12 @@ check_equal(li_std_wstring.test_value(x), x)
check_equal(li_std_wstring.test_ccvalue(x), "abc")
check_equal(li_std_wstring.test_wchar_overload(x), "abc")
+ts = li_std_wstring.wchar_test_struct()
+ts.wchar_t_member = h
+check_equal(ts.wchar_t_member, h)
+ts.wchar_t_ptr_member = s
+check_equal(ts.wchar_t_ptr_member, s)
+
################### Python specific
# Byte strings only converted in Python 2
@@ -72,7 +78,7 @@ except TypeError:
# Check surrogateescape
if sys.version_info[0:2] > (3, 1):
- x = u"h\udce9llo" # surrogate escaped representation of C char*: "h\xe9llo"
+ x = "h\udce9llo" # surrogate escaped representation of C char*: "h\xe9llo"
if li_std_wstring.non_utf8_c_str() != x:
raise RuntimeError("surrogateescape not working")
if li_std_wstring.size_wstring(x) != 5 and len(x) != 5:
diff --git a/Examples/test-suite/python/minherit_runme.py b/Examples/test-suite/python/minherit_runme.py
index b7e7d019c..8638d2357 100644
--- a/Examples/test-suite/python/minherit_runme.py
+++ b/Examples/test-suite/python/minherit_runme.py
@@ -7,31 +7,31 @@ c = minherit.FooBar()
d = minherit.Spam()
if a.xget() != 1:
- raise RuntimeError, "Bad attribute value"
+ raise RuntimeError("Bad attribute value")
if b.yget() != 2:
- raise RuntimeError, "Bad attribute value"
+ raise RuntimeError("Bad attribute value")
if c.xget() != 1 or c.yget() != 2 or c.zget() != 3:
- raise RuntimeError, "Bad attribute value"
+ raise RuntimeError("Bad attribute value")
if d.xget() != 1 or d.yget() != 2 or d.zget() != 3 or d.wget() != 4:
- raise RuntimeError, "Bad attribute value"
+ raise RuntimeError("Bad attribute value")
if minherit.xget(a) != 1:
- raise RuntimeError, "Bad attribute value %d" % (minherit.xget(a))
+ raise RuntimeError("Bad attribute value %d" % (minherit.xget(a)))
if minherit.yget(b) != 2:
- raise RuntimeError, "Bad attribute value %d" % (minherit.yget(b))
+ raise RuntimeError("Bad attribute value %d" % (minherit.yget(b)))
if minherit.xget(c) != 1 or minherit.yget(c) != 2 or minherit.zget(c) != 3:
- raise RuntimeError, "Bad attribute value %d %d %d" % (
- minherit.xget(c), minherit.yget(c), minherit.zget(c))
+ raise RuntimeError("Bad attribute value %d %d %d" % (
+ minherit.xget(c), minherit.yget(c), minherit.zget(c)))
if minherit.xget(d) != 1 or minherit.yget(d) != 2 or minherit.zget(d) != 3 or minherit.wget(d) != 4:
- raise RuntimeError, "Bad attribute value %d %d %d %d" % (
- minherit.xget(d), minherit.yget(d), minherit.zget(d), minherit.wget(d))
+ raise RuntimeError("Bad attribute value %d %d %d %d" % (
+ minherit.xget(d), minherit.yget(d), minherit.zget(d), minherit.wget(d)))
# Cleanse all of the pointers and see what happens
@@ -41,27 +41,27 @@ cc = minherit.toFooBarPtr(c)
dd = minherit.toSpamPtr(d)
if aa.xget() != 1:
- raise RuntimeError, "Bad attribute value"
+ raise RuntimeError("Bad attribute value")
if bb.yget() != 2:
- raise RuntimeError, "Bad attribute value"
+ raise RuntimeError("Bad attribute value")
if cc.xget() != 1 or cc.yget() != 2 or cc.zget() != 3:
- raise RuntimeError, "Bad attribute value"
+ raise RuntimeError("Bad attribute value")
if dd.xget() != 1 or dd.yget() != 2 or dd.zget() != 3 or dd.wget() != 4:
- raise RuntimeError, "Bad attribute value"
+ raise RuntimeError("Bad attribute value")
if minherit.xget(aa) != 1:
- raise RuntimeError, "Bad attribute value %d" % (minherit.xget(aa))
+ raise RuntimeError("Bad attribute value %d" % (minherit.xget(aa)))
if minherit.yget(bb) != 2:
- raise RuntimeError, "Bad attribute value %d" % (minherit.yget(bb))
+ raise RuntimeError("Bad attribute value %d" % (minherit.yget(bb)))
if minherit.xget(cc) != 1 or minherit.yget(cc) != 2 or minherit.zget(cc) != 3:
- raise RuntimeError, "Bad attribute value %d %d %d" % (
- minherit.xget(cc), minherit.yget(cc), minherit.zget(cc))
+ raise RuntimeError("Bad attribute value %d %d %d" % (
+ minherit.xget(cc), minherit.yget(cc), minherit.zget(cc)))
if minherit.xget(dd) != 1 or minherit.yget(dd) != 2 or minherit.zget(dd) != 3 or minherit.wget(dd) != 4:
- raise RuntimeError, "Bad attribute value %d %d %d %d" % (
- minherit.xget(dd), minherit.yget(dd), minherit.zget(dd), minherit.wget(dd))
+ raise RuntimeError("Bad attribute value %d %d %d %d" % (
+ minherit.xget(dd), minherit.yget(dd), minherit.zget(dd), minherit.wget(dd)))
diff --git a/Examples/test-suite/python/multivalue_runme.py b/Examples/test-suite/python/multivalue_runme.py
new file mode 100644
index 000000000..ba832724a
--- /dev/null
+++ b/Examples/test-suite/python/multivalue_runme.py
@@ -0,0 +1,19 @@
+import multivalue
+
+q, r = multivalue.divide_l(37, 5);
+if q != 7:
+ raise RuntimeError("Test divide_l quotient")
+if r != 2:
+ raise RuntimeError("Test divide_l remainder")
+
+q, r = multivalue.divide_v(41, 7);
+if q != 5:
+ raise RuntimeError("Test divide_v quotient")
+if r != 6:
+ raise RuntimeError("Test divide_v remainder")
+
+q, r = multivalue.divide_l(91, 13);
+if q != 7:
+ raise RuntimeError("Test divide_mv quotient")
+if r != 0:
+ raise RuntimeError("Test divide_mv remainder")
diff --git a/Examples/test-suite/python/name_warnings_runme.py b/Examples/test-suite/python/name_warnings_runme.py
new file mode 100644
index 000000000..0387436e0
--- /dev/null
+++ b/Examples/test-suite/python/name_warnings_runme.py
@@ -0,0 +1,9 @@
+from name_warnings import *
+
+def check(flag):
+ if not flag:
+ raise RuntimeError("Test failed")
+
+four = double_an_int(2)
+check(four == 4)
+
diff --git a/Examples/test-suite/python/namespace_class_runme.py b/Examples/test-suite/python/namespace_class_runme.py
index aa5165562..9349f2430 100644
--- a/Examples/test-suite/python/namespace_class_runme.py
+++ b/Examples/test-suite/python/namespace_class_runme.py
@@ -7,7 +7,7 @@ except:
error = 0
if (error):
- raise RuntimeError, "Private1 is private"
+ raise RuntimeError("Private1 is private")
try:
p = Private2()
@@ -16,7 +16,7 @@ except:
error = 0
if (error):
- raise RuntimeError, "Private2 is private"
+ raise RuntimeError("Private2 is private")
EulerT3D.toFrame(1, 1, 1)
diff --git a/Examples/test-suite/python/not_c_keywords_runme.py b/Examples/test-suite/python/not_c_keywords_runme.py
new file mode 100644
index 000000000..7f0772407
--- /dev/null
+++ b/Examples/test-suite/python/not_c_keywords_runme.py
@@ -0,0 +1,7 @@
+from not_c_keywords import *
+
+cs = ComplexStruct()
+cs.init()
+if cs.complex != 123:
+ raise RuntimeError("complex not correct")
+cs.complex = 456
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_complicated_runme.py b/Examples/test-suite/python/overload_complicated_runme.py
index 2593c4f16..8794da12b 100644
--- a/Examples/test-suite/python/overload_complicated_runme.py
+++ b/Examples/test-suite/python/overload_complicated_runme.py
@@ -10,38 +10,38 @@ p = Pop(pInt, False)
# Check overloaded in const only and pointers/references which target
# languages cannot disambiguate
if p.hip(False) != 701:
- raise RuntimeError, "Test 1 failed"
+ raise RuntimeError("Test 1 failed")
if p.hip(pInt) != 702:
- raise RuntimeError, "Test 2 failed"
+ raise RuntimeError("Test 2 failed")
# Reverse the order for the above
if p.hop(pInt) != 805:
- raise RuntimeError, "Test 3 failed"
+ raise RuntimeError("Test 3 failed")
if p.hop(False) != 801:
- raise RuntimeError, "Test 4 failed"
+ raise RuntimeError("Test 4 failed")
# Few more variations and order shuffled
if p.pop(False) != 901:
- raise RuntimeError, "Test 5 failed"
+ raise RuntimeError("Test 5 failed")
if p.pop(pInt) != 904:
- raise RuntimeError, "Test 6 failed"
+ raise RuntimeError("Test 6 failed")
if p.pop() != 905:
- raise RuntimeError, "Test 7 failed"
+ raise RuntimeError("Test 7 failed")
# Overload on const only
if p.bop(pInt) != 1001:
- raise RuntimeError, "Test 8 failed"
+ raise RuntimeError("Test 8 failed")
if p.bip(pInt) != 2002:
- raise RuntimeError, "Test 9 failed"
+ raise RuntimeError("Test 9 failed")
# Globals
if muzak(False) != 3001:
- raise RuntimeError, "Test 10 failed"
+ raise RuntimeError("Test 10 failed")
if muzak(pInt) != 3002:
- raise RuntimeError, "Test 11 failed"
+ raise RuntimeError("Test 11 failed")
diff --git a/Examples/test-suite/python/overload_null_runme.py b/Examples/test-suite/python/overload_null_runme.py
index a34524255..4b69b5c8d 100644
--- a/Examples/test-suite/python/overload_null_runme.py
+++ b/Examples/test-suite/python/overload_null_runme.py
@@ -32,13 +32,13 @@ check(14, o.byval1cpr(None))
check(15, o.byval2cpr(None))
check(16, o.byval2cpr(x))
-# forward class declaration
-check(17, o.byval1forwardptr(x))
-check(18, o.byval1forwardptr(None))
+# fwd class declaration
+check(17, o.byval1fwdptr(x))
+check(18, o.byval1fwdptr(None))
-check(19, o.byval2forwardptr(None))
-check(20, o.byval2forwardptr(x))
+check(19, o.byval2fwdptr(None))
+check(20, o.byval2fwdptr(x))
-check(21, o.byval1forwardref(x))
+check(21, o.byval1fwdref(x))
-check(22, o.byval2forwardref(x))
+check(22, o.byval2fwdref(x))
diff --git a/Examples/test-suite/python/overload_simple_runme.py b/Examples/test-suite/python/overload_simple_runme.py
index 6d72ec081..56763828d 100644
--- a/Examples/test-suite/python/overload_simple_runme.py
+++ b/Examples/test-suite/python/overload_simple_runme.py
@@ -1,95 +1,95 @@
from overload_simple import *
if foo(3) != "foo:int":
- raise RuntimeError, "foo(int)"
+ raise RuntimeError("foo(int)")
if foo(3.0) != "foo:double":
- raise RuntimeError, "foo(double)"
+ raise RuntimeError("foo(double)")
if foo("hello") != "foo:char *":
- raise RuntimeError, "foo(char *)"
+ raise RuntimeError("foo(char *)")
f = Foo()
b = Bar()
if foo(f) != "foo:Foo *":
- raise RuntimeError, "foo(Foo *)"
+ raise RuntimeError("foo(Foo *)")
if foo(b) != "foo:Bar *":
- raise RuntimeError, "foo(Bar *)"
+ raise RuntimeError("foo(Bar *)")
v = malloc_void(32)
if foo(v) != "foo:void *":
- raise RuntimeError, "foo(void *)"
+ raise RuntimeError("foo(void *)")
s = Spam()
if s.foo(3) != "foo:int":
- raise RuntimeError, "Spam::foo(int)"
+ raise RuntimeError("Spam::foo(int)")
if s.foo(3.0) != "foo:double":
- raise RuntimeError, "Spam::foo(double)"
+ raise RuntimeError("Spam::foo(double)")
if s.foo("hello") != "foo:char *":
- raise RuntimeError, "Spam::foo(char *)"
+ raise RuntimeError("Spam::foo(char *)")
if s.foo(f) != "foo:Foo *":
- raise RuntimeError, "Spam::foo(Foo *)"
+ raise RuntimeError("Spam::foo(Foo *)")
if s.foo(b) != "foo:Bar *":
- raise RuntimeError, "Spam::foo(Bar *)"
+ raise RuntimeError("Spam::foo(Bar *)")
if s.foo(v) != "foo:void *":
- raise RuntimeError, "Spam::foo(void *)"
+ raise RuntimeError("Spam::foo(void *)")
-if Spam_bar(3) != "bar:int":
- raise RuntimeError, "Spam::bar(int)"
+if Spam.bar(3) != "bar:int":
+ raise RuntimeError("Spam::bar(int)")
-if Spam_bar(3.0) != "bar:double":
- raise RuntimeError, "Spam::bar(double)"
+if Spam.bar(3.0) != "bar:double":
+ raise RuntimeError("Spam::bar(double)")
-if Spam_bar("hello") != "bar:char *":
- raise RuntimeError, "Spam::bar(char *)"
+if Spam.bar("hello") != "bar:char *":
+ raise RuntimeError("Spam::bar(char *)")
-if Spam_bar(f) != "bar:Foo *":
- raise RuntimeError, "Spam::bar(Foo *)"
+if Spam.bar(f) != "bar:Foo *":
+ raise RuntimeError("Spam::bar(Foo *)")
-if Spam_bar(b) != "bar:Bar *":
- raise RuntimeError, "Spam::bar(Bar *)"
+if Spam.bar(b) != "bar:Bar *":
+ raise RuntimeError("Spam::bar(Bar *)")
-if Spam_bar(v) != "bar:void *":
- raise RuntimeError, "Spam::bar(void *)"
+if Spam.bar(v) != "bar:void *":
+ raise RuntimeError("Spam::bar(void *)")
# Test constructors
s = Spam()
if s.type != "none":
- raise RuntimeError, "Spam()"
+ raise RuntimeError("Spam()")
s = Spam(3)
if s.type != "int":
- raise RuntimeError, "Spam(int)"
+ raise RuntimeError("Spam(int)")
s = Spam(3.4)
if s.type != "double":
- raise RuntimeError, "Spam(double)"
+ raise RuntimeError("Spam(double)")
s = Spam("hello")
if s.type != "char *":
- raise RuntimeError, "Spam(char *)"
+ raise RuntimeError("Spam(char *)")
s = Spam(f)
if s.type != "Foo *":
- raise RuntimeError, "Spam(Foo *)"
+ raise RuntimeError("Spam(Foo *)")
s = Spam(b)
if s.type != "Bar *":
- raise RuntimeError, "Spam(Bar *)"
+ raise RuntimeError("Spam(Bar *)")
s = Spam(v)
if s.type != "void *":
- raise RuntimeError, "Spam(void *)"
+ raise RuntimeError("Spam(void *)")
free_void(v)
diff --git a/Examples/test-suite/python/overload_subtype_runme.py b/Examples/test-suite/python/overload_subtype_runme.py
index 3f32a5583..b02e62ff3 100644
--- a/Examples/test-suite/python/overload_subtype_runme.py
+++ b/Examples/test-suite/python/overload_subtype_runme.py
@@ -4,7 +4,7 @@ f = Foo()
b = Bar()
if spam(f) != 1:
- raise RuntimeError, "foo"
+ raise RuntimeError("foo")
if spam(b) != 2:
- raise RuntimeError, "bar"
+ raise RuntimeError("bar")
diff --git a/Examples/test-suite/python/overload_template_fast_runme.py b/Examples/test-suite/python/overload_template_fast_runme.py
index ca3cac9b5..e4eb33288 100644
--- a/Examples/test-suite/python/overload_template_fast_runme.py
+++ b/Examples/test-suite/python/overload_template_fast_runme.py
@@ -7,74 +7,74 @@ b = maximum(3.4, 5.2)
# mix 1
if (mix1("hi") != 101):
- raise RuntimeError, ("mix1(const char*)")
+ raise RuntimeError(("mix1(const char*)"))
if (mix1(1.0, 1.0) != 102):
- raise RuntimeError, ("mix1(double, const double &)")
+ raise RuntimeError(("mix1(double, const double &)"))
if (mix1(1.0) != 103):
- raise RuntimeError, ("mix1(double)")
+ raise RuntimeError(("mix1(double)"))
# mix 2
if (mix2("hi") != 101):
- raise RuntimeError, ("mix2(const char*)")
+ raise RuntimeError(("mix2(const char*)"))
if (mix2(1.0, 1.0) != 102):
- raise RuntimeError, ("mix2(double, const double &)")
+ raise RuntimeError(("mix2(double, const double &)"))
if (mix2(1.0) != 103):
- raise RuntimeError, ("mix2(double)")
+ raise RuntimeError(("mix2(double)"))
# mix 3
if (mix3("hi") != 101):
- raise RuntimeError, ("mix3(const char*)")
+ raise RuntimeError(("mix3(const char*)"))
if (mix3(1.0, 1.0) != 102):
- raise RuntimeError, ("mix3(double, const double &)")
+ raise RuntimeError(("mix3(double, const double &)"))
if (mix3(1.0) != 103):
- raise RuntimeError, ("mix3(double)")
+ raise RuntimeError(("mix3(double)"))
# Combination 1
if (overtparams1(100) != 10):
- raise RuntimeError, ("overtparams1(int)")
+ raise RuntimeError(("overtparams1(int)"))
if (overtparams1(100.0, 100) != 20):
- raise RuntimeError, ("overtparams1(double, int)")
+ raise RuntimeError(("overtparams1(double, int)"))
# Combination 2
if (overtparams2(100.0, 100) != 40):
- raise RuntimeError, ("overtparams2(double, int)")
+ raise RuntimeError(("overtparams2(double, int)"))
# Combination 3
if (overloaded() != 60):
- raise RuntimeError, ("overloaded()")
+ raise RuntimeError(("overloaded()"))
if (overloaded(100.0, 100) != 70):
- raise RuntimeError, ("overloaded(double, int)")
+ raise RuntimeError(("overloaded(double, int)"))
# Combination 4
if (overloadedagain("hello") != 80):
- raise RuntimeError, ("overloadedagain(const char *)")
+ raise RuntimeError(("overloadedagain(const char *)"))
if (overloadedagain() != 90):
- raise RuntimeError, ("overloadedagain(double)")
+ raise RuntimeError(("overloadedagain(double)"))
# specializations
if (specialization(10) != 202):
- raise RuntimeError, ("specialization(int)")
+ raise RuntimeError(("specialization(int)"))
if (specialization(10.0) != 203):
- raise RuntimeError, ("specialization(double)")
+ raise RuntimeError(("specialization(double)"))
if (specialization(10, 10) != 204):
- raise RuntimeError, ("specialization(int, int)")
+ raise RuntimeError(("specialization(int, int)"))
if (specialization(10.0, 10.0) != 205):
- raise RuntimeError, ("specialization(double, double)")
+ raise RuntimeError(("specialization(double, double)"))
if (specialization("hi", "hi") != 201):
- raise RuntimeError, ("specialization(const char *, const char *)")
+ raise RuntimeError(("specialization(const char *, const char *)"))
# simple specialization
@@ -84,61 +84,61 @@ xyz_double()
# a bit of everything
if (overload("hi") != 0):
- raise RuntimeError, ("overload()")
+ raise RuntimeError(("overload()"))
if (overload(1) != 10):
- raise RuntimeError, ("overload(int t)")
+ raise RuntimeError(("overload(int t)"))
if (overload(1, 1) != 20):
- raise RuntimeError, ("overload(int t, const int &)")
+ raise RuntimeError(("overload(int t, const int &)"))
if (overload(1, "hello") != 30):
- raise RuntimeError, ("overload(int t, const char *)")
+ raise RuntimeError(("overload(int t, const char *)"))
k = Klass()
if (overload(k) != 10):
- raise RuntimeError, ("overload(Klass t)")
+ raise RuntimeError(("overload(Klass t)"))
if (overload(k, k) != 20):
- raise RuntimeError, ("overload(Klass t, const Klass &)")
+ raise RuntimeError(("overload(Klass t, const Klass &)"))
if (overload(k, "hello") != 30):
- raise RuntimeError, ("overload(Klass t, const char *)")
+ raise RuntimeError(("overload(Klass t, const char *)"))
if (overload(10.0, "hi") != 40):
- raise RuntimeError, ("overload(double t, const char *)")
+ raise RuntimeError(("overload(double t, const char *)"))
if (overload() != 50):
- raise RuntimeError, ("overload(const char *)")
+ raise RuntimeError(("overload(const char *)"))
# everything put in a namespace
if (nsoverload("hi") != 1000):
- raise RuntimeError, ("nsoverload()")
+ raise RuntimeError(("nsoverload()"))
if (nsoverload(1) != 1010):
- raise RuntimeError, ("nsoverload(int t)")
+ raise RuntimeError(("nsoverload(int t)"))
if (nsoverload(1, 1) != 1020):
- raise RuntimeError, ("nsoverload(int t, const int &)")
+ raise RuntimeError(("nsoverload(int t, const int &)"))
if (nsoverload(1, "hello") != 1030):
- raise RuntimeError, ("nsoverload(int t, const char *)")
+ raise RuntimeError(("nsoverload(int t, const char *)"))
if (nsoverload(k) != 1010):
- raise RuntimeError, ("nsoverload(Klass t)")
+ raise RuntimeError(("nsoverload(Klass t)"))
if (nsoverload(k, k) != 1020):
- raise RuntimeError, ("nsoverload(Klass t, const Klass &)")
+ raise RuntimeError(("nsoverload(Klass t, const Klass &)"))
if (nsoverload(k, "hello") != 1030):
- raise RuntimeError, ("nsoverload(Klass t, const char *)")
+ raise RuntimeError(("nsoverload(Klass t, const char *)"))
if (nsoverload(10.0, "hi") != 1040):
- raise RuntimeError, ("nsoverload(double t, const char *)")
+ raise RuntimeError(("nsoverload(double t, const char *)"))
if (nsoverload() != 1050):
- raise RuntimeError, ("nsoverload(const char *)")
+ raise RuntimeError(("nsoverload(const char *)"))
A.foo(1)
diff --git a/Examples/test-suite/python/overload_template_runme.py b/Examples/test-suite/python/overload_template_runme.py
index 014ec71cb..8bd105add 100644
--- a/Examples/test-suite/python/overload_template_runme.py
+++ b/Examples/test-suite/python/overload_template_runme.py
@@ -6,74 +6,74 @@ b = maximum(3.4, 5.2)
# mix 1
if (mix1("hi") != 101):
- raise RuntimeError, ("mix1(const char*)")
+ raise RuntimeError(("mix1(const char*)"))
if (mix1(1.0, 1.0) != 102):
- raise RuntimeError, ("mix1(double, const double &)")
+ raise RuntimeError(("mix1(double, const double &)"))
if (mix1(1.0) != 103):
- raise RuntimeError, ("mix1(double)")
+ raise RuntimeError(("mix1(double)"))
# mix 2
if (mix2("hi") != 101):
- raise RuntimeError, ("mix2(const char*)")
+ raise RuntimeError(("mix2(const char*)"))
if (mix2(1.0, 1.0) != 102):
- raise RuntimeError, ("mix2(double, const double &)")
+ raise RuntimeError(("mix2(double, const double &)"))
if (mix2(1.0) != 103):
- raise RuntimeError, ("mix2(double)")
+ raise RuntimeError(("mix2(double)"))
# mix 3
if (mix3("hi") != 101):
- raise RuntimeError, ("mix3(const char*)")
+ raise RuntimeError(("mix3(const char*)"))
if (mix3(1.0, 1.0) != 102):
- raise RuntimeError, ("mix3(double, const double &)")
+ raise RuntimeError(("mix3(double, const double &)"))
if (mix3(1.0) != 103):
- raise RuntimeError, ("mix3(double)")
+ raise RuntimeError(("mix3(double)"))
# Combination 1
if (overtparams1(100) != 10):
- raise RuntimeError, ("overtparams1(int)")
+ raise RuntimeError(("overtparams1(int)"))
if (overtparams1(100.0, 100) != 20):
- raise RuntimeError, ("overtparams1(double, int)")
+ raise RuntimeError(("overtparams1(double, int)"))
# Combination 2
if (overtparams2(100.0, 100) != 40):
- raise RuntimeError, ("overtparams2(double, int)")
+ raise RuntimeError(("overtparams2(double, int)"))
# Combination 3
if (overloaded() != 60):
- raise RuntimeError, ("overloaded()")
+ raise RuntimeError(("overloaded()"))
if (overloaded(100.0, 100) != 70):
- raise RuntimeError, ("overloaded(double, int)")
+ raise RuntimeError(("overloaded(double, int)"))
# Combination 4
if (overloadedagain("hello") != 80):
- raise RuntimeError, ("overloadedagain(const char *)")
+ raise RuntimeError(("overloadedagain(const char *)"))
if (overloadedagain() != 90):
- raise RuntimeError, ("overloadedagain(double)")
+ raise RuntimeError(("overloadedagain(double)"))
# specializations
if (specialization(10) != 202):
- raise RuntimeError, ("specialization(int)")
+ raise RuntimeError(("specialization(int)"))
if (specialization(10.0) != 203):
- raise RuntimeError, ("specialization(double)")
+ raise RuntimeError(("specialization(double)"))
if (specialization(10, 10) != 204):
- raise RuntimeError, ("specialization(int, int)")
+ raise RuntimeError(("specialization(int, int)"))
if (specialization(10.0, 10.0) != 205):
- raise RuntimeError, ("specialization(double, double)")
+ raise RuntimeError(("specialization(double, double)"))
if (specialization("hi", "hi") != 201):
- raise RuntimeError, ("specialization(const char *, const char *)")
+ raise RuntimeError(("specialization(const char *, const char *)"))
# simple specialization
@@ -83,63 +83,63 @@ xyz_double()
# a bit of everything
if (overload("hi") != 0):
- raise RuntimeError, ("overload()")
+ raise RuntimeError(("overload()"))
if (overload(1) != 10):
- raise RuntimeError, ("overload(int t)")
+ raise RuntimeError(("overload(int t)"))
if (overload(1, 1) != 20):
- raise RuntimeError, ("overload(int t, const int &)")
+ raise RuntimeError(("overload(int t, const int &)"))
if (overload(1, "hello") != 30):
- raise RuntimeError, ("overload(int t, const char *)")
+ raise RuntimeError(("overload(int t, const char *)"))
k = Klass()
if (overload(k) != 10):
- raise RuntimeError, ("overload(Klass t)")
+ raise RuntimeError(("overload(Klass t)"))
if (overload(k, k) != 20):
- raise RuntimeError, ("overload(Klass t, const Klass &)")
+ raise RuntimeError(("overload(Klass t, const Klass &)"))
if (overload(k, "hello") != 30):
- raise RuntimeError, ("overload(Klass t, const char *)")
+ raise RuntimeError(("overload(Klass t, const char *)"))
if (overload(10.0, "hi") != 40):
- raise RuntimeError, ("overload(double t, const char *)")
+ raise RuntimeError(("overload(double t, const char *)"))
if (overload() != 50):
- raise RuntimeError, ("overload(const char *)")
+ raise RuntimeError(("overload(const char *)"))
# everything put in a namespace
if (nsoverload("hi") != 1000):
- raise RuntimeError, ("nsoverload()")
+ raise RuntimeError(("nsoverload()"))
if (nsoverload(1) != 1010):
- raise RuntimeError, ("nsoverload(int t)")
+ raise RuntimeError(("nsoverload(int t)"))
if (nsoverload(1, 1) != 1020):
- raise RuntimeError, ("nsoverload(int t, const int &)")
+ raise RuntimeError(("nsoverload(int t, const int &)"))
if (nsoverload(1, "hello") != 1030):
- raise RuntimeError, ("nsoverload(int t, const char *)")
+ raise RuntimeError(("nsoverload(int t, const char *)"))
if (nsoverload(k) != 1010):
- raise RuntimeError, ("nsoverload(Klass t)")
+ raise RuntimeError(("nsoverload(Klass t)"))
if (nsoverload(k, k) != 1020):
- raise RuntimeError, ("nsoverload(Klass t, const Klass &)")
+ raise RuntimeError(("nsoverload(Klass t, const Klass &)"))
if (nsoverload(k, "hello") != 1030):
- raise RuntimeError, ("nsoverload(Klass t, const char *)")
+ raise RuntimeError(("nsoverload(Klass t, const char *)"))
if (nsoverload(10.0, "hi") != 1040):
- raise RuntimeError, ("nsoverload(double t, const char *)")
+ raise RuntimeError(("nsoverload(double t, const char *)"))
if (nsoverload() != 1050):
- raise RuntimeError, ("nsoverload(const char *)")
+ raise RuntimeError(("nsoverload(const char *)"))
-A_foo(1)
+A.foo(1)
b = B()
b.foo(1)
diff --git a/Examples/test-suite/python/pointer_reference_runme.py b/Examples/test-suite/python/pointer_reference_runme.py
index b9b47881d..f12648696 100644
--- a/Examples/test-suite/python/pointer_reference_runme.py
+++ b/Examples/test-suite/python/pointer_reference_runme.py
@@ -2,15 +2,15 @@ import pointer_reference
s = pointer_reference.get()
if s.value != 10:
- raise RuntimeError, "get test failed"
+ raise RuntimeError("get test failed")
ss = pointer_reference.Struct(20)
pointer_reference.set(ss)
if pointer_reference.cvar.Struct_instance.value != 20:
- raise RuntimeError, "set test failed"
+ raise RuntimeError("set test failed")
if pointer_reference.overloading(1) != 111:
- raise RuntimeError, "overload test 1 failed"
+ raise RuntimeError("overload test 1 failed")
if pointer_reference.overloading(ss) != 222:
- raise RuntimeError, "overload test 2 failed"
+ raise RuntimeError("overload test 2 failed")
diff --git a/Examples/test-suite/python/preproc_cpp_runme.py b/Examples/test-suite/python/preproc_cpp_runme.py
new file mode 100644
index 000000000..8c3e21237
--- /dev/null
+++ b/Examples/test-suite/python/preproc_cpp_runme.py
@@ -0,0 +1,4 @@
+import preproc_cpp
+
+t1 = preproc_cpp.tcxMessageTest()
+t2 = preproc_cpp.tcxMessageBug()
diff --git a/Examples/test-suite/python/preproc_defined_runme.py b/Examples/test-suite/python/preproc_defined_runme.py
index af46816be..37441db52 100644
--- a/Examples/test-suite/python/preproc_defined_runme.py
+++ b/Examples/test-suite/python/preproc_defined_runme.py
@@ -9,3 +9,12 @@ d.defined = 10
preproc_defined.thing(10)
preproc_defined.stuff(10)
preproc_defined.bumpf(10)
+
+if preproc_defined.a != 2:
+ raise RuntimeError
+
+if preproc_defined.b != 42:
+ raise RuntimeError
+
+if preproc_defined.z != 8:
+ raise RuntimeError
diff --git a/Examples/test-suite/python/primitive_types_runme.py b/Examples/test-suite/python/primitive_types_runme.py
index 04588ddf2..e397c1179 100644
--- a/Examples/test-suite/python/primitive_types_runme.py
+++ b/Examples/test-suite/python/primitive_types_runme.py
@@ -31,8 +31,7 @@ v_check()
def pyerror(name, val, cte):
- print "bad val/cte", name, val, cte
- raise RuntimeError
+ raise RuntimeError("bad val/cte {} {} {}".format(name, val, cte))
pass
if cvar.var_bool != cct_bool:
@@ -173,7 +172,7 @@ p = PyTest()
# internal call check
if t.c_check() != p.c_check():
- raise RuntimeError, "bad director"
+ raise RuntimeError("bad director")
p.var_bool = p.stc_bool
p.var_schar = p.stc_schar
@@ -228,63 +227,57 @@ t.v_check()
# this value contains a '0' char!
if def_namet != "hola":
- print "bad namet", def_namet
- raise RuntimeError
+ raise RuntimeError("bad namet {}".format(def_namet))
t.var_namet = def_namet
if t.var_namet != def_namet:
- print "bad namet", t.var_namet, def_namet
- raise RuntimeError
+ raise RuntimeError("bad namet {} {}".format(t.var_namet, def_namet))
t.var_namet = "hola"
if t.var_namet != "hola":
- print "bad namet", t.var_namet
- raise RuntimeError
+ raise RuntimeError("bad namet {}".format(t.var_namet))
t.var_namet = "hol"
if t.var_namet != "hol":
# if t.var_namet != "hol\0\0":
- print "bad namet", t.var_namet
- raise RuntimeError
+ raise RuntimeError("bad namet {}".format(t.var_namet))
cvar.var_char = "\0"
if cvar.var_char != "\0":
- raise RuntimeError, "bad char '0' case"
+ raise RuntimeError("bad char '0' case")
cvar.var_char = 0
if cvar.var_char != "\0":
- raise RuntimeError, "bad char '0' case"
+ raise RuntimeError("bad char '0' case")
cvar.var_namet = "\0"
# if cvar.var_namet != "\0\0\0\0\0":
if cvar.var_namet != "":
- print "hola", "", cvar.var_namet
- raise RuntimeError, "bad char '\0' case"
+ raise RuntimeError("bad char '\0' case hola {}".format(cvar.var_namet))
cvar.var_namet = ""
# if cvar.var_namet != "\0\0\0\0\0":
if cvar.var_namet != "":
- raise RuntimeError, "bad char empty case"
+ raise RuntimeError("bad char empty case")
cvar.var_pchar = None
if cvar.var_pchar != None:
- raise RuntimeError, "bad None case"
+ raise RuntimeError("bad None case")
cvar.var_pchar = ""
if cvar.var_pchar != "":
- print "%c" % (cvar.var_pchar[0],)
- raise RuntimeError, "bad char empty case"
+ raise RuntimeError("bad char empty case %c" % (cvar.var_pchar[0],))
cvar.var_pcharc = None
if cvar.var_pcharc != None:
- raise RuntimeError, "bad None case"
+ raise RuntimeError("bad None case")
cvar.var_pcharc = ""
if cvar.var_pcharc != "":
- raise RuntimeError, "bad char empty case"
+ raise RuntimeError("bad char empty case")
#
@@ -300,13 +293,12 @@ pchar_setitem(pc, 4, 0)
cvar.var_pchar = pc
if cvar.var_pchar != "hola":
- print cvar.var_pchar
- raise RuntimeError, "bad pointer case"
+ raise RuntimeError("bad pointer case {}".format(cvar.var_pchar))
cvar.var_namet = pc
# if cvar.var_namet != "hola\0":
if cvar.var_namet != "hola":
- raise RuntimeError, "bad pointer case"
+ raise RuntimeError("bad pointer case")
delete_pchar(pc)
@@ -325,7 +317,7 @@ except OverflowError:
error = 1
pass
if error:
- raise RuntimeError, "bad uchar typemap"
+ raise RuntimeError("bad uchar typemap")
try:
@@ -338,7 +330,7 @@ except TypeError:
error = 1
pass
if error:
- raise RuntimeError, "bad char typemap"
+ raise RuntimeError("bad char typemap")
try:
error = 0
@@ -350,7 +342,7 @@ except OverflowError:
error = 1
pass
if error:
- raise RuntimeError, "bad ushort typemap"
+ raise RuntimeError("bad ushort typemap")
try:
error = 0
@@ -362,7 +354,7 @@ except OverflowError:
error = 1
pass
if error:
- raise RuntimeError, "bad uint typemap"
+ raise RuntimeError("bad uint typemap")
try:
error = 0
@@ -374,7 +366,7 @@ except OverflowError:
error = 1
pass
if error:
- raise RuntimeError, "bad sizet typemap"
+ raise RuntimeError("bad sizet typemap")
try:
error = 0
@@ -386,7 +378,7 @@ except OverflowError:
error = 1
pass
if error:
- raise RuntimeError, "bad ulong typemap"
+ raise RuntimeError("bad ulong typemap")
#
#
@@ -400,51 +392,48 @@ except TypeError:
error = 1
pass
if error:
- raise RuntimeError, "bad namet typemap"
+ raise RuntimeError("bad namet typemap")
#
#
#
t2 = p.vtest(t)
if t.var_namet != t2.var_namet:
- raise RuntimeError, "bad SWIGTYPE* typemap"
+ raise RuntimeError("bad SWIGTYPE* typemap")
if cvar.fixsize != "ho\0la\0\0\0":
- raise RuntimeError, "bad FIXSIZE typemap"
+ raise RuntimeError("bad FIXSIZE typemap")
cvar.fixsize = "ho"
if cvar.fixsize != "ho\0\0\0\0\0\0":
- raise RuntimeError, "bad FIXSIZE typemap"
+ raise RuntimeError("bad FIXSIZE typemap")
f = Foo(3)
f1 = fptr_val(f)
f2 = fptr_ref(f)
if f1._a != f2._a:
- raise RuntimeError, "bad const ptr& typemap"
+ raise RuntimeError("bad const ptr& typemap")
v = char_foo(1, 3)
if v != 3:
- raise RuntimeError, "bad int typemap"
+ raise RuntimeError("bad int typemap")
s = char_foo(1, "hello")
if s != "hello":
- raise RuntimeError, "bad char* typemap"
+ raise RuntimeError("bad char* typemap")
v = SetPos(1, 3)
if v != 4:
- raise RuntimeError, "bad int typemap"
+ raise RuntimeError("bad int typemap")
#
# Check the bounds for converting various types
#
-# ctypes not available until 2.5
-if sys.version_info[0:2] <= (2, 4):
- sys.exit(0)
import ctypes
# Get the minimum and maximum values that fit in signed char, short, int, long, and long long
@@ -481,7 +470,7 @@ maxullong = 2 * maxllong + 1
# Make sure Python 2's sys.maxint is the same as the maxlong we calculated
if sys.version_info[0] <= 2 and maxlong != sys.maxint:
- raise RuntimeError, "sys.maxint is not the maximum value of a signed long"
+ raise RuntimeError("sys.maxint is not the maximum value of a signed long")
def checkType(t, e, val, delta):
"""t = Test object, e = type name (e.g. ulong), val = max or min allowed value, delta = +1 for max, -1 for min"""
@@ -511,7 +500,7 @@ def checkType(t, e, val, delta):
except OverflowError:
pass
if error:
- raise RuntimeError, "bad " + e + " typemap"
+ raise RuntimeError("bad " + e + " typemap")
def checkFull(t, e, maxval, minval):
"""Check the maximum and minimum bounds for the type given by e"""
@@ -543,17 +532,17 @@ def checkOverload(t, name, val, delta, prevval, limit):
if val != prevval:
# Make sure the most extreme value of this type gives the name of this type
if t.ovr_str(val) != name:
- raise RuntimeError, "bad " + name + " typemap"
+ raise RuntimeError("bad " + name + " typemap")
# Make sure a more extreme value doesn't give the name of this type
try:
if t.ovr_str(val + delta) == name:
- raise RuntimeError, "bad " + name + " typemap"
+ raise RuntimeError("bad " + name + " typemap")
if val == limit:
# Should raise TypeError here since this is the largest integral type
- raise RuntimeError, "bad " + name + " typemap"
+ raise RuntimeError("bad " + name + " typemap")
except TypeError:
if val != limit:
- raise RuntimeError, "bad " + name + " typemap"
+ raise RuntimeError("bad " + name + " typemap")
# Check that overloading works: uchar > schar > ushort > short > uint > int > ulong > long > ullong > llong
checkOverload(t, "uchar", maxuchar, +1, 0, maxullong)
@@ -568,22 +557,22 @@ checkOverload(t, "long", minlong, -1, minint, minllong)
checkOverload(t, "llong", minllong, -1, minlong, minllong)
# Make sure that large ints can be converted to doubles properly
-if val_double(sys.maxint + 1) != float(sys.maxint + 1):
- raise RuntimeError, "bad double typemap"
-if val_double(-sys.maxint - 2) != float(-sys.maxint - 2):
- raise RuntimeError, "bad double typemap"
+if val_double(sys.maxsize + 1) != float(sys.maxsize + 1):
+ raise RuntimeError("bad double typemap")
+if val_double(-sys.maxsize - 2) != float(-sys.maxsize - 2):
+ raise RuntimeError("bad double typemap")
# Check the minimum and maximum values that fit in ptrdiff_t and size_t
def checkType(name, maxfunc, maxval, minfunc, minval, echofunc):
if maxfunc() != maxval:
- raise RuntimeError, "bad " + name + " typemap"
+ raise RuntimeError("bad " + name + " typemap")
if minfunc() != minval:
- raise RuntimeError, "bad " + name + " typemap"
+ raise RuntimeError("bad " + name + " typemap")
if echofunc(maxval) != maxval:
- raise RuntimeError, "bad " + name + " typemap"
+ raise RuntimeError("bad " + name + " typemap")
if echofunc(minval) != minval:
- raise RuntimeError, "bad " + name + " typemap"
+ raise RuntimeError("bad " + name + " typemap")
error = 0
try:
echofunc(maxval + 1)
@@ -591,16 +580,15 @@ def checkType(name, maxfunc, maxval, minfunc, minval, echofunc):
except OverflowError:
pass
if error == 1:
- raise RuntimeError, "bad " + name + " typemap"
+ raise RuntimeError("bad " + name + " typemap")
try:
echofunc(minval - 1)
error = 1
except OverflowError:
pass
if error == 1:
- raise RuntimeError, "bad " + name + " typemap"
+ raise RuntimeError("bad " + name + " typemap")
# sys.maxsize is the largest value supported by Py_ssize_t, which should be the same as ptrdiff_t
-if sys.version_info[0:2] >= (2, 6):
- checkType("ptrdiff_t", get_ptrdiff_max, sys.maxsize, get_ptrdiff_min, -(sys.maxsize + 1), ptrdiff_echo)
- checkType("size_t", get_size_max, (2 * sys.maxsize) + 1, get_size_min, 0, size_echo)
+checkType("ptrdiff_t", get_ptrdiff_max, sys.maxsize, get_ptrdiff_min, -(sys.maxsize + 1), ptrdiff_echo)
+checkType("size_t", get_size_max, (2 * sys.maxsize) + 1, get_size_min, 0, size_echo)
diff --git a/Examples/test-suite/python/python_abstractbase_runme.py b/Examples/test-suite/python/python_abstractbase_runme.py
new file mode 100644
index 000000000..0790c5ca7
--- /dev/null
+++ b/Examples/test-suite/python/python_abstractbase_runme.py
@@ -0,0 +1,40 @@
+import sys
+
+# collections.abc requires Python 3.3+
+
+from python_abstractbase import *
+if sys.version_info[0:2] >= (3, 3):
+ import collections.abc
+else:
+ import collections
+
+# This is expected to fail with -builtin option
+# Builtin types can't inherit from pure-python abstract bases
+if is_python_builtin():
+ exit(0)
+
+def check_issubclass(derived, base):
+ if not issubclass(derived, base):
+ raise RuntimeError("{} is not a subclass of {}".format(derived, base))
+
+if sys.version_info[0:2] >= (3, 3):
+ check_issubclass(Mapii, collections.abc.MutableMapping)
+ check_issubclass(Multimapii, collections.abc.MutableMapping)
+ check_issubclass(IntSet, collections.abc.MutableSet)
+ check_issubclass(IntMultiset, collections.abc.MutableSet)
+ check_issubclass(IntVector, collections.abc.MutableSequence)
+ check_issubclass(IntList, collections.abc.MutableSequence)
+else:
+ check_issubclass(Mapii, collections.MutableMapping)
+ check_issubclass(Multimapii, collections.MutableMapping)
+ check_issubclass(IntSet, collections.MutableSet)
+ check_issubclass(IntMultiset, collections.MutableSet)
+ check_issubclass(IntVector, collections.MutableSequence)
+ check_issubclass(IntList, collections.MutableSequence)
+
+mapii = Mapii()
+multimapii = Multimapii()
+intset = IntSet()
+intmultiset = IntMultiset()
+intvector = IntVector()
+intlist = IntList()
diff --git a/Examples/test-suite/python/python_abstractbase_runme3.py b/Examples/test-suite/python/python_abstractbase_runme3.py
deleted file mode 100644
index 9f99dcb54..000000000
--- a/Examples/test-suite/python/python_abstractbase_runme3.py
+++ /dev/null
@@ -1,35 +0,0 @@
-import sys
-
-# collections.abc requires Python 3.3+
-if sys.version_info[0:2] < (3, 3):
- exit(0)
-
-from python_abstractbase import *
-import collections.abc
-
-# This is expected to fail with -builtin option
-# Builtin types can't inherit from pure-python abstract bases
-if is_python_builtin():
- exit(0)
-
-# Python abc is only turned on when -py3 option is passed to SWIG
-if not is_swig_py3:
- exit(0)
-
-def check_issubclass(derived, base):
- if not issubclass(derived, base):
- raise RuntimeError("{} is not a subclass of {}".format(derived, base))
-
-check_issubclass(Mapii, collections.abc.MutableMapping)
-check_issubclass(Multimapii, collections.abc.MutableMapping)
-check_issubclass(IntSet, collections.abc.MutableSet)
-check_issubclass(IntMultiset, collections.abc.MutableSet)
-check_issubclass(IntVector, collections.abc.MutableSequence)
-check_issubclass(IntList, collections.abc.MutableSequence)
-
-mapii = Mapii()
-multimapii = Multimapii()
-intset = IntSet()
-intmultiset = IntMultiset()
-intvector = IntVector()
-intlist = IntList()
diff --git a/Examples/test-suite/python/python_annotations_c_runme.py b/Examples/test-suite/python/python_annotations_c_runme.py
new file mode 100644
index 000000000..3110d8f83
--- /dev/null
+++ b/Examples/test-suite/python/python_annotations_c_runme.py
@@ -0,0 +1,31 @@
+import sys
+
+if sys.version_info[0:2] >= (3, 2):
+ from python_annotations_c import *
+
+ # No __annotations__ support with -builtin or -fastproxy
+ annotations_supported = not(is_python_builtin() or is_python_fastproxy())
+
+ if annotations_supported:
+ anno = MakeShort.__annotations__
+ if anno != {'x': 'int', 'return': 'Space::Template< short >'}:
+ raise RuntimeError("annotations mismatch: {}".format(anno))
+
+ anno = global_ints.__annotations__
+ if anno != {'ri': 'int &', 't': 'TemplateShort', 'return': 'int *'}:
+ raise RuntimeError("annotations mismatch: {}".format(anno))
+
+ ts = MakeShort(10)
+
+ anno = MakeShort.__annotations__
+ if anno != {'x': 'int', 'return': 'Space::Template< short >'}:
+ raise RuntimeError("annotations mismatch: {}".format(anno))
+
+ anno = ts.mymethod.__annotations__
+ if anno != {'arg2': 'int', 'tt': 'TemplateShort', 'return': 'void'}:
+ raise RuntimeError("annotations mismatch: {}".format(anno))
+
+ # No annotations
+ anno = no_annotations.__annotations__
+ if anno != {}:
+ raise RuntimeError("annotations mismatch: {}".format(anno))
diff --git a/Examples/test-suite/python/python_annotations_variable_c_runme.py b/Examples/test-suite/python/python_annotations_variable_c_runme.py
new file mode 100644
index 000000000..153852d05
--- /dev/null
+++ b/Examples/test-suite/python/python_annotations_variable_c_runme.py
@@ -0,0 +1,24 @@
+import sys
+
+# Variable annotations for properties is only supported in python-3.6 and later (PEP 526)
+if sys.version_info[0:2] >= (3, 6):
+ from python_annotations_variable_c import *
+
+ # No SWIG __annotations__ support with -builtin or -fastproxy
+ annotations_supported = not(is_python_builtin() or is_python_fastproxy())
+
+ if annotations_supported:
+ ts = TemplateShort()
+ anno = ts.__annotations__
+ if anno != {'member_variable': 'int'}:
+ raise RuntimeError("annotations mismatch: {}".format(anno))
+
+ ts = StructWithVar()
+ anno = ts.__annotations__
+ if anno != {'member_variable': 'int'}:
+ raise RuntimeError("annotations mismatch: {}".format(anno))
+
+ ts = StructWithVarNotAnnotated()
+ if getattr(ts, "__annotations__", None) != None:
+ anno = ts.__annotations__
+ raise RuntimeError("annotations mismatch: {}".format(anno))
diff --git a/Examples/test-suite/python/python_append_runme.py b/Examples/test-suite/python/python_append_runme.py
index eddda53ff..e5f6b07cf 100644
--- a/Examples/test-suite/python/python_append_runme.py
+++ b/Examples/test-suite/python/python_append_runme.py
@@ -21,3 +21,16 @@ if grabstaticpath() != None:
Test.static_func()
if grabstaticpath() != os.path.basename(mypath):
raise RuntimeError("grabstaticpath failed")
+
+# slots test
+fs = ForSlots()
+if fs.ValidVariable != 99:
+ raise RuntimeError("ValidVariable failed")
+fs.ValidVariable = 11
+if fs.ValidVariable != 11:
+ raise RuntimeError("ValidVariable failed")
+try:
+ fs.Invalid = 22
+ raise RuntimeError("It should not be possible to set a random variable name")
+except AttributeError:
+ pass
diff --git a/Examples/test-suite/python/python_builtin_runme.py b/Examples/test-suite/python/python_builtin_runme.py
index 26e757ca7..5476c4532 100644
--- a/Examples/test-suite/python/python_builtin_runme.py
+++ b/Examples/test-suite/python/python_builtin_runme.py
@@ -32,7 +32,7 @@ if is_python_builtin():
passed = False
try:
h = hash(ExceptionHashFunction())
- except RuntimeError, e:
+ except RuntimeError as e:
passed = str(e).find("oops") != -1
pass
@@ -111,3 +111,26 @@ z = ANumber(9)
z = pow(x, y, z)
if z.Value() != 7:
raise RuntimeError("pow(x, y, z) wrong")
+
+# Test 8 https://github.com/swig/swig/pull/2771 __setitem__ for deleting item, uses C NULL
+def check_gsi(gsi, idx, value, args_count, kw_count):
+ if gsi.idx != idx:
+ raise RuntimeError("idx wrong {}".format(idx))
+ if gsi.value != value:
+ raise RuntimeError("value wrong {}".format(value))
+ if gsi.args_count != args_count:
+ raise RuntimeError("args_count wrong {}".format(args_count))
+ if gsi.kw_count != kw_count:
+ raise RuntimeError("kw_count wrong {}".format(kw_count))
+ gsi.reset()
+
+if is_python_builtin():
+ gsi = GetSetItem()
+ gsi[0] = 111
+ check_gsi(gsi, 0, 111, -100, -100)
+ del gsi[0]
+ check_gsi(gsi, 0, -11, -100, -100)
+ gsi(222, fred = 333, jack = 444)
+ check_gsi(gsi, -100, -100, 1, 2)
+ gsi(333)
+ check_gsi(gsi, -100, -100, 1, -11)
diff --git a/Examples/test-suite/python/python_destructor_exception_runme.py b/Examples/test-suite/python/python_destructor_exception_runme.py
index ee71ab33b..47659531b 100644
--- a/Examples/test-suite/python/python_destructor_exception_runme.py
+++ b/Examples/test-suite/python/python_destructor_exception_runme.py
@@ -1,7 +1,11 @@
import python_destructor_exception
-from StringIO import StringIO
import sys
+if sys.version_info[0:2] < (3, 0):
+ import StringIO as io
+else:
+ import io
+
def error_function():
python_destructor_exception.ClassWithThrowingDestructor().GetBlah()
@@ -9,13 +13,13 @@ def runtest():
attributeErrorOccurred = False
try:
error_function()
- except AttributeError, e:
+ except AttributeError:
attributeErrorOccurred = True
return attributeErrorOccurred
def test1():
stderr_saved = sys.stderr
- buffer = StringIO()
+ buffer = io.StringIO()
attributeErrorOccurred = False
try:
# Suppress stderr while making this call to suppress the output shown by PyErr_WriteUnraisable
diff --git a/Examples/test-suite/python/python_flatstaticmethod_runme.py b/Examples/test-suite/python/python_flatstaticmethod_runme.py
new file mode 100644
index 000000000..13d935f47
--- /dev/null
+++ b/Examples/test-suite/python/python_flatstaticmethod_runme.py
@@ -0,0 +1,92 @@
+from python_flatstaticmethod import *
+import inspect
+
+# This testcase tests C++ class static functions when using legacy "flattened"
+# staticmethod access, A_bar, as well as the normal staticmethod access, A.bar.
+
+
+def check(got, expected):
+ if got != expected:
+ raise RuntimeError("\ngot :{}\nwant:{}\n".format(got, expected))
+
+if A_bar(2) != 4:
+ raise RuntimeError
+
+if A.bar(2) != 4:
+ raise RuntimeError
+
+# %callback
+if foobar(3, A_bar) != A_bar(3):
+ raise RuntimeError
+
+if foobar(3, A.bar) != A_bar(3):
+ raise RuntimeError
+
+# kwargs
+if A_pub() != 1:
+ raise RuntimeError
+
+if A_pub(b=2) != 3:
+ raise RuntimeError
+
+if A_pub(b=10,a=20) != 30:
+ raise RuntimeError
+
+if A.pub() != 1:
+ raise RuntimeError
+
+if A.pub(b=2) != 3:
+ raise RuntimeError
+
+if A.pub(b=10,a=20) != 30:
+ raise RuntimeError
+
+check(inspect.getdoc(A_func0static),
+ "A_func0static(e, arg2, hello, f=2) -> int")
+check(inspect.getdoc(A_func1static),
+ "A_func1static(A e, short arg2, Tuple hello, double f=2) -> int")
+
+# overloaded static functions
+if A_over(3) != "over:int":
+ raise RuntimeError("A::over(int)")
+
+if A_over(3.0) != "over:double":
+ raise RuntimeError("A::over(double)")
+
+if A_over("hello") != "over:char *":
+ raise RuntimeError("A::over(char *)")
+
+if A.over(3) != "over:int":
+ raise RuntimeError("A::over(int)")
+
+if A.over(3.0) != "over:double":
+ raise RuntimeError("A::over(double)")
+
+if A.over("hello") != "over:char *":
+ raise RuntimeError("A::over(char *)")
+
+# default args
+if A_defargs() != 30:
+ raise RuntimeError
+
+if A_defargs(1) != 21:
+ raise RuntimeError
+
+if A_defargs(1, 2) != 3:
+ raise RuntimeError
+
+if A.defargs() != 30:
+ raise RuntimeError
+
+if A.defargs(1) != 21:
+ raise RuntimeError
+
+if A.defargs(1, 2) != 3:
+ raise RuntimeError
+
+# %extend
+if A_staticextended(11) != 11:
+ raise RuntimeError
+
+if A.staticextended(11) != 11:
+ raise RuntimeError
diff --git a/Examples/test-suite/python/python_nondynamic_runme.py b/Examples/test-suite/python/python_nondynamic_runme.py
index fbb60ad36..870c70b3b 100644
--- a/Examples/test-suite/python/python_nondynamic_runme.py
+++ b/Examples/test-suite/python/python_nondynamic_runme.py
@@ -1,9 +1,5 @@
import python_nondynamic
-def is_python_modern():
- """Return True if SWIG is generating Python code using -modern. Works only if %python_nondynamic has been used."""
- return hasattr(python_nondynamic, "_swig_setattr_nondynamic_class_variable")
-
def debug_print(s):
show_debug = False
if show_debug:
@@ -51,9 +47,7 @@ if python_nondynamic.retrieve_A_b(bb) != 5: raise RuntimeError("b not set correc
try:
bb.c = 3
- print("bb.c = {}".format(bb.c))
- print("B.c = {}".format(B.c))
- raise RuntimeError("B.c class variable messes up nondynamic-ness of B")
+ raise RuntimeError("B.c class variable messes up nondynamic-ness of B bb.c={} B.c={}".format(bb.c, B.c))
except AttributeError as e:
debug_print(e)
pass
@@ -68,7 +62,7 @@ except AttributeError as e:
cc = python_nondynamic.C()
cc.d = 3
-# An inconsistency between builtin and (non-builtin/modern).
+# An inconsistency between builtin and non-builtin.
# Class variables cannot be set on builtin types, like other Python builtins, eg list.classvar=111 fails
if python_nondynamic.is_python_builtin():
try:
@@ -80,8 +74,8 @@ if python_nondynamic.is_python_builtin():
else:
python_nondynamic.C.classvar = 111
-if is_python_modern() and not python_nondynamic.is_python_builtin():
- # Not working with builtin or non-modern :(
+if not python_nondynamic.is_python_builtin():
+ # Not working with builtin :(
try:
B.a = 10
raise RuntimeError("B should not allow adding a class variable by setting it as an instance variable")
@@ -99,9 +93,7 @@ if is_python_modern() and not python_nondynamic.is_python_builtin():
if not python_nondynamic.is_python_builtin():
try:
bb.cc = 3
- print("bb.cc = {}".format(bb.cc))
- print("B.cc = {}".format(B.cc))
- raise RuntimeError("B.cc class variable messes up nondynamic-ness of B")
+ raise RuntimeError("B.cc class variable messes up nondynamic-ness of B bb.cc={} B.cc={}".format(bb.cc, B.cc))
except AttributeError as e:
debug_print(e)
pass
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 d4cb8a37a..e40a34a81 100644
--- a/Examples/test-suite/python/python_overload_simple_cast_runme.py
+++ b/Examples/test-suite/python/python_overload_simple_cast_runme.py
@@ -1,5 +1,6 @@
from python_overload_simple_cast import *
+import sys
class Ai:
@@ -9,6 +10,8 @@ class Ai:
def __int__(self):
return self.x
+ def __index__(self):
+ return self.x
class Ad:
@@ -30,166 +33,264 @@ except:
good = 1
if not good:
- raise RuntimeError, "fint(int)"
+ raise RuntimeError("fint(int)")
if fint(ad) != "fint:int":
- raise RuntimeError, "fint(int)"
+ raise RuntimeError("fint(int)")
if fdouble(ad) != "fdouble:double":
- raise RuntimeError, "fdouble(double)"
+ raise RuntimeError("fdouble(double)")
if fint(ai) != "fint:int":
- raise RuntimeError, "fint(int)"
+ raise RuntimeError("fint(int)")
if fint(5.0) != "fint:int":
- raise RuntimeError, "fint(int)"
+ raise RuntimeError("fint(int)")
if fint(3) != "fint:int":
- raise RuntimeError, "fint(int)"
+ raise RuntimeError("fint(int)")
if fint(3.0) != "fint:int":
- raise RuntimeError, "fint(int)"
+ raise RuntimeError("fint(int)")
if fdouble(ad) != "fdouble:double":
- raise RuntimeError, "fdouble(double)"
+ raise RuntimeError("fdouble(double)")
if fdouble(3) != "fdouble:double":
- raise RuntimeError, "fdouble(double)"
+ raise RuntimeError("fdouble(double)")
if fdouble(3.0) != "fdouble:double":
- raise RuntimeError, "fdouble(double)"
+ raise RuntimeError("fdouble(double)")
if fid(3, 3.0) != "fid:intdouble":
- raise RuntimeError, "fid:intdouble"
+ raise RuntimeError("fid:intdouble")
if fid(3.0, 3) != "fid:doubleint":
- raise RuntimeError, "fid:doubleint"
+ raise RuntimeError("fid:doubleint")
if fid(ad, ai) != "fid:doubleint":
- raise RuntimeError, "fid:doubleint"
+ raise RuntimeError("fid:doubleint")
if fid(ai, ad) != "fid:intdouble":
- raise RuntimeError, "fid:intdouble"
+ raise RuntimeError("fid:intdouble")
if foo(3) != "foo:int":
- raise RuntimeError, "foo(int)"
+ raise RuntimeError("foo(int)")
if foo(3.0) != "foo:double":
- raise RuntimeError, "foo(double)"
+ raise RuntimeError("foo(double)")
if foo("hello") != "foo:char *":
- raise RuntimeError, "foo(char *)"
+ raise RuntimeError("foo(char *)")
f = Foo()
b = Bar()
if foo(f) != "foo:Foo *":
- raise RuntimeError, "foo(Foo *)"
+ raise RuntimeError("foo(Foo *)")
if foo(b) != "foo:Bar *":
- raise RuntimeError, "foo(Bar *)"
+ raise RuntimeError("foo(Bar *)")
v = malloc_void(32)
if foo(v) != "foo:void *":
- raise RuntimeError, "foo(void *)"
+ raise RuntimeError("foo(void *)")
s = Spam()
if s.foo(3) != "foo:int":
- raise RuntimeError, "Spam::foo(int)"
+ raise RuntimeError("Spam::foo(int)")
if s.foo(3.0) != "foo:double":
- raise RuntimeError, "Spam::foo(double)"
+ raise RuntimeError("Spam::foo(double)")
if s.foo("hello") != "foo:char *":
- raise RuntimeError, "Spam::foo(char *)"
+ raise RuntimeError("Spam::foo(char *)")
if s.foo(f) != "foo:Foo *":
- raise RuntimeError, "Spam::foo(Foo *)"
+ raise RuntimeError("Spam::foo(Foo *)")
if s.foo(b) != "foo:Bar *":
- raise RuntimeError, "Spam::foo(Bar *)"
+ raise RuntimeError("Spam::foo(Bar *)")
if s.foo(v) != "foo:void *":
- raise RuntimeError, "Spam::foo(void *)"
+ raise RuntimeError("Spam::foo(void *)")
-if Spam_bar(3) != "bar:int":
- raise RuntimeError, "Spam::bar(int)"
+if Spam.bar(3) != "bar:int":
+ raise RuntimeError("Spam::bar(int)")
-if Spam_bar(3.0) != "bar:double":
- raise RuntimeError, "Spam::bar(double)"
+if Spam.bar(3.0) != "bar:double":
+ raise RuntimeError("Spam::bar(double)")
-if Spam_bar("hello") != "bar:char *":
- raise RuntimeError, "Spam::bar(char *)"
+if Spam.bar("hello") != "bar:char *":
+ raise RuntimeError("Spam::bar(char *)")
-if Spam_bar(f) != "bar:Foo *":
- raise RuntimeError, "Spam::bar(Foo *)"
+if Spam.bar(f) != "bar:Foo *":
+ raise RuntimeError("Spam::bar(Foo *)")
-if Spam_bar(b) != "bar:Bar *":
- raise RuntimeError, "Spam::bar(Bar *)"
+if Spam.bar(b) != "bar:Bar *":
+ raise RuntimeError("Spam::bar(Bar *)")
-if Spam_bar(v) != "bar:void *":
- raise RuntimeError, "Spam::bar(void *)"
+if Spam.bar(v) != "bar:void *":
+ raise RuntimeError("Spam::bar(void *)")
# Test constructors
s = Spam()
if s.type != "none":
- raise RuntimeError, "Spam()"
+ raise RuntimeError("Spam()")
s = Spam(3)
if s.type != "int":
- raise RuntimeError, "Spam(int)"
+ raise RuntimeError("Spam(int)")
s = Spam(3.4)
if s.type != "double":
- raise RuntimeError, "Spam(double)"
+ raise RuntimeError("Spam(double)")
s = Spam("hello")
if s.type != "char *":
- raise RuntimeError, "Spam(char *)"
+ raise RuntimeError("Spam(char *)")
s = Spam(f)
if s.type != "Foo *":
- raise RuntimeError, "Spam(Foo *)"
+ raise RuntimeError("Spam(Foo *)")
s = Spam(b)
if s.type != "Bar *":
- raise RuntimeError, "Spam(Bar *)"
+ raise RuntimeError("Spam(Bar *)")
s = Spam(v)
if s.type != "void *":
- raise RuntimeError, "Spam(void *)"
-
+ raise RuntimeError("Spam(void *)")
+
+
+# nextafter: ++ and -- operators for float, off by one LSB
+# nextafter was released in Python 3.9
+if sys.version_info[0:2] >= (3, 9):
+ from math import inf, nextafter
+else:
+ # workaround: try to load nextafter from numpy if available
+ try:
+ # Skip numpy workaround for consistency in testing
+ if True:
+ raise RuntimeError("skip test")
+ from numpy import nextafter
+ except:
+ # else just disable this tests
+ def nextafter(x, y):
+ return None
+
+ # math.inf was added in Python 3.5
+ inf = float('inf')
+
+def exceptMatch(fun, arg, res, msg):
+ if arg is None or res is None:
+ # nextafter is missing, so skipping this test
+ return
+ if fun(arg) != res:
+ raise RuntimeError(msg)
+
+def exceptTypeError(fun, arg, msg):
+ if arg is None:
+ # nextafter is missing, so skipping this test
+ return
+ try:
+ fun(arg)
+ raise RuntimeError(msg)
+ except TypeError:
+ pass
+
+# x86_64: long is 32bit on MSVC but 64bit on *nix
+if not(sizeof_long() in [4, 8]):
+ raise RuntimeError("Unexpected size for long")
+
+# unsigned long
+ulmax = 2**32 - 1
+ulmin = 0
+ulmaxd = float(2**32 - 1)
+ulmind = 0.0
+if sizeof_long() == 8:
+ ulmax = 2**64 - 1
+ ulmaxd = nextafter(float(2**64), 0.0)
+
+exceptMatch(as_ul, ulmin, ulmin, "as_ul(ulmin)")
+exceptMatch(as_ul, ulmax, ulmax, "as_ul(ulmax)")
+exceptMatch(as_ul, ulmind, ulmind, "as_ul(ulmind)")
+exceptMatch(as_ul, ulmaxd, ulmaxd, "as_ul(ulmaxd)")
+
+exceptTypeError(as_ul, ulmin - 1, "as_ul(ulmin - 1)")
+exceptTypeError(as_ul, ulmax + 1, "as_ul(ulmax + 1)")
+exceptTypeError(as_ul, nextafter(ulmind, -inf), "as_ul(ulmind - LSB)")
+exceptTypeError(as_ul, nextafter(ulmaxd, inf), "as_ul(ulmaxd + LSB)")
+
+# long
+lmax = 2**31 - 1
+lmin = -2**31
+lmaxd = float(2**31 - 1)
+lmind = float(-2**31)
+lmaxd_v = lmaxd # expected value after the cast
+lmind_v = lmind
+if sys.version_info[0:2] < (3, 10):
+ # PyLong_AsLong(float) truncated the input before 3.10
+ lmaxd = nextafter(float(2**31), 0.0)
+ lmind = nextafter(float(-2**31 - 1), 0.0)
+ lmaxd_v = float(2**31 - 1)
+ lmind_v = float(-2**31)
+if sizeof_long() == 8:
+ lmax = 2**63 - 1
+ lmin = -2**63
+ lmaxd = nextafter(float(2**63), 0.0)
+ lmind = float(-2**63)
+ lmaxd_v = lmaxd
+ lmind_v = lmind
+
+exceptMatch(as_l, lmin, lmin, "as_l(lmin)")
+exceptMatch(as_l, lmax, lmax, "as_l(lmax)")
+exceptMatch(as_l, lmind, lmind_v, "as_l(lmind)")
+exceptMatch(as_l, lmaxd, lmaxd_v, "as_l(lmaxd)")
+
+exceptTypeError(as_l, lmin - 1, "as_l(lmin - 1)")
+exceptTypeError(as_l, lmax + 1, "as_l(lmax + 1)")
+exceptTypeError(as_l, nextafter(lmind, -inf), "as_l(lmind - LSB)")
+exceptTypeError(as_l, nextafter(lmaxd, inf), "as_l(lmaxd + LSB)")
# unsigned long long
-ullmax = 9223372036854775807 # 0xffffffffffffffff
-ullmaxd = 9007199254740992.0
+ullmax = 2**64 - 1
ullmin = 0
+ullmaxd = float(2**53) # 64 bit double significand
ullmind = 0.0
-if ull(ullmin) != ullmin:
- raise RuntimeError, "ull(ullmin)"
-if ull(ullmax) != ullmax:
- raise RuntimeError, "ull(ullmax)"
-if ull(ullmind) != ullmind:
- raise RuntimeError, "ull(ullmind)"
-if ull(ullmaxd) != ullmaxd:
- raise RuntimeError, "ull(ullmaxd)"
+if sizeof_long() == 8:
+ ullmaxd = nextafter(float(2**64), 0.0)
+
+exceptMatch(as_ull, ullmin, ullmin, "as_ull(ullmin)")
+exceptMatch(as_ull, ullmax, ullmax, "as_ull(ullmax)")
+exceptMatch(as_ull, ullmind, ullmind, "as_ull(ullmind)")
+exceptMatch(as_ull, ullmaxd, ullmaxd, "as_ull(ullmaxd)")
+
+exceptTypeError(as_ull, ullmin - 1, "as_ull(ullmin - 1)")
+exceptTypeError(as_ull, ullmax + 1, "as_ull(ullmax + 1)")
+exceptTypeError(as_ull, nextafter(ullmind, -inf), "as_ull(ullmind - LSB)")
+exceptTypeError(as_ull, nextafter(ullmaxd, inf), "as_ull(ullmaxd + LSB)")
# long long
-llmax = 9223372036854775807 # 0x7fffffffffffffff
-llmin = -9223372036854775808
-# these are near the largest floats we can still convert into long long
-llmaxd = 9007199254740992.0
-llmind = -9007199254740992.0
-if ll(llmin) != llmin:
- raise RuntimeError, "ll(llmin)"
-if ll(llmax) != llmax:
- raise RuntimeError, "ll(llmax)"
-if ll(llmind) != llmind:
- raise RuntimeError, "ll(llmind)"
-if ll(llmaxd) != llmaxd:
- raise RuntimeError, "ll(llmaxd)"
+llmax = 2**63 - 1
+llmin = -2**63
+llmaxd = float(2**53) # 64 bit double significand
+llmind = float(-2**53)
+if sizeof_long() == 8:
+ llmaxd = nextafter(float(2**63), 0.0)
+ llmind = float(-2**63)
+
+exceptMatch(as_ll, llmin, llmin, "as_ll(llmin)")
+exceptMatch(as_ll, llmax, llmax, "as_ll(llmax)")
+exceptMatch(as_ll, llmind, llmind, "as_ll(llmind)")
+exceptMatch(as_ll, llmaxd, llmaxd, "as_ll(llmaxd)")
+
+exceptTypeError(as_ll, llmin - 1, "as_ll(llmin - 1)")
+exceptTypeError(as_ll, llmax + 1, "as_ll(llmax + 1)")
+exceptTypeError(as_ll, nextafter(llmind, -inf), "as_ll(llmind - LSB)")
+exceptTypeError(as_ll, nextafter(llmaxd, inf), "as_ll(llmaxd + LSB)")
free_void(v)
diff --git a/Examples/test-suite/python/python_pickle_runme.py b/Examples/test-suite/python/python_pickle_runme.py
index 27c67ae10..7cb07ef59 100644
--- a/Examples/test-suite/python/python_pickle_runme.py
+++ b/Examples/test-suite/python/python_pickle_runme.py
@@ -8,22 +8,22 @@ def check(p):
if msg != "hi there":
raise RuntimeError("Bad, got: " + msg)
-python_pickle.cvar.debug = False
+python_pickle.cvar.trace = False
p = python_pickle.PickleMe("hi there")
check(p)
r = p.__reduce__()
-if python_pickle.cvar.debug:
- print "__reduce__ returned:", r
+if python_pickle.cvar.trace:
+ print("__reduce__ returned: {}".format(r))
pickle_string = pickle.dumps(p)
newp = pickle.loads(pickle_string)
check(newp)
# Not yet working... some crash and others are not producing a sensible "can't be pickled" error
#nfp = python_pickle.NotForPickling("no no")
-#print nfp.__reduce__()
+#print("{}".format(nfp.__reduce__()))
#pickle_string = pickle.dumps(nfp)
-#print pickle_string
+#print("{}".format(pickle_string))
#newp = pickle.loads(pickle_string)
-#print newp.msg
+#print("{}".format(newp.msg))
diff --git a/Examples/test-suite/python/python_pybuffer_runme.py b/Examples/test-suite/python/python_pybuffer_runme.py
index 8ecdb523b..65079200b 100644
--- a/Examples/test-suite/python/python_pybuffer_runme.py
+++ b/Examples/test-suite/python/python_pybuffer_runme.py
@@ -17,13 +17,13 @@ if len(sys.argv) >= 2 and sys.argv[1] == "benchmark":
a = bytearray(b"hello world")
for i in range(k):
python_pybuffer.title1(a)
- print "Time used by bytearray:", time.time() - t
+ print("Time used by bytearray: {}".format(time.time() - t))
t = time.time()
b = "hello world"
for i in range(k):
python_pybuffer.title2(b)
- print "Time used by string:", time.time() - t
+ print("Time used by string: {}".format(time.time() - t))
else:
# run the test case
buf1 = bytearray(10)
@@ -44,3 +44,27 @@ else:
buf3 = bytearray(b"hello")
python_pybuffer.title1(buf3)
check(buf3 == b"Hello")
+
+ try:
+ python_pybuffer.func1(1)
+ raise RuntimeError("should throw TypeError")
+ except TypeError as e:
+ check("(char *buf1, int len)" in str(e))
+
+ try:
+ python_pybuffer.func2(1)
+ raise RuntimeError("should throw TypeError")
+ except TypeError as e:
+ check("(char *buf2)" in str(e))
+
+ try:
+ python_pybuffer.func3(1)
+ raise RuntimeError("should throw TypeError")
+ except TypeError as e:
+ check("(const char *buf3, int len)" in str(e))
+
+ try:
+ python_pybuffer.func4(1)
+ raise RuntimeError("should throw TypeError")
+ except TypeError as e:
+ check("(const char *buf4)" in str(e))
diff --git a/Examples/test-suite/python/python_richcompare_runme.py b/Examples/test-suite/python/python_richcompare_runme.py
index 724d1d73c..09af8a4e8 100644
--- a/Examples/test-suite/python/python_richcompare_runme.py
+++ b/Examples/test-suite/python/python_richcompare_runme.py
@@ -114,22 +114,22 @@ else:
try:
res = base1 < 42
raise RuntimeError("Failed to throw")
- except TypeError,e:
+ except TypeError as e:
check_unorderable_types(e)
try:
res = base1 <= 42
raise RuntimeError("Failed to throw")
- except TypeError,e:
+ except TypeError as e:
check_unorderable_types(e)
try:
res = base1 > 42
raise RuntimeError("Failed to throw")
- except TypeError,e:
+ except TypeError as e:
check_unorderable_types(e)
try:
res = base1 >= 42
raise RuntimeError("Failed to throw")
- except TypeError,e:
+ except TypeError as e:
check_unorderable_types(e)
# Check inequalities used for ordering
@@ -156,3 +156,83 @@ if not (x[1] is base2):
if not (x[2] is a3):
raise RuntimeError("Ordering failed")
+
+
+# Test custom exceptions can still be thrown in operators which use %pythonmaybecall
+et0 = python_richcompare.ExceptionThrower(0)
+et1 = python_richcompare.ExceptionThrower(1)
+et2 = python_richcompare.ExceptionThrower(2)
+
+if not(et1 < et2):
+ raise RuntimeError("ExceptionThrower (a) failed")
+
+if et2 < et1:
+ raise RuntimeError("ExceptionThrower (b) failed")
+
+try:
+ x = et2 < et0
+ raise RuntimeError("ExceptionThrower failed to throw ValueError (A)")
+except ValueError:
+ pass
+
+try:
+ x = et0 < et2
+ raise RuntimeError("ExceptionThrower failed to throw ValueError (B)")
+except ValueError:
+ pass
+
+if sys.version_info[0:2] >= (3, 0):
+ try:
+ x = et2 < 99
+ raise RuntimeError("ExceptionThrower (d) failed")
+ except TypeError:
+ pass
+
+ try:
+ x = 99 < et2
+ raise RuntimeError("ExceptionThrower (e) failed")
+ except TypeError:
+ pass
+
+ try:
+ x = et0 < 99
+ raise RuntimeError("ExceptionThrower (f) failed")
+ except TypeError:
+ pass
+
+ try:
+ x = 99 < et0
+ raise RuntimeError("ExceptionThrower (g) failed")
+ except TypeError:
+ pass
+
+
+# Overloaded operators and custom exceptions
+c0 = python_richcompare.SubClassCThrower(0)
+c1 = python_richcompare.SubClassCThrower(1)
+c1b = python_richcompare.SubClassCThrower(1)
+c2 = python_richcompare.SubClassCThrower(2)
+
+if c1 == c2:
+ raise RuntimeError("SubClassCThrower failed (a)")
+
+if not(c1 == c1b):
+ raise RuntimeError("SubClassCThrower failed (b)")
+
+if c0 == 99:
+ raise RuntimeError("SubClassCThrower failed (c)")
+
+if 99 == c0:
+ raise RuntimeError("SubClassCThrower failed (d)")
+
+try:
+ x = c0 == c1
+ raise RuntimeError("SubClassCThrower failed to throw (A)")
+except ValueError:
+ pass
+
+try:
+ x = c1 == c0
+ raise RuntimeError("SubClassCThrower failed to throw (B)")
+except ValueError:
+ pass
diff --git a/Examples/test-suite/python/python_runtime_data_runme.py b/Examples/test-suite/python/python_runtime_data_runme.py
new file mode 100644
index 000000000..063bf82d1
--- /dev/null
+++ b/Examples/test-suite/python/python_runtime_data_runme.py
@@ -0,0 +1,15 @@
+import python_runtime_data_builtin as builtin
+import python_runtime_data_nobuiltin as nobuiltin
+
+def swig_assert(a):
+ if not a:
+ raise RuntimeError("Failed")
+
+swig_assert(builtin.is_python_builtin())
+swig_assert(not nobuiltin.is_python_builtin())
+
+for i in range(1, 5):
+ v1 = builtin.vectord([1.] * i)
+ swig_assert(len(v1) == i)
+ v2 = nobuiltin.vectord([1.] * i)
+ swig_assert(len(v2) == i)
diff --git a/Examples/test-suite/python/python_strict_unicode_runme.py b/Examples/test-suite/python/python_strict_unicode_runme.py
index e7fae2556..79c768de1 100644
--- a/Examples/test-suite/python/python_strict_unicode_runme.py
+++ b/Examples/test-suite/python/python_strict_unicode_runme.py
@@ -1,8 +1,20 @@
import python_strict_unicode
+import sys
test_bytes = b"hello \x01world\x99"
BYTES = b"BYTES"
-test_unicode = u"h\udce9llo w\u00f6rld"
+
+if sys.version_info[0:2] < (3, 0):
+ # Python 3.0-3.2 results in a SyntaxError when using u"" string literals, so we use a
+ # convoluted unicode string construction using unicode() and unichr().
+ # Conventional Python 2 syntax shown in comments.
+ test_unicode = unicode("h" + unichr(0xdce9) + "llo w" + unichr(0x00f6) + "rld") # u"h\udce9llo w\u00f6rld"
+ UNICODE = unicode("UNICODE")
+ type_unicode_string = type(UNICODE)
+else:
+ test_unicode = "h\udce9llo w\u00f6rld"
+ UNICODE = "UNICODE"
+ type_unicode_string = type(UNICODE)
# Test that byte string inputs and outputs work as expected
bdbl = python_strict_unicode.double_str(test_bytes)
@@ -20,12 +32,12 @@ if type(bout) != type(BYTES):
udbl = python_strict_unicode.double_wstr(test_unicode)
if udbl != test_unicode + test_unicode:
raise RuntimeError("Failed to double wide string")
-if type(udbl) != type(u""):
+if type(udbl) != type_unicode_string:
raise RuntimeError("Wrong type output for wide string")
uout = python_strict_unicode.same_wstr(test_unicode)
if uout != test_unicode:
raise RuntimeError("Failed to copy wchar_t*")
-if type(uout) != type(u""):
+if type(uout) != type_unicode_string:
raise RuntimeError("Wrong type output for wchar_t*")
# Test that overloading is handled properly
@@ -35,9 +47,9 @@ if bovr != BYTES:
if type(bovr) != type(BYTES):
raise RuntimeError("Wrong type output from overload")
uovr = python_strict_unicode.overload(test_unicode)
-if uovr != u"UNICODE":
+if uovr != UNICODE:
raise RuntimeError("Failed to return unicode from overload")
-if type(uovr) != type(u""):
+if type(uovr) != type_unicode_string:
raise RuntimeERror("Wrong type output from overload")
# Test that bytes aren't accepted as wide strings and unicode isn't accepted as narrow strings
diff --git a/Examples/test-suite/python/python_typemap_macro_runme.py b/Examples/test-suite/python/python_typemap_macro_runme.py
new file mode 100644
index 000000000..ec494e077
--- /dev/null
+++ b/Examples/test-suite/python/python_typemap_macro_runme.py
@@ -0,0 +1,27 @@
+from python_typemap_macro import *
+
+psi = PairStringInt(["i am a string", 5])
+psi = PairStringInt(psi)
+pcpsi = PairCharPairStringInt(['a', psi])
+pcpsi = PairCharPairStringInt(['b', ["i am a string", 5]])
+
+psi = PairInputOutput(["list item 1", 55])
+PairInputOutput(psi)
+PairInputOutput(PairStringInt())
+
+pcpsi = MakePair()
+if pcpsi != ('x', ('outstring', 111)):
+ raise RuntimeError("failed {}".format(pcpsi))
+
+pcpsi = PairInputOutput2(['c', ["list item 1", 55]])
+if pcpsi != ('c', ('list item 1', 55)):
+ raise RuntimeError("failed {}".format(pcpsi))
+
+pcpsi = PairInputOutput2(pcpsi)
+pcpsi = PairInputOutput2(['c', ["list item 1", 55]])
+if pcpsi != ('c', ('list item 1', 55)):
+ raise RuntimeError("failed {}".format(pcpsi))
+
+pcpsi = PairInputOutput2(PairCharPairStringInt())
+if pcpsi != ('\x00', ('', 0)):
+ raise RuntimeError("failed {}".format(pcpsi))
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 ff3bd5f02..8cbac125c 100644
--- a/Examples/test-suite/python/return_const_value_runme.py
+++ b/Examples/test-suite/python/return_const_value_runme.py
@@ -1,12 +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):
- print "Runtime test1 failed. p.getVal()=", p.getVal()
- sys.exit(1)
+ 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):
- print "Runtime test2 failed. p.getVal()=", p.getVal()
- sys.exit(1)
+ raise RuntimeError("Runtime test2 failed. p.getVal()={}".format(p.getVal()))
diff --git a/Examples/test-suite/python/smart_pointer_member_runme.py b/Examples/test-suite/python/smart_pointer_member_runme.py
index d2ed87e79..9758b0ba4 100644
--- a/Examples/test-suite/python/smart_pointer_member_runme.py
+++ b/Examples/test-suite/python/smart_pointer_member_runme.py
@@ -11,9 +11,7 @@ b = Bar(f)
b.y = 2
if f.y != 2:
- print f.y
- print b.y
- raise RuntimeError
+ raise RuntimeError("Failed {} {}".format(f.y, b.y))
if b.x != f.x:
raise RuntimeError
diff --git a/Examples/test-suite/python/smart_pointer_not_runme.py b/Examples/test-suite/python/smart_pointer_not_runme.py
index 69704c4ef..8cd9f11f3 100644
--- a/Examples/test-suite/python/smart_pointer_not_runme.py
+++ b/Examples/test-suite/python/smart_pointer_not_runme.py
@@ -7,36 +7,36 @@ g = Grok(f)
try:
x = b.x
- print "Error! b.x"
-except:
+ raise RuntimeError("Error! b.x")
+except AttributeError:
pass
try:
x = s.x
- print "Error! s.x"
-except:
+ raise RuntimeError("Error! s.x")
+except AttributeError:
pass
try:
x = g.x
- print "Error! g.x"
-except:
+ raise RuntimeError("Error! g.x")
+except AttributeError:
pass
try:
x = b.getx()
- print "Error! b.getx()"
-except:
+ raise RuntimeError("Error! b.getx()")
+except AttributeError:
pass
try:
x = s.getx()
- print "Error! s.getx()"
-except:
+ raise RuntimeError("Error! s.getx()")
+except AttributeError:
pass
try:
x = g.getx()
- print "Error! g.getx()"
-except:
+ raise RuntimeError("Error! g.getx()")
+except AttributeError:
pass
diff --git a/Examples/test-suite/python/special_variable_macros_runme.py b/Examples/test-suite/python/special_variable_macros_runme.py
index e487f9a50..d06b879cf 100644
--- a/Examples/test-suite/python/special_variable_macros_runme.py
+++ b/Examples/test-suite/python/special_variable_macros_runme.py
@@ -1,10 +1,15 @@
import special_variable_macros
+cvar = special_variable_macros.cvar
name = special_variable_macros.Name()
if special_variable_macros.testFred(name) != "none":
raise "test failed"
+if cvar.accessed_examplekw != 0:
+ raise "Precondition failed"
if special_variable_macros.testJack(name) != "$specialname":
raise "test failed"
+if cvar.accessed_examplekw != 1:
+ raise "Postcondition failed"
if special_variable_macros.testJill(name) != "jilly":
raise "test failed"
if special_variable_macros.testMary(name) != "SWIGTYPE_p_NameWrap":
@@ -15,3 +20,7 @@ if special_variable_macros.testJim(name) != "multiname num":
raise "test failed"
if special_variable_macros.testJohn(special_variable_macros.PairIntBool(10, False)) != 123:
raise "test failed"
+if special_variable_macros.makeStringInt("stringint", 999) != "stringint":
+ raise "test failed"
+if special_variable_macros.provideStringInt(999) != "1000":
+ raise "test failed"
diff --git a/Examples/test-suite/python/std_containers_runme.py b/Examples/test-suite/python/std_containers_runme.py
index 7404cd5f4..820c8f454 100644
--- a/Examples/test-suite/python/std_containers_runme.py
+++ b/Examples/test-suite/python/std_containers_runme.py
@@ -7,34 +7,33 @@ cube = (((1, 2), (3, 4)), ((5, 6), (7, 8)))
icube = std_containers.cident(cube)
for i in range(0, len(cube)):
if cube[i] != icube[i]:
- raise RuntimeError, "bad cident"
+ raise RuntimeError("bad cident")
p = (1, 2)
if p != std_containers.pident(p):
- raise RuntimeError, "bad pident"
+ raise RuntimeError("bad pident")
v = (1, 2, 3, 4, 5, 6)
iv = std_containers.vident(v)
for i in range(0, len(v)):
if v[i] != iv[i]:
- raise RuntimeError, "bad vident"
+ raise RuntimeError("bad vident")
iv = std_containers.videntu(v)
for i in range(0, len(v)):
if v[i] != iv[i]:
- raise RuntimeError, "bad videntu"
+ raise RuntimeError("bad videntu")
vu = std_containers.vector_ui(v)
if vu[2] != std_containers.videntu(vu)[2]:
- raise RuntimeError, "bad videntu"
+ raise RuntimeError("bad videntu")
if v[0:3][1] != vu[0:3][1]:
- print v[0:3][1], vu[0:3][1]
- raise RuntimeError, "bad getslice"
+ raise RuntimeError("bad getslice {} {}".format(v[0:3][1], vu[0:3][1]))
m = ((1, 2, 3), (2, 3), (3, 4))
@@ -43,20 +42,20 @@ im = std_containers.midenti(m)
for i in range(0, len(m)):
for j in range(0, len(m[i])):
if m[i][j] != im[i][j]:
- raise RuntimeError, "bad getslice"
+ raise RuntimeError("bad getslice")
m = ((True, False, True), (True, True), (True, True))
im = std_containers.midentb(m)
for i in range(0, len(m)):
for j in range(0, len(m[i])):
if m[i][j] != im[i][j]:
- raise RuntimeError, "bad getslice"
+ raise RuntimeError("bad getslice")
mi = std_containers.imatrix(m)
mc = std_containers.cmatrix(m)
if mi[0][1] != mc[0][1]:
- raise RuntimeError, "bad matrix"
+ raise RuntimeError("bad matrix")
map = {}
@@ -67,7 +66,7 @@ map["3"] = 2
imap = std_containers.mapident(map)
for k in map:
if map[k] != imap[k]:
- raise RuntimeError, "bad map"
+ raise RuntimeError("bad map")
# Test __contains__ (required for 'x in y' to work)
if not imap.__contains__("hello"):
diff --git a/Examples/test-suite/python/struct_value_runme.py b/Examples/test-suite/python/struct_value_runme.py
index aa3ece38c..9fe5c815c 100644
--- a/Examples/test-suite/python/struct_value_runme.py
+++ b/Examples/test-suite/python/struct_value_runme.py
@@ -17,7 +17,7 @@ b.added = 123
if b.added != 123:
raise RuntimeError("Wrong attribute value")
-if not b.__dict__.has_key("added"):
+if "added" not in b.__dict__:
raise RuntimeError("Missing added attribute in __dict__")
@@ -28,7 +28,7 @@ class PyBar(struct_value.Bar):
struct_value.Bar.__init__(self)
pybar = PyBar()
-if not pybar.__dict__.has_key("extra"):
+if "extra" not in pybar.__dict__:
raise RuntimeError("Missing extra attribute in __dict__")
if pybar.extra != "hi":
raise RuntimeError("Incorrect attribute value for extra")
diff --git a/Examples/test-suite/python/swigobject_runme.py b/Examples/test-suite/python/swigobject_runme.py
index de232f580..e28e187c9 100644
--- a/Examples/test-suite/python/swigobject_runme.py
+++ b/Examples/test-suite/python/swigobject_runme.py
@@ -1,5 +1,5 @@
-
from swigobject import *
+import sys
a = A()
@@ -11,7 +11,11 @@ if a1.this != a2.this:
raise RuntimeError
-lthis = long(a.this)
+if sys.version_info[0:2] < (3, 0):
+ lthis = long(a.this)
+else:
+ lthis = int(a.this)
+
# match pointer value, but deal with leading zeros on 8/16 bit systems and
# different C++ compilers interpretation of %p
xstr1 = "%016X" % (lthis,)
@@ -23,13 +27,17 @@ xstr2 = str.lstrip(xstr2, "0")
xstr2 = str.upper(xstr2)
if xstr1 != xstr2:
- print xstr1, xstr2
- raise RuntimeError
+ raise RuntimeError("Not equal failed {} {}".format(xstr1, xstr2))
s = str(a.this)
r = repr(a.this)
v1 = v_ptr(a)
v2 = v_ptr(a)
-if long(v1) != long(v2):
- raise RuntimeError
+
+if sys.version_info[0:2] < (3, 0):
+ if long(v1) != long(v2):
+ raise RuntimeError
+else:
+ if int(v1) != int(v2):
+ raise RuntimeError
diff --git a/Examples/test-suite/python/template_classes_runme.py b/Examples/test-suite/python/template_classes_runme.py
index 38b2d7a62..1bd133975 100644
--- a/Examples/test-suite/python/template_classes_runme.py
+++ b/Examples/test-suite/python/template_classes_runme.py
@@ -13,7 +13,7 @@ RectangleInt.static_onearg(1)
fail = True
try:
rectangle.setPoint()
-except TypeError, e:
+except TypeError as e:
fail = False
if fail:
raise RuntimeError("argument count check failed")
@@ -22,7 +22,7 @@ if fail:
fail = True
try:
rectangle.getPoint(0)
-except TypeError, e:
+except TypeError as e:
fail = False
if fail:
raise RuntimeError("argument count check failed")
@@ -30,7 +30,7 @@ if fail:
fail = True
try:
RectangleInt.static_noargs(0)
-except TypeError, e:
+except TypeError as e:
fail = False
if fail:
raise RuntimeError("argument count check failed")
@@ -38,7 +38,7 @@ if fail:
fail = True
try:
RectangleInt.static_onearg()
-except TypeError, e:
+except TypeError as e:
fail = False
if fail:
raise RuntimeError("argument count check failed")
diff --git a/Examples/test-suite/python/template_default_arg_runme.py b/Examples/test-suite/python/template_default_arg_runme.py
index 91b1e0e8c..e9ef00f99 100644
--- a/Examples/test-suite/python/template_default_arg_runme.py
+++ b/Examples/test-suite/python/template_default_arg_runme.py
@@ -7,25 +7,25 @@ helloInt.foo(template_default_arg.Hello_int.hi)
x = template_default_arg.X_int()
if (x.meth(20.0, 200) != 200):
- raise RuntimeError, ("X_int test 1 failed")
+ raise RuntimeError(("X_int test 1 failed"))
if (x.meth(20) != 20):
- raise RuntimeError, ("X_int test 2 failed")
+ raise RuntimeError(("X_int test 2 failed"))
if (x.meth() != 0):
- raise RuntimeError, ("X_int test 3 failed")
+ raise RuntimeError(("X_int test 3 failed"))
y = template_default_arg.Y_unsigned()
if (y.meth(20.0, 200) != 200):
- raise RuntimeError, ("Y_unsigned test 1 failed")
+ raise RuntimeError(("Y_unsigned test 1 failed"))
if (y.meth(20) != 20):
- raise RuntimeError, ("Y_unsigned test 2 failed")
+ raise RuntimeError(("Y_unsigned test 2 failed"))
if (y.meth() != 0):
- raise RuntimeError, ("Y_unsigned test 3 failed")
+ raise RuntimeError(("Y_unsigned test 3 failed"))
x = template_default_arg.X_longlong()
x = template_default_arg.X_longlong(20.0)
-x = template_default_arg.X_longlong(20.0, 200L)
+x = template_default_arg.X_longlong(20.0, 200)
x = template_default_arg.X_int()
@@ -54,40 +54,40 @@ fzc = x.meth(fz)
# plain function: int ott(Foo<int>)
if (template_default_arg.ott(template_default_arg.Foo_int()) != 30):
- raise RuntimeError, ("ott test 1 failed")
+ raise RuntimeError(("ott test 1 failed"))
# %template(ott) ott<int, int>
if (template_default_arg.ott() != 10):
- raise RuntimeError, ("ott test 2 failed")
+ raise RuntimeError(("ott test 2 failed"))
if (template_default_arg.ott(1) != 10):
- raise RuntimeError, ("ott test 3 failed")
+ raise RuntimeError(("ott test 3 failed"))
if (template_default_arg.ott(1, 1) != 10):
- raise RuntimeError, ("ott test 4 failed")
+ raise RuntimeError(("ott test 4 failed"))
if (template_default_arg.ott("hi") != 20):
- raise RuntimeError, ("ott test 5 failed")
+ raise RuntimeError(("ott test 5 failed"))
if (template_default_arg.ott("hi", 1) != 20):
- raise RuntimeError, ("ott test 6 failed")
+ raise RuntimeError(("ott test 6 failed"))
if (template_default_arg.ott("hi", 1, 1) != 20):
- raise RuntimeError, ("ott test 7 failed")
+ raise RuntimeError(("ott test 7 failed"))
# %template(ott) ott<const char *>
if (template_default_arg.ottstring(template_default_arg.Hello_int(), "hi") != 40):
- raise RuntimeError, ("ott test 8 failed")
+ raise RuntimeError(("ott test 8 failed"))
if (template_default_arg.ottstring(template_default_arg.Hello_int()) != 40):
- raise RuntimeError, ("ott test 9 failed")
+ raise RuntimeError(("ott test 9 failed"))
# %template(ott) ott<int>
if (template_default_arg.ottint(template_default_arg.Hello_int(), 1) != 50):
- raise RuntimeError, ("ott test 10 failed")
+ raise RuntimeError(("ott test 10 failed"))
if (template_default_arg.ottint(template_default_arg.Hello_int()) != 50):
- raise RuntimeError, ("ott test 11 failed")
+ raise RuntimeError(("ott test 11 failed"))
# %template(ott) ott<double>
if (template_default_arg.ott(template_default_arg.Hello_int(), 1.0) != 60):
- raise RuntimeError, ("ott test 12 failed")
+ raise RuntimeError(("ott test 12 failed"))
if (template_default_arg.ott(template_default_arg.Hello_int()) != 60):
- raise RuntimeError, ("ott test 13 failed")
+ raise RuntimeError(("ott test 13 failed"))
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/template_template_parameters_runme.py b/Examples/test-suite/python/template_template_parameters_runme.py
new file mode 100644
index 000000000..312935970
--- /dev/null
+++ b/Examples/test-suite/python/template_template_parameters_runme.py
@@ -0,0 +1,33 @@
+from template_template_parameters import *
+
+# Test part 1
+listBool = ListFastBool()
+listBool.item = True
+x_boolean = listBool.allotype
+if listBool.item != True:
+ raise RuntimeError("Failed")
+
+listDouble = ListDefaultDouble()
+listDouble.item = 10.2
+x_double = listDouble.allotype
+if listDouble.item != 10.2:
+ raise RuntimeError("Failed")
+
+# Test part 2
+floatTestStruct = FloatTestStruct()
+floatContainer2 = floatTestStruct.x
+floatContainer2.x = 8.1
+intTestStruct = IntTestStruct()
+intContainer1 = intTestStruct.x
+intContainer1.x = 91
+if intContainer1.x != 91:
+ raise RuntimeError("Failed")
+if intTestStruct.x.x != 91:
+ raise RuntimeError("Failed")
+intTestStructReturned = TestStructContainer1Method(intTestStruct)
+if intTestStructReturned.x.x != 101:
+ raise RuntimeError("Failed")
+
+# Test part 3
+mfi99 = MyFootInt99()
+mfi99 += mfi99 # __iadd__
diff --git a/Examples/test-suite/python/template_templated_constructors_runme.py b/Examples/test-suite/python/template_templated_constructors_runme.py
new file mode 100644
index 000000000..c3fbda0cd
--- /dev/null
+++ b/Examples/test-suite/python/template_templated_constructors_runme.py
@@ -0,0 +1,20 @@
+from template_templated_constructors import *
+
+t1 = TConstructor1(123)
+t2a = TConstructor2()
+t2b = TConstructor2(123)
+
+tc1 = TClass1Int(123.4)
+tc2a = TClass2Int()
+tc2b = TClass2Int(123.4)
+
+double_pair = DoublePair(1.1, 2.2)
+short_pair = ShortPair(0, 1)
+string_pair = StringPair("10", "11")
+ip1 = IntPair()
+ip2 = IntPair(20, 21)
+ip3 = IntPair(ip1)
+ip4 = IntPair(short_pair)
+# These next two create an IntPair from factory function calls in Python, unlike Java which calls the IntPair constructor
+ip5 = Pair(double_pair)
+ip6 = MakeStringPair(string_pair)
diff --git a/Examples/test-suite/python/template_typedef_cplx2_runme.py b/Examples/test-suite/python/template_typedef_cplx2_runme.py
index 161bd51fc..23f19efb9 100644
--- a/Examples/test-suite/python/template_typedef_cplx2_runme.py
+++ b/Examples/test-suite/python/template_typedef_cplx2_runme.py
@@ -8,25 +8,21 @@ try:
d = make_Identity_double()
a = d.this
except:
- print d, "is not an instance"
- raise RuntimeError
+ raise RuntimeError("{} is not an instance".format(d))
s = "%s" % d
if str.find(s, "ArithUnaryFunction") == -1:
- print d, "is not an ArithUnaryFunction"
- raise RuntimeError
+ raise RuntimeError("{} is not an ArithUnaryFunction".format(d))
try:
e = make_Multiplies_double_double_double_double(d, d)
a = e.this
except:
- print e, "is not an instance"
- raise RuntimeError
+ raise RuntimeError("{} is not an instance".format(e))
s = "%s" % e
if str.find(s, "ArithUnaryFunction") == -1:
- print e, "is not an ArithUnaryFunction"
- raise RuntimeError
+ raise RuntimeError("{} is not an ArithUnaryFunction".format(e))
#
@@ -37,25 +33,21 @@ try:
c = make_Identity_complex()
a = c.this
except:
- print c, "is not an instance"
- raise RuntimeError
+ raise RuntimeError("{} is not an instance".format(c))
s = "%s" % c
if str.find(s, "ArithUnaryFunction") == -1:
- print c, "is not an ArithUnaryFunction"
- raise RuntimeError
+ raise RuntimeError("{} is not an ArithUnaryFunction".format(c))
try:
f = make_Multiplies_complex_complex_complex_complex(c, c)
a = f.this
except:
- print f, "is not an instance"
- raise RuntimeError
+ raise RuntimeError("{} is not an instance".format(f))
s = "%s" % f
if str.find(s, "ArithUnaryFunction") == -1:
- print f, "is not an ArithUnaryFunction"
- raise RuntimeError
+ raise RuntimeError("{} is not an ArithUnaryFunction".format(f))
#
# Mix case
@@ -65,29 +57,24 @@ try:
g = make_Multiplies_double_double_complex_complex(d, c)
a = g.this
except:
- print g, "is not an instance"
- raise RuntimeError
+ raise RuntimeError("{} is not an instance".format(g))
s = "%s" % g
if str.find(s, "ArithUnaryFunction") == -1:
- print g, "is not an ArithUnaryFunction"
- raise RuntimeError
+ raise RuntimeError("{} is not an ArithUnaryFunction".format(g))
try:
h = make_Multiplies_complex_complex_double_double(c, d)
a = h.this
except:
- print h, "is not an instance"
- raise RuntimeError
+ raise RuntimeError("{} is not an instance".format(h))
s = "%s" % h
if str.find(s, "ArithUnaryFunction") == -1:
- print h, "is not an ArithUnaryFunction"
- raise RuntimeError
+ raise RuntimeError("{} is not an ArithUnaryFunction".format(h))
try:
a = g.get_value()
except:
- print g, "has not get_value() method"
- raise RuntimeError
+ raise RuntimeError("{}, has not get_value() method".format(g))
diff --git a/Examples/test-suite/python/template_typedef_cplx_runme.py b/Examples/test-suite/python/template_typedef_cplx_runme.py
index 1846739eb..69d5642d6 100644
--- a/Examples/test-suite/python/template_typedef_cplx_runme.py
+++ b/Examples/test-suite/python/template_typedef_cplx_runme.py
@@ -8,25 +8,21 @@ try:
d = make_Identity_double()
a = d.this
except:
- print d, "is not an instance"
- raise RuntimeError
+ raise RuntimeError("{} is not an instance".format(d))
s = "%s" % d
if str.find(s, "ArithUnaryFunction") == -1:
- print d, "is not an ArithUnaryFunction"
- raise RuntimeError
+ raise RuntimeError("{} is not an ArithUnaryFunction".format(d))
try:
e = make_Multiplies_double_double_double_double(d, d)
a = e.this
except:
- print e, "is not an instance"
- raise RuntimeError
+ raise RuntimeError("{} is not an instance".format(e))
s = "%s" % e
if str.find(s, "ArithUnaryFunction") == -1:
- print e, "is not an ArithUnaryFunction"
- raise RuntimeError
+ raise RuntimeError("{} is not an ArithUnaryFunction".format(e))
#
@@ -37,25 +33,21 @@ try:
c = make_Identity_complex()
a = c.this
except:
- print c, "is not an instance"
- raise RuntimeError
+ raise RuntimeError("{} is not an instance".format(c))
s = "%s" % c
if str.find(s, "ArithUnaryFunction") == -1:
- print c, "is not an ArithUnaryFunction"
- raise RuntimeError
+ raise RuntimeError("{} is not an ArithUnaryFunction".format(c))
try:
f = make_Multiplies_complex_complex_complex_complex(c, c)
a = f.this
except:
- print f, "is not an instance"
- raise RuntimeError
+ raise RuntimeError("{} is not an instance".format(f))
s = "%s" % f
if str.find(s, "ArithUnaryFunction") == -1:
- print f, "is not an ArithUnaryFunction"
- raise RuntimeError
+ raise RuntimeError("{} is not an ArithUnaryFunction".format(f))
#
# Mix case
@@ -65,23 +57,19 @@ try:
g = make_Multiplies_double_double_complex_complex(d, c)
a = g.this
except:
- print g, "is not an instance"
- raise RuntimeError
+ raise RuntimeError("{} is not an instance".format(g))
s = "%s" % g
if str.find(s, "ArithUnaryFunction") == -1:
- print g, "is not an ArithUnaryFunction"
- raise RuntimeError
+ raise RuntimeError("{} is not an ArithUnaryFunction".format(g))
try:
h = make_Multiplies_complex_complex_double_double(c, d)
a = h.this
except:
- print h, "is not an instance"
- raise RuntimeError
+ raise RuntimeError("{} is not an instance".format(h))
s = "%s" % h
if str.find(s, "ArithUnaryFunction") == -1:
- print h, "is not an ArithUnaryFunction"
- raise RuntimeError
+ raise RuntimeError("{} is not an ArithUnaryFunction".format(h))
diff --git a/Examples/test-suite/python/template_typedef_runme.py b/Examples/test-suite/python/template_typedef_runme.py
index 16695bada..5723e4f59 100644
--- a/Examples/test-suite/python/template_typedef_runme.py
+++ b/Examples/test-suite/python/template_typedef_runme.py
@@ -14,22 +14,19 @@ try:
e = make_Multiplies_float_float_float_float(d, d)
a = e.this
except:
- print e, "is not an instance"
- raise RuntimeError
+ raise RuntimeError("{} is not an instance".format(e))
try:
f = make_Multiplies_reald_reald_reald_reald(c, c)
a = f.this
except:
- print f, "is not an instance"
- raise RuntimeError
+ raise RuntimeError("{} is not an instance".format(f))
try:
g = make_Multiplies_float_float_reald_reald(d, c)
a = g.this
except:
- print g, "is not an instance"
- raise RuntimeError
+ raise RuntimeError("{} is not an instance".format(g))
# the old large format
diff --git a/Examples/test-suite/python/template_typemaps_typedef2_runme.py b/Examples/test-suite/python/template_typemaps_typedef2_runme.py
index 258f44366..da26a9f76 100644
--- a/Examples/test-suite/python/template_typemaps_typedef2_runme.py
+++ b/Examples/test-suite/python/template_typemaps_typedef2_runme.py
@@ -5,7 +5,7 @@ m1 = MultimapIntA()
dummy_pair = m1.make_dummy_pair()
val = m1.typemap_test(dummy_pair).val
if val != 1234:
- raise RuntimeError, "typemaps not working"
+ raise RuntimeError("typemaps not working")
m2 = MultimapAInt()
@@ -13,24 +13,24 @@ m2 = MultimapAInt()
#dummy_pair = m2.make_dummy_pair()
#val = m2.typemap_test(dummy_pair)
-# print val
+# print("{}".format(val))
# if val != 4321:
# raise RuntimeError, "typemaps not working"
if typedef_test1(dummy_pair).val != 1234:
- raise RuntimeError, "typedef_test1 not working"
+ raise RuntimeError("typedef_test1 not working")
if typedef_test2(dummy_pair).val != 1234:
- raise RuntimeError, "typedef_test2 not working"
+ raise RuntimeError("typedef_test2 not working")
if typedef_test3(dummy_pair).val != 1234:
- raise RuntimeError, "typedef_test3 not working"
+ raise RuntimeError("typedef_test3 not working")
if typedef_test4(dummy_pair).val != 1234:
- raise RuntimeError, "typedef_test4 not working"
+ raise RuntimeError("typedef_test4 not working")
if typedef_test5(dummy_pair).val != 1234:
- raise RuntimeError, "typedef_test5 not working"
+ raise RuntimeError("typedef_test5 not working")
if typedef_test6(dummy_pair).val != 1234:
- raise RuntimeError, "typedef_test6 not working"
+ raise RuntimeError("typedef_test6 not working")
diff --git a/Examples/test-suite/python/template_typemaps_typedef_runme.py b/Examples/test-suite/python/template_typemaps_typedef_runme.py
index 1ca3f835c..a5209b71f 100644
--- a/Examples/test-suite/python/template_typemaps_typedef_runme.py
+++ b/Examples/test-suite/python/template_typemaps_typedef_runme.py
@@ -5,7 +5,7 @@ m1 = MultimapIntA()
dummy_pair = m1.make_dummy_pair()
val = m1.typemap_test(dummy_pair).val
if val != 1234:
- raise RuntimeError, "typemaps not working"
+ raise RuntimeError("typemaps not working")
m2 = MultimapAInt()
@@ -13,24 +13,24 @@ m2 = MultimapAInt()
#dummy_pair = m2.make_dummy_pair()
#val = m2.typemap_test(dummy_pair)
-# print val
+# print("{}".format(val))
# if val != 4321:
# raise RuntimeError, "typemaps not working"
if typedef_test1(dummy_pair).val != 1234:
- raise RuntimeError, "typedef_test1 not working"
+ raise RuntimeError("typedef_test1 not working")
if typedef_test2(dummy_pair).val != 1234:
- raise RuntimeError, "typedef_test2 not working"
+ raise RuntimeError("typedef_test2 not working")
if typedef_test3(dummy_pair).val != 1234:
- raise RuntimeError, "typedef_test3 not working"
+ raise RuntimeError("typedef_test3 not working")
if typedef_test4(dummy_pair).val != 1234:
- raise RuntimeError, "typedef_test4 not working"
+ raise RuntimeError("typedef_test4 not working")
if typedef_test5(dummy_pair).val != 1234:
- raise RuntimeError, "typedef_test5 not working"
+ raise RuntimeError("typedef_test5 not working")
if typedef_test6(dummy_pair).val != 1234:
- raise RuntimeError, "typedef_test6 not working"
+ raise RuntimeError("typedef_test6 not working")
diff --git a/Examples/test-suite/python/template_using_member_default_arg_runme.py b/Examples/test-suite/python/template_using_member_default_arg_runme.py
new file mode 100644
index 000000000..432306a8a
--- /dev/null
+++ b/Examples/test-suite/python/template_using_member_default_arg_runme.py
@@ -0,0 +1,6 @@
+from template_using_member_default_arg import *
+
+a = ThingADerivedInt()
+a.describeA()
+b = ThingBDerivedInt()
+b.describeB()
diff --git a/Examples/test-suite/python/threads_exception_runme.py b/Examples/test-suite/python/threads_exception_runme.py
index 056bd849b..e3f6299e7 100644
--- a/Examples/test-suite/python/threads_exception_runme.py
+++ b/Examples/test-suite/python/threads_exception_runme.py
@@ -3,18 +3,18 @@ import threads_exception
t = threads_exception.Test()
try:
t.unknown()
-except RuntimeError, e:
+except RuntimeError as e:
pass
try:
t.simple()
-except RuntimeError, e:
+except RuntimeError as e:
if e.args[0] != 37:
raise RuntimeError
try:
t.message()
-except RuntimeError, e:
+except RuntimeError as e:
if e.args[0] != "I died.":
raise RuntimeError
@@ -23,18 +23,18 @@ except RuntimeError, e:
if not threads_exception.is_python_builtin():
try:
t.hosed()
- except threads_exception.Exc, e:
+ except threads_exception.Exc as e:
code = e.code
if code != 42:
- raise RuntimeError, "bad... code: %d" % code
+ raise RuntimeError("bad... code: %d" % code)
msg = e.msg
if msg != "Hosed":
- raise RuntimeError, "bad... msg: '%s' len: %d" % (msg, len(msg))
+ raise RuntimeError("bad... msg: '%s' len: %d" % (msg, len(msg)))
for i in range(1, 4):
try:
t.multi(i)
- except RuntimeError, e:
+ except RuntimeError as e:
pass
- except threads_exception.Exc, e:
+ except threads_exception.Exc as e:
pass
diff --git a/Examples/test-suite/python/typedef_inherit_runme.py b/Examples/test-suite/python/typedef_inherit_runme.py
index 6b7f2d872..020e4cc5e 100644
--- a/Examples/test-suite/python/typedef_inherit_runme.py
+++ b/Examples/test-suite/python/typedef_inherit_runme.py
@@ -5,19 +5,23 @@ b = typedef_inherit.Bar()
x = typedef_inherit.do_blah(a)
if x != "Foo::blah":
- print "Whoa! Bad return", x
+ raise RuntimeError("Whoa! Bad return {}".format(x))
x = typedef_inherit.do_blah(b)
if x != "Bar::blah":
- print "Whoa! Bad return", x
+ raise RuntimeError("Whoa! Bad return {}".format(x))
c = typedef_inherit.Spam()
d = typedef_inherit.Grok()
x = typedef_inherit.do_blah2(c)
if x != "Spam::blah":
- print "Whoa! Bad return", x
+ raise RuntimeError("Whoa! Bad return {}".format(x))
x = typedef_inherit.do_blah2(d)
if x != "Grok::blah":
- print "Whoa! Bad return", x
+ raise RuntimeError("Whoa! Bad return {}".format(x))
+
+x = d.far()
+if x != "Spam::far":
+ raise RuntimeError("Whoa! Bad return {}".format(x))
diff --git a/Examples/test-suite/python/typedef_scope_runme.py b/Examples/test-suite/python/typedef_scope_runme.py
index edd3e9f3a..0294c4a07 100644
--- a/Examples/test-suite/python/typedef_scope_runme.py
+++ b/Examples/test-suite/python/typedef_scope_runme.py
@@ -3,8 +3,8 @@ import typedef_scope
b = typedef_scope.Bar()
x = b.test1(42, "hello")
if x != 42:
- print "Failed!!"
+ raise RuntimeError("Failed!!")
x = b.test2(42, "hello")
if x != "hello":
- print "Failed!!"
+ raise RuntimeError("Failed!!")
diff --git a/Examples/test-suite/python/typemap_arrays_runme.py b/Examples/test-suite/python/typemap_arrays_runme.py
index ea0f08d6b..7bc45f908 100644
--- a/Examples/test-suite/python/typemap_arrays_runme.py
+++ b/Examples/test-suite/python/typemap_arrays_runme.py
@@ -1,4 +1,4 @@
from typemap_arrays import *
if sumA(None) != 60:
- raise RuntimeError, "Sum is wrong"
+ raise RuntimeError("Sum is wrong")
diff --git a/Examples/test-suite/python/typemap_out_optimal_runme.py b/Examples/test-suite/python/typemap_out_optimal_runme.py
index c7a34308e..6f6cc5490 100644
--- a/Examples/test-suite/python/typemap_out_optimal_runme.py
+++ b/Examples/test-suite/python/typemap_out_optimal_runme.py
@@ -1,4 +1,7 @@
from typemap_out_optimal import *
-cvar.XX_debug = False
-x = XX_create()
+cvar.XX_trace = False
+x = XX.create()
+del x
+x = XX.createConst()
+del x
diff --git a/Examples/test-suite/python/typename_runme.py b/Examples/test-suite/python/typename_runme.py
index aac936fde..a4f76fc36 100644
--- a/Examples/test-suite/python/typename_runme.py
+++ b/Examples/test-suite/python/typename_runme.py
@@ -4,8 +4,8 @@ f = typename.Foo()
b = typename.Bar()
x = typename.twoFoo(f)
-if not isinstance(x, types.FloatType):
- raise RuntimeError, "Wrong return type (FloatType) !"
+if not isinstance(x, float):
+ raise RuntimeError("Wrong return type (FloatType) !")
y = typename.twoBar(b)
-if not isinstance(y, types.IntType):
- raise RuntimeError, "Wrong return type (IntType)!"
+if not isinstance(y, int):
+ raise RuntimeError("Wrong return type (IntType)!")
diff --git a/Examples/test-suite/python/unicode_strings_runme.py b/Examples/test-suite/python/unicode_strings_runme.py
index 4e661f00e..57bd7abca 100644
--- a/Examples/test-suite/python/unicode_strings_runme.py
+++ b/Examples/test-suite/python/unicode_strings_runme.py
@@ -2,12 +2,8 @@ import sys
import unicode_strings
-# The 'u' string prefix isn't valid in Python 3.0 - 3.2 and is redundant
-# in 3.3+. Since this file is run through 2to3 before testing, though,
-# mark this as a unicode string in 2.x so it'll become a str in 3.x.
-test_string = u"h\udce9llo w\u00f6rld"
-
if sys.version_info[0:2] >= (3, 1):
+ test_string = "h\udce9llo w\u00f6rld"
if unicode_strings.non_utf8_c_str() != test_string:
raise ValueError("Test comparison mismatch")
if unicode_strings.non_utf8_std_string() != test_string:
@@ -19,19 +15,24 @@ def check(s1, s2):
# Testing SWIG_PYTHON_2_UNICODE flag which allows unicode strings to be passed to C
if sys.version_info[0:2] < (3, 0):
+ # Python 3.0-3.2 results in a SyntaxError when using u"" string literals, so we use a
+ # convoluted unicode string construction using unicode() and unichr().
+ # Conventional Python 2 syntax shown in comments.
check(unicode_strings.charstring("hello1"), "hello1")
- check(unicode_strings.charstring(str(u"hello2")), "hello2")
- check(unicode_strings.charstring(u"hello3"), "hello3")
- check(unicode_strings.charstring(unicode("hello4")), "hello4")
- unicode_strings.charstring(u"hell\xb05")
- unicode_strings.charstring(u"hell\u00f66")
-
-low_surrogate_string = u"\udcff"
-try:
+ check(unicode_strings.charstring(str(unicode("hello2"))), "hello2") # u"hello2"
+ check(unicode_strings.charstring(unicode("hello3")), "hello3") # u"hello3"
+ check(unicode_strings.charstring(str("hello4")), "hello4")
+ unicode_strings.charstring(unicode("hell" + unichr(0xb0) + "5")) # u"hell\xb05"
+ unicode_strings.charstring(unicode("hell" + unichr(0x00f6) +"6")) # u"hell\u00f66"
+ low_surrogate_string = unichr(0xdcff) # u"\udcff"
unicode_strings.instring(low_surrogate_string)
- # Will succeed with Python 2
-except TypeError, e:
- # Python 3 will fail the PyUnicode_AsUTF8String conversion resulting in a TypeError.
- # The real error is actually:
- # UnicodeEncodeError: 'utf-8' codec can't encode character '\udcff' in position 0: surrogates not allowed
- pass
+else:
+ low_surrogate_string = "\udcff"
+ try:
+ unicode_strings.instring(low_surrogate_string)
+ raise RuntimeError("Exception should have been thrown")
+ except TypeError as e:
+ # Python 3 will fail the PyUnicode_AsUTF8String conversion resulting in a TypeError.
+ # The real error is actually:
+ # UnicodeEncodeError: 'utf-8' codec can't encode character '\udcff' in position 0: surrogates not allowed
+ pass
diff --git a/Examples/test-suite/python/unions_runme.py b/Examples/test-suite/python/unions_runme.py
index 387a048c8..5a3ee3b5c 100644
--- a/Examples/test-suite/python/unions_runme.py
+++ b/Examples/test-suite/python/unions_runme.py
@@ -3,7 +3,6 @@
# union embedded within a struct can be set and read correctly.
import unions
-import sys
import string
# Create new instances of SmallStruct and BigStruct for later use
@@ -23,28 +22,23 @@ eut.number = 1
eut.uni.small = small
Jill1 = eut.uni.small.jill
if (Jill1 != 200):
- print "Runtime test1 failed. eut.uni.small.jill=", Jill1
- sys.exit(1)
+ raise RuntimeError("Runtime test1 failed. eut.uni.small.jill={}".format(Jill1))
Num1 = eut.number
if (Num1 != 1):
- print "Runtime test2 failed. eut.number=", Num1
- sys.exit(1)
+ raise RuntimeError("Runtime test2 failed. eut.number=".format(Num1))
# Secondly check the BigStruct in EmbeddedUnionTest
eut.number = 2
eut.uni.big = big
Jack1 = eut.uni.big.jack
if (Jack1 != 300):
- print "Runtime test3 failed. eut.uni.big.jack=", Jack1
- sys.exit(1)
+ raise RuntimeError("Runtime test3 failed. eut.uni.big.jack={}".format(Jack1))
Jill2 = eut.uni.big.smallstruct.jill
if (Jill2 != 200):
- print "Runtime test4 failed. eut.uni.big.smallstruct.jill=", Jill2
- sys.exit(1)
+ raise RuntimeError("Runtime test4 failed. eut.uni.big.smallstruct.jill={}".format(Jill2))
Num2 = eut.number
if (Num2 != 2):
- print "Runtime test5 failed. eut.number=", Num2
- sys.exit(1)
+ raise RuntimeError("Runtime test5 failed. eut.number={}".format(Num2))
diff --git a/Examples/test-suite/python/using_composition_runme.py b/Examples/test-suite/python/using_composition_runme.py
index c4f339095..67f72bc2f 100644
--- a/Examples/test-suite/python/using_composition_runme.py
+++ b/Examples/test-suite/python/using_composition_runme.py
@@ -2,32 +2,32 @@ from using_composition import *
f = FooBar()
if f.blah(3) != 3:
- raise RuntimeError, "FooBar::blah(int)"
+ raise RuntimeError("FooBar::blah(int)")
if f.blah(3.5) != 3.5:
- raise RuntimeError, "FooBar::blah(double)"
+ raise RuntimeError("FooBar::blah(double)")
if f.blah("hello") != "hello":
- raise RuntimeError, "FooBar::blah(char *)"
+ raise RuntimeError("FooBar::blah(char *)")
f = FooBar2()
if f.blah(3) != 3:
- raise RuntimeError, "FooBar2::blah(int)"
+ raise RuntimeError("FooBar2::blah(int)")
if f.blah(3.5) != 3.5:
- raise RuntimeError, "FooBar2::blah(double)"
+ raise RuntimeError("FooBar2::blah(double)")
if f.blah("hello") != "hello":
- raise RuntimeError, "FooBar2::blah(char *)"
+ raise RuntimeError("FooBar2::blah(char *)")
f = FooBar3()
if f.blah(3) != 3:
- raise RuntimeError, "FooBar3::blah(int)"
+ raise RuntimeError("FooBar3::blah(int)")
if f.blah(3.5) != 3.5:
- raise RuntimeError, "FooBar3::blah(double)"
+ raise RuntimeError("FooBar3::blah(double)")
if f.blah("hello") != "hello":
- raise RuntimeError, "FooBar3::blah(char *)"
+ raise RuntimeError("FooBar3::blah(char *)")
diff --git a/Examples/test-suite/python/using_extend_runme.py b/Examples/test-suite/python/using_extend_runme.py
index 038a1686a..7e0912926 100644
--- a/Examples/test-suite/python/using_extend_runme.py
+++ b/Examples/test-suite/python/using_extend_runme.py
@@ -2,20 +2,20 @@ from using_extend import *
f = FooBar()
if f.blah(3) != 3:
- raise RuntimeError, "blah(int)"
+ raise RuntimeError("blah(int)")
if f.blah(3.5) != 3.5:
- raise RuntimeError, "blah(double)"
+ raise RuntimeError("blah(double)")
if f.blah("hello") != "hello":
- raise RuntimeError, "blah(char *)"
+ raise RuntimeError("blah(char *)")
if f.blah(3, 4) != 7:
- raise RuntimeError, "blah(int,int)"
+ raise RuntimeError("blah(int,int)")
if f.blah(3.5, 7.5) != (3.5 + 7.5):
- raise RuntimeError, "blah(double,double)"
+ raise RuntimeError("blah(double,double)")
if f.duh(3) != 3:
- raise RuntimeError, "duh(int)"
+ raise RuntimeError("duh(int)")
diff --git a/Examples/test-suite/python/using_inherit_runme.py b/Examples/test-suite/python/using_inherit_runme.py
index 4fd595968..ccdeece8d 100644
--- a/Examples/test-suite/python/using_inherit_runme.py
+++ b/Examples/test-suite/python/using_inherit_runme.py
@@ -2,47 +2,47 @@ from using_inherit import *
b = Bar()
if b.test(3) != 3:
- raise RuntimeError, "Bar::test(int)"
+ raise RuntimeError("Bar::test(int)")
if b.test(3.5) != 3.5:
- raise RuntimeError, "Bar::test(double)"
+ raise RuntimeError("Bar::test(double)")
b = Bar2()
if b.test(3) != 6:
- raise RuntimeError, "Bar2::test(int)"
+ raise RuntimeError("Bar2::test(int)")
if b.test(3.5) != 7.0:
- raise RuntimeError, "Bar2::test(double)"
+ raise RuntimeError("Bar2::test(double)")
b = Bar3()
if b.test(3) != 6:
- raise RuntimeError, "Bar3::test(int)"
+ raise RuntimeError("Bar3::test(int)")
if b.test(3.5) != 7.0:
- raise RuntimeError, "Bar3::test(double)"
+ raise RuntimeError("Bar3::test(double)")
b = Bar4()
if b.test(3) != 6:
- raise RuntimeError, "Bar4::test(int)"
+ raise RuntimeError("Bar4::test(int)")
if b.test(3.5) != 7.0:
- raise RuntimeError, "Bar4::test(double)"
+ raise RuntimeError("Bar4::test(double)")
b = Fred1()
if b.test(3) != 3:
- raise RuntimeError, "Fred1::test(int)"
+ raise RuntimeError("Fred1::test(int)")
if b.test(3.5) != 7.0:
- raise RuntimeError, "Fred1::test(double)"
+ raise RuntimeError("Fred1::test(double)")
b = Fred2()
if b.test(3) != 3:
- raise RuntimeError, "Fred2::test(int)"
+ raise RuntimeError("Fred2::test(int)")
if b.test(3.5) != 7.0:
- raise RuntimeError, "Fred2::test(double)"
+ raise RuntimeError("Fred2::test(double)")
diff --git a/Examples/test-suite/python/using_member_multiple_inherit_runme.py b/Examples/test-suite/python/using_member_multiple_inherit_runme.py
new file mode 100644
index 000000000..c7d81097d
--- /dev/null
+++ b/Examples/test-suite/python/using_member_multiple_inherit_runme.py
@@ -0,0 +1,32 @@
+from using_member_multiple_inherit import *
+
+# Single inheritance three deep, only using declarations
+s3 = Susing3()
+s3.usingmethod(11)
+
+# Single inheritance three deep, overload using and methods
+u3 = Using3()
+u3.usingmethod(11)
+u3.usingmethod(11, 22)
+u3.usingmethod(11, 22, 33)
+
+m3 = Musing3()
+m3.usingmethod(11)
+m3.usingmethod(11, 22)
+m3.usingmethod(11, 22, 33)
+
+d3 = Dusing3()
+d3.usingmethod(11)
+d3.usingmethod(11, 22)
+
+# Multiple inheritance, multiple using declarations
+ma = MultMiddleA()
+ma.multmethod(123)
+ma.multmethod("hi")
+ma.multmethod(123, 234)
+
+mb = MultBottomB()
+mb.multmethod(123)
+mb.multmethod("hi")
+mb.multmethod(123, 234)
+mb.multmethod(123, 345, 567)
diff --git a/Examples/test-suite/python/using_member_runme.py b/Examples/test-suite/python/using_member_runme.py
new file mode 100644
index 000000000..a0ea64888
--- /dev/null
+++ b/Examples/test-suite/python/using_member_runme.py
@@ -0,0 +1,24 @@
+from using_member import *
+
+def swig_assert_equal(a, b):
+ if a != b:
+ raise RuntimeError(str(a) + " != " + str(b))
+
+b = B()
+swig_assert_equal(b.get(int(1)), 10)
+swig_assert_equal(b.get(float(1)), 20)
+
+bb = BB()
+swig_assert_equal(bb.greater(int(1)), 0)
+swig_assert_equal(bb.greater(float(1)), 1)
+swig_assert_equal(bb.great(True), 2)
+
+cc = CC()
+swig_assert_equal(cc.greater(int(10)), 0)
+swig_assert_equal(cc.greater(float(10)), 1)
+swig_assert_equal(cc.greater(True), 20)
+
+dd = DD()
+swig_assert_equal(dd.greater(int(10)), 0)
+swig_assert_equal(dd.greater(float(10)), 1)
+swig_assert_equal(dd.greaterstill(True), 30)
diff --git a/Examples/test-suite/python/using_private_runme.py b/Examples/test-suite/python/using_private_runme.py
index 00c9a8d25..9e0a15f12 100644
--- a/Examples/test-suite/python/using_private_runme.py
+++ b/Examples/test-suite/python/using_private_runme.py
@@ -4,10 +4,10 @@ f = FooBar()
f.x = 3
if f.blah(4) != 4:
- raise RuntimeError, "blah(int)"
+ raise RuntimeError("blah(int)")
if f.defaulted() != -1:
- raise RuntimeError, "defaulted()"
+ raise RuntimeError("defaulted()")
if f.defaulted(222) != 222:
- raise RuntimeError, "defaulted(222)"
+ raise RuntimeError("defaulted(222)")
diff --git a/Examples/test-suite/python/using_protected_runme.py b/Examples/test-suite/python/using_protected_runme.py
index 525a1cde4..dd477237e 100644
--- a/Examples/test-suite/python/using_protected_runme.py
+++ b/Examples/test-suite/python/using_protected_runme.py
@@ -4,4 +4,4 @@ f = FooBar()
f.x = 3
if f.blah(4) != 4:
- raise RuntimeError, "blah(int)"
+ raise RuntimeError("blah(int)")
diff --git a/Examples/test-suite/python/varargs_overload_runme.py b/Examples/test-suite/python/varargs_overload_runme.py
index 6f5a70222..ffa763450 100644
--- a/Examples/test-suite/python/varargs_overload_runme.py
+++ b/Examples/test-suite/python/varargs_overload_runme.py
@@ -1,62 +1,62 @@
import varargs_overload
if varargs_overload.vararg_over1("Hello") != "Hello":
- raise RuntimeError, "Failed"
+ raise RuntimeError("Failed")
if varargs_overload.vararg_over1(2) != "2":
- raise RuntimeError, "Failed"
+ raise RuntimeError("Failed")
if varargs_overload.vararg_over2("Hello") != "Hello":
- raise RuntimeError, "Failed"
+ raise RuntimeError("Failed")
if varargs_overload.vararg_over2(2, 2.2) != "2 2.2":
- raise RuntimeError, "Failed"
+ raise RuntimeError("Failed")
if varargs_overload.vararg_over3("Hello") != "Hello":
- raise RuntimeError, "Failed"
+ raise RuntimeError("Failed")
if varargs_overload.vararg_over3(2, 2.2, "hey") != "2 2.2 hey":
- raise RuntimeError, "Failed"
+ raise RuntimeError("Failed")
if varargs_overload.vararg_over4("Hello") != "Hello":
- raise RuntimeError, "Failed"
+ raise RuntimeError("Failed")
if varargs_overload.vararg_over4(123) != "123":
- raise RuntimeError, "Failed"
+ raise RuntimeError("Failed")
if varargs_overload.vararg_over4("Hello", 123) != "Hello":
- raise RuntimeError, "Failed"
+ raise RuntimeError("Failed")
# Same as above but non-vararg function declared first
if varargs_overload.vararg_over6("Hello") != "Hello":
- raise RuntimeError, "Failed"
+ raise RuntimeError("Failed")
if varargs_overload.vararg_over6(2) != "2":
- raise RuntimeError, "Failed"
+ raise RuntimeError("Failed")
if varargs_overload.vararg_over7("Hello") != "Hello":
- raise RuntimeError, "Failed"
+ raise RuntimeError("Failed")
if varargs_overload.vararg_over7(2, 2.2) != "2 2.2":
- raise RuntimeError, "Failed"
+ raise RuntimeError("Failed")
if varargs_overload.vararg_over8("Hello") != "Hello":
- raise RuntimeError, "Failed"
+ raise RuntimeError("Failed")
if varargs_overload.vararg_over8(2, 2.2, "hey") != "2 2.2 hey":
- raise RuntimeError, "Failed"
+ raise RuntimeError("Failed")
if varargs_overload.vararg_over9("Hello") != "Hello":
- raise RuntimeError, "Failed"
+ raise RuntimeError("Failed")
if varargs_overload.vararg_over9(123) != "123":
- raise RuntimeError, "Failed"
+ raise RuntimeError("Failed")
if varargs_overload.vararg_over9("Hello", 123) != "Hello":
- raise RuntimeError, "Failed"
+ raise RuntimeError("Failed")
diff --git a/Examples/test-suite/python/varargs_runme.py b/Examples/test-suite/python/varargs_runme.py
index 277ea757a..13f85a75f 100644
--- a/Examples/test-suite/python/varargs_runme.py
+++ b/Examples/test-suite/python/varargs_runme.py
@@ -1,31 +1,35 @@
import varargs
if varargs.test("Hello") != "Hello":
- raise RuntimeError, "Failed"
+ raise RuntimeError("Failed")
+
+vc = varargs.VarargConstructor("Hey there")
+if vc.str != "Hey there":
+ raise RuntimeError("Failed")
f = varargs.Foo("Greetings")
if f.str != "Greetings":
- raise RuntimeError, "Failed"
+ raise RuntimeError("Failed")
if f.test("Hello") != "Hello":
- raise RuntimeError, "Failed"
+ raise RuntimeError("Failed")
if varargs.test_def("Hello", 1) != "Hello":
- raise RuntimeError, "Failed"
+ raise RuntimeError("Failed")
if varargs.test_def("Hello") != "Hello":
- raise RuntimeError, "Failed"
+ raise RuntimeError("Failed")
###
if varargs.test_plenty("Hello") != "Hello":
- raise RuntimeError, "Failed"
+ raise RuntimeError("Failed")
if varargs.test_plenty("Hello", 1) != "Hello":
- raise RuntimeError, "Failed"
+ raise RuntimeError("Failed")
if varargs.test_plenty("Hello", 1, 2) != "Hello":
- raise RuntimeError, "Failed"
+ raise RuntimeError("Failed")
try:
varargs.test_plenty("Hello", 1, 2, 3)
diff --git a/Examples/test-suite/python/virtual_derivation_runme.py b/Examples/test-suite/python/virtual_derivation_runme.py
index 68546c6eb..21014bd02 100644
--- a/Examples/test-suite/python/virtual_derivation_runme.py
+++ b/Examples/test-suite/python/virtual_derivation_runme.py
@@ -4,4 +4,4 @@ from virtual_derivation import *
#
b = B(3)
if b.get_a() != b.get_b():
- raise RuntimeError, "something is really wrong"
+ raise RuntimeError("something is really wrong")
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():