Merge branch 'master' into doxygen
The way Python docstrings are indented has changed on master, so use the standard inspect module in Python autodoc unit test to ignore the differences in their indentation level between -builtin and non-builtin cases to make the test still pass with the branch version, which avoids the use of different (but almost identical) values in the test itself.
This commit is contained in:
commit
e668c47b70
1094 changed files with 39390 additions and 11483 deletions
|
|
@ -11,7 +11,7 @@ endif
|
|||
LANGUAGE = python
|
||||
PYTHON = $(PYBIN)
|
||||
PEP8 = @PEP8@
|
||||
PEP8_FLAGS = --ignore=E402,E501,E30,W291,W391
|
||||
PEP8_FLAGS = --ignore=E30,E402,E501,E731,W291,W391
|
||||
|
||||
#*_runme.py for Python 2.x, *_runme3.py for Python 3.x
|
||||
PY2SCRIPTSUFFIX = _runme.py
|
||||
|
|
@ -58,11 +58,18 @@ CPP_TEST_CASES += \
|
|||
primitive_types \
|
||||
python_abstractbase \
|
||||
python_append \
|
||||
python_builtin \
|
||||
python_destructor_exception \
|
||||
python_director \
|
||||
python_docstring \
|
||||
python_extranative \
|
||||
python_moduleimport \
|
||||
python_nondynamic \
|
||||
python_overload_simple_cast \
|
||||
python_pickle \
|
||||
python_pythoncode \
|
||||
python_richcompare \
|
||||
python_strict_unicode \
|
||||
simutry \
|
||||
std_containers \
|
||||
swigobject \
|
||||
|
|
@ -127,11 +134,11 @@ py2_runme = $(SCRIPTPREFIX)$*$(PY2SCRIPTSUFFIX)
|
|||
py3_runme = $(SCRIPTPREFIX)$*$(PY3SCRIPTSUFFIX)
|
||||
|
||||
ifneq (,$(PEP8))
|
||||
check_pep8 = $(PEP8) $(PEP8_FLAGS) $(SCRIPTPREFIX)$*.py
|
||||
check_pep8 = $(COMPILETOOL) $(PEP8) $(PEP8_FLAGS) $(SCRIPTPREFIX)$*.py
|
||||
|
||||
check_pep8_multi_cpp = \
|
||||
for f in `cat $(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/$*.list` ; do \
|
||||
$(PEP8) $(PEP8_FLAGS) $$f.py; \
|
||||
$(COMPILETOOL) $(PEP8) $(PEP8_FLAGS) $$f.py; \
|
||||
done
|
||||
endif
|
||||
|
||||
|
|
@ -166,7 +173,7 @@ endif
|
|||
@if test "x$(SCRIPTDIR)" != "x$(srcdir)"; then rm -f $(SCRIPTDIR)/$(py2_runme); fi
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR="$(SRCDIR)" python_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 imports_a.py imports_b.py mod_a.py mod_b.py multi_import_a.py
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
from autodoc import *
|
||||
import commentVerifier
|
||||
import inspect
|
||||
import sys
|
||||
|
||||
def check(got, expected, expected_builtin=None, skip=False):
|
||||
|
|
@ -12,174 +13,191 @@ def check(got, expected, expected_builtin=None, skip=False):
|
|||
def is_new_style_class(cls):
|
||||
return hasattr(cls, "__class__")
|
||||
|
||||
def is_fastproxy(module):
|
||||
return "new_instancemethod" in module
|
||||
|
||||
if not is_new_style_class(A):
|
||||
# Missing static methods make this hard to test... skip if -classic is
|
||||
# used!
|
||||
sys.exit(0)
|
||||
|
||||
if is_fastproxy(dir()):
|
||||
# Detect when -fastproxy is specified and skip test as it changes the function names making it
|
||||
# hard to test... skip until the number of options are reduced in SWIG-3.1 and autodoc is improved
|
||||
sys.exit(0)
|
||||
|
||||
# skip builtin check - the autodoc is missing, but it probably should not be
|
||||
skip = True
|
||||
|
||||
check(A.__doc__, "Proxy of C++ A class", "::A")
|
||||
check(A.funk.__doc__, "just a string")
|
||||
check(A.func0.__doc__, "func0(self, arg2, hello) -> int")
|
||||
check(A.func1.__doc__, "func1(A self, short arg2, Tuple hello) -> int")
|
||||
check(A.func2.__doc__,
|
||||
check(inspect.getdoc(A), "Proxy of C++ A class.", "::A")
|
||||
check(inspect.getdoc(A.funk), "just a string.")
|
||||
check(inspect.getdoc(A.func0),
|
||||
"func0(self, arg2, hello) -> int")
|
||||
check(inspect.getdoc(A.func1),
|
||||
"func1(A self, short arg2, Tuple hello) -> int")
|
||||
check(inspect.getdoc(A.func2),
|
||||
"func2(self, arg2, hello) -> int\n"
|
||||
"\n"
|
||||
"Parameters:\n"
|
||||
" arg2: short\n"
|
||||
" hello: int tuple[2]\n"
|
||||
)
|
||||
check(A.func3.__doc__,
|
||||
"Parameters\n"
|
||||
"----------\n"
|
||||
"arg2: short\n"
|
||||
"hello: int tuple[2]")
|
||||
check(inspect.getdoc(A.func3),
|
||||
"func3(A self, short arg2, Tuple hello) -> int\n"
|
||||
"\n"
|
||||
"Parameters:\n"
|
||||
" arg2: short\n"
|
||||
" hello: int tuple[2]\n"
|
||||
)
|
||||
"Parameters\n"
|
||||
"----------\n"
|
||||
"arg2: short\n"
|
||||
"hello: int tuple[2]")
|
||||
|
||||
check(A.func0default.__doc__,
|
||||
check(inspect.getdoc(A.func0default),
|
||||
"func0default(self, e, arg3, hello, f=2) -> int\n"
|
||||
"func0default(self, e, arg3, hello) -> int"
|
||||
)
|
||||
check(A.func1default.__doc__,
|
||||
"func0default(self, e, arg3, hello) -> int")
|
||||
check(inspect.getdoc(A.func1default),
|
||||
"func1default(A self, A e, short arg3, Tuple hello, double f=2) -> int\n"
|
||||
"func1default(A self, A e, short arg3, Tuple hello) -> int"
|
||||
)
|
||||
check(A.func2default.__doc__,
|
||||
"func1default(A self, A e, short arg3, Tuple hello) -> int")
|
||||
check(inspect.getdoc(A.func2default),
|
||||
"func2default(self, e, arg3, hello, f=2) -> int\n"
|
||||
"\n"
|
||||
"Parameters:\n"
|
||||
" e: A *\n"
|
||||
" arg3: short\n"
|
||||
" hello: int tuple[2]\n"
|
||||
" f: double\n"
|
||||
"Parameters\n"
|
||||
"----------\n"
|
||||
"e: A *\n"
|
||||
"arg3: short\n"
|
||||
"hello: int tuple[2]\n"
|
||||
"f: double\n"
|
||||
"\n"
|
||||
"func2default(self, e, arg3, hello) -> int\n"
|
||||
"\n"
|
||||
"Parameters:\n"
|
||||
" e: A *\n"
|
||||
" arg3: short\n"
|
||||
" hello: int tuple[2]\n"
|
||||
)
|
||||
check(A.func3default.__doc__,
|
||||
"Parameters\n"
|
||||
"----------\n"
|
||||
"e: A *\n"
|
||||
"arg3: short\n"
|
||||
"hello: int tuple[2]")
|
||||
check(inspect.getdoc(A.func3default),
|
||||
"func3default(A self, A e, short arg3, Tuple hello, double f=2) -> int\n"
|
||||
"\n"
|
||||
"Parameters:\n"
|
||||
" e: A *\n"
|
||||
" arg3: short\n"
|
||||
" hello: int tuple[2]\n"
|
||||
" f: double\n"
|
||||
"Parameters\n"
|
||||
"----------\n"
|
||||
"e: A *\n"
|
||||
"arg3: short\n"
|
||||
"hello: int tuple[2]\n"
|
||||
"f: double\n"
|
||||
"\n"
|
||||
"func3default(A self, A e, short arg3, Tuple hello) -> int\n"
|
||||
"\n"
|
||||
"Parameters:\n"
|
||||
" e: A *\n"
|
||||
" arg3: short\n"
|
||||
" hello: int tuple[2]\n"
|
||||
)
|
||||
"Parameters\n"
|
||||
"----------\n"
|
||||
"e: A *\n"
|
||||
"arg3: short\n"
|
||||
"hello: int tuple[2]")
|
||||
|
||||
check(A.func0static.__doc__,
|
||||
check(inspect.getdoc(A.func0static),
|
||||
"func0static(e, arg2, hello, f=2) -> int\n"
|
||||
"func0static(e, arg2, hello) -> int"
|
||||
)
|
||||
check(A.func1static.__doc__,
|
||||
"func0static(e, arg2, hello) -> int")
|
||||
check(inspect.getdoc(A.func1static),
|
||||
"func1static(A e, short arg2, Tuple hello, double f=2) -> int\n"
|
||||
"func1static(A e, short arg2, Tuple hello) -> int"
|
||||
)
|
||||
check(A.func2static.__doc__,
|
||||
"func1static(A e, short arg2, Tuple hello) -> int")
|
||||
check(inspect.getdoc(A.func2static),
|
||||
"func2static(e, arg2, hello, f=2) -> int\n"
|
||||
"\n"
|
||||
"Parameters:\n"
|
||||
" e: A *\n"
|
||||
" arg2: short\n"
|
||||
" hello: int tuple[2]\n"
|
||||
" f: double\n"
|
||||
"Parameters\n"
|
||||
"----------\n"
|
||||
"e: A *\n"
|
||||
"arg2: short\n"
|
||||
"hello: int tuple[2]\n"
|
||||
"f: double\n"
|
||||
"\n"
|
||||
"func2static(e, arg2, hello) -> int\n"
|
||||
"\n"
|
||||
"Parameters:\n"
|
||||
" e: A *\n"
|
||||
" arg2: short\n"
|
||||
" hello: int tuple[2]\n"
|
||||
)
|
||||
check(A.func3static.__doc__,
|
||||
"Parameters\n"
|
||||
"----------\n"
|
||||
"e: A *\n"
|
||||
"arg2: short\n"
|
||||
"hello: int tuple[2]")
|
||||
check(inspect.getdoc(A.func3static),
|
||||
"func3static(A e, short arg2, Tuple hello, double f=2) -> int\n"
|
||||
"\n"
|
||||
"Parameters:\n"
|
||||
" e: A *\n"
|
||||
" arg2: short\n"
|
||||
" hello: int tuple[2]\n"
|
||||
" f: double\n"
|
||||
"Parameters\n"
|
||||
"----------\n"
|
||||
"e: A *\n"
|
||||
"arg2: short\n"
|
||||
"hello: int tuple[2]\n"
|
||||
"f: double\n"
|
||||
"\n"
|
||||
"func3static(A e, short arg2, Tuple hello) -> int\n"
|
||||
"\n"
|
||||
"Parameters:\n"
|
||||
" e: A *\n"
|
||||
" arg2: short\n"
|
||||
" hello: int tuple[2]\n"
|
||||
)
|
||||
"Parameters\n"
|
||||
"----------\n"
|
||||
"e: A *\n"
|
||||
"arg2: short\n"
|
||||
"hello: int tuple[2]")
|
||||
|
||||
if sys.version_info[0:2] > (2, 4):
|
||||
# Python 2.4 does not seem to work
|
||||
check(A.variable_a.__doc__,
|
||||
check(inspect.getdoc(A.variable_a),
|
||||
"A_variable_a_get(self) -> int",
|
||||
"A.variable_a"
|
||||
)
|
||||
check(A.variable_b.__doc__,
|
||||
check(inspect.getdoc(A.variable_b),
|
||||
"A_variable_b_get(A self) -> int",
|
||||
"A.variable_b"
|
||||
)
|
||||
check(A.variable_c.__doc__,
|
||||
check(inspect.getdoc(A.variable_c),
|
||||
"A_variable_c_get(self) -> int\n"
|
||||
"\n"
|
||||
"Parameters:\n"
|
||||
" self: A *\n",
|
||||
"Parameters\n"
|
||||
"----------\n"
|
||||
"self: A *",
|
||||
"A.variable_c"
|
||||
)
|
||||
check(A.variable_d.__doc__,
|
||||
)
|
||||
check(inspect.getdoc(A.variable_d),
|
||||
"A_variable_d_get(A self) -> int\n"
|
||||
"\n"
|
||||
"Parameters:\n"
|
||||
" self: A *\n",
|
||||
"Parameters\n"
|
||||
"----------\n"
|
||||
"self: A *",
|
||||
"A.variable_d"
|
||||
)
|
||||
)
|
||||
|
||||
check(B.__doc__,
|
||||
"Proxy of C++ B class",
|
||||
check(inspect.getdoc(B),
|
||||
"Proxy of C++ B class.",
|
||||
"::B"
|
||||
)
|
||||
check(C.__init__.__doc__, "__init__(self, a, b, h) -> C", None, skip)
|
||||
check(D.__init__.__doc__,
|
||||
check(inspect.getdoc(C.__init__), "__init__(self, a, b, h) -> C", None, skip)
|
||||
check(inspect.getdoc(D.__init__),
|
||||
"__init__(D self, int a, int b, Hola h) -> D", None, skip)
|
||||
check(E.__init__.__doc__,
|
||||
check(inspect.getdoc(E.__init__),
|
||||
"__init__(self, a, b, h) -> E\n"
|
||||
"\n"
|
||||
"Parameters:\n"
|
||||
" a: special comment for parameter a\n"
|
||||
" b: another special comment for parameter b\n"
|
||||
" h: enum Hola\n",
|
||||
None, skip
|
||||
"__init__(self, a, b, h) -> E\n"
|
||||
"\n"
|
||||
"Parameters\n"
|
||||
"----------\n"
|
||||
"a: special comment for parameter a\n"
|
||||
"b: another special comment for parameter b\n"
|
||||
"h: enum Hola", None, skip
|
||||
)
|
||||
check(F.__init__.__doc__,
|
||||
check(inspect.getdoc(F.__init__),
|
||||
"__init__(F self, int a, int b, Hola h) -> F\n"
|
||||
"\n"
|
||||
"Parameters:\n"
|
||||
" a: special comment for parameter a\n"
|
||||
" b: another special comment for parameter b\n"
|
||||
" h: enum Hola\n",
|
||||
None, skip
|
||||
"__init__(F self, int a, int b, Hola h) -> F\n"
|
||||
"\n"
|
||||
"Parameters\n"
|
||||
"----------\n"
|
||||
"a: special comment for parameter a\n"
|
||||
"b: another special comment for parameter b\n"
|
||||
"h: enum Hola", None, skip
|
||||
)
|
||||
|
||||
check(B.funk.__doc__, "funk(B self, int c, int d) -> int")
|
||||
check(funk.__doc__, "funk(A e, short arg2, int c, int d) -> int")
|
||||
check(funkdefaults.__doc__,
|
||||
check(inspect.getdoc(B.funk),
|
||||
"funk(B self, int c, int d) -> int")
|
||||
check(inspect.getdoc(funk), "funk(A e, short arg2, int c, int d) -> int")
|
||||
check(inspect.getdoc(funkdefaults),
|
||||
"funkdefaults(A e, short arg2, int c, int d, double f=2) -> int\n"
|
||||
"funkdefaults(A e, short arg2, int c, int d) -> int"
|
||||
)
|
||||
"funkdefaults(A e, short arg2, int c, int d) -> int")
|
||||
|
||||
check(func_input.__doc__, "func_input(int * INPUT) -> int")
|
||||
check(func_output.__doc__, "func_output() -> int")
|
||||
check(func_inout.__doc__, "func_inout(int * INOUT) -> int")
|
||||
check(banana.__doc__, "banana(S a, S b, int c, Integer d)")
|
||||
check(inspect.getdoc(func_input), "func_input(int * INPUT) -> int")
|
||||
check(inspect.getdoc(func_output), "func_output() -> int")
|
||||
check(inspect.getdoc(func_inout), "func_inout(int * INOUT) -> int")
|
||||
check(inspect.getdoc(func_cb), "func_cb(int c, int d) -> int")
|
||||
check(inspect.getdoc(banana), "banana(S a, S b, int c, Integer d)")
|
||||
|
|
|
|||
|
|
@ -4,9 +4,14 @@ t = Test()
|
|||
if t.strlen('hile') != 4:
|
||||
print t.strlen('hile')
|
||||
raise RuntimeError, "bad multi-arg typemap"
|
||||
if t.ustrlen('hile') != 4:
|
||||
print t.ustrlen('hile')
|
||||
raise RuntimeError, "bad multi-arg typemap"
|
||||
|
||||
if t.strlen('hil\0') != 4:
|
||||
raise RuntimeError, "bad multi-arg typemap"
|
||||
if t.ustrlen('hil\0') != 4:
|
||||
raise RuntimeError, "bad multi-arg typemap"
|
||||
|
||||
#
|
||||
# creating a raw char*
|
||||
|
|
@ -21,6 +26,8 @@ pchar_setitem(pc, 4, 0)
|
|||
|
||||
if t.strlen(pc) != 4:
|
||||
raise RuntimeError, "bad multi-arg typemap"
|
||||
if t.ustrlen(pc) != 4:
|
||||
raise RuntimeError, "bad multi-arg typemap"
|
||||
|
||||
cvar.var_pchar = pc
|
||||
if cvar.var_pchar != "hola":
|
||||
|
|
|
|||
|
|
@ -17,3 +17,6 @@ if defaults2.ret(10.0) != 10.0:
|
|||
|
||||
if defaults2.ret() != -1.0:
|
||||
raise RuntimeError
|
||||
|
||||
if defaults2.nodefault(-2) != -2:
|
||||
raise RuntimeError
|
||||
|
|
|
|||
|
|
@ -18,3 +18,11 @@ if constant_directive.TYPE1_CONSTANT2.val != 2:
|
|||
if constant_directive.TYPE1_CONSTANT3.val != 3:
|
||||
raise RuntimeError("constant_directive.TYPE1_CONSTANT3.val is %r (should be 3)" %
|
||||
constant_directive.TYPE1_CONSTANT3.val)
|
||||
|
||||
if constant_directive.TYPE1CONST_CONSTANT1.val != 1:
|
||||
raise RuntimeError("constant_directive.TYPE1CONST_CONSTANT1.val is %r (should be 1)" %
|
||||
constant_directive.TYPE1CONST_CONSTANT1.val)
|
||||
|
||||
if constant_directive.TYPE1CPTR_CONSTANT1.val != 1:
|
||||
raise RuntimeError("constant_directive.TYPE1CPTR_CONSTANT1.val is %r (should be 1)" %
|
||||
constant_directive.TYPE1CPTR_CONSTANT1.val)
|
||||
|
|
|
|||
163
Examples/test-suite/python/cpp11_li_std_array_runme.py
Normal file
163
Examples/test-suite/python/cpp11_li_std_array_runme.py
Normal file
|
|
@ -0,0 +1,163 @@
|
|||
from cpp11_li_std_array import *
|
||||
import sys
|
||||
|
||||
|
||||
def failed(a, b, msg):
|
||||
raise RuntimeError, msg + " " + str(list(a)) + " " + str(list(b))
|
||||
|
||||
|
||||
def compare_sequences(a, b):
|
||||
if len(a) != len(b):
|
||||
failed(a, b, "different sizes")
|
||||
for i in range(len(a)):
|
||||
if a[i] != b[i]:
|
||||
failed(a, b, "elements are different")
|
||||
|
||||
def compare_containers(pythonlist, swigarray):
|
||||
compare_sequences(pythonlist, swigarray)
|
||||
|
||||
def steps_exception(swigarray, i, j, step):
|
||||
try:
|
||||
if i == None and j == None:
|
||||
a = swigarray[::step]
|
||||
elif i == None:
|
||||
a = swigarray[:j:step]
|
||||
elif j == None:
|
||||
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:
|
||||
# print("exception: {}".format(e))
|
||||
pass
|
||||
|
||||
def del_exception(swigarray, i, j, step):
|
||||
try:
|
||||
if i == None and j == None:
|
||||
del swigarray[::step]
|
||||
elif j == None and step == None:
|
||||
del swigarray[i]
|
||||
elif i == None:
|
||||
del swigarray[:j:step]
|
||||
elif j == None:
|
||||
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:
|
||||
# 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:
|
||||
# print("exception: {}".format(e))
|
||||
pass
|
||||
|
||||
|
||||
# Check std::array has similar behaviour to a Python list
|
||||
# except it is not resizable
|
||||
|
||||
ps = [0, 1, 2, 3, 4, 5]
|
||||
|
||||
ai = ArrayInt6(ps)
|
||||
|
||||
compare_containers(ps, ai)
|
||||
|
||||
# slices
|
||||
compare_containers(ps[0:6], ai[0:6])
|
||||
compare_containers(ps[0:10], ai[0:10])
|
||||
compare_containers(ps[-10:6], ai[-10:6])
|
||||
compare_containers(ps[-10:10], ai[-10:10])
|
||||
|
||||
compare_containers(ps[0:6:1], ai[0:6:1])
|
||||
compare_containers(ps[::], ai[::])
|
||||
compare_containers(ps[::1], ai[::1])
|
||||
|
||||
compare_containers([x for x in ps], [x for x in ai])
|
||||
|
||||
# Reverse
|
||||
compare_containers(ps[::-1], ai[::-1])
|
||||
compare_containers(ps[5::-1], ai[5::-1])
|
||||
compare_containers(ps[10::-1], ai[10::-1])
|
||||
|
||||
# Steps other than +1 and -1 not supported
|
||||
steps_exception(ai, 0, 6, 3)
|
||||
steps_exception(ai, None, None, 0)
|
||||
steps_exception(ai, None, None, 2)
|
||||
steps_exception(ai, None, None, -2)
|
||||
steps_exception(ai, 1, 3, 1)
|
||||
steps_exception(ai, 3, 1, -1)
|
||||
|
||||
# Modify content
|
||||
for i in range(len(ps)):
|
||||
ps[i] = (ps[i] + 1) * 10
|
||||
ai[i] = (ai[i] + 1) * 10
|
||||
compare_containers(ps, ai)
|
||||
|
||||
# Delete
|
||||
del_exception(ai, 0, 6, 3)
|
||||
del_exception(ai, None, None, 0)
|
||||
del_exception(ai, None, None, 2)
|
||||
del_exception(ai, None, None, -2)
|
||||
del_exception(ai, 1, 3, 1)
|
||||
del_exception(ai, 3, 1, -1)
|
||||
|
||||
del_exception(ai, 0, None, None)
|
||||
del_exception(ai, 5, None, None)
|
||||
|
||||
# Empty
|
||||
ai = ArrayInt6()
|
||||
compare_containers([0, 0, 0, 0, 0, 0], ai)
|
||||
|
||||
# Set slice
|
||||
newvals = [10, 20, 30, 40, 50, 60]
|
||||
ai[::] = newvals
|
||||
compare_containers(ai, newvals)
|
||||
|
||||
newvals = [100, 200, 300, 400, 500, 600]
|
||||
ai[0:6:1] = newvals
|
||||
compare_containers(ai, newvals)
|
||||
|
||||
newvals = [1000, 2000, 3000, 4000, 5000, 6000]
|
||||
ai[::-1] = newvals
|
||||
compare_containers(ai, newvals[::-1])
|
||||
|
||||
newvals = [10000, 20000, 30000, 40000, 50000, 60000]
|
||||
ai[-10:100:1] = newvals
|
||||
compare_containers(ai, newvals[-10:100:1])
|
||||
|
||||
setslice_exception(ai, [1, 2, 3, 4, 5, 6, 7])
|
||||
setslice_exception(ai, [1, 2, 3, 4, 5])
|
||||
setslice_exception(ai, [1, 2, 3, 4])
|
||||
setslice_exception(ai, [1, 2, 3])
|
||||
setslice_exception(ai, [1, 2])
|
||||
setslice_exception(ai, [1])
|
||||
setslice_exception(ai, [])
|
||||
|
||||
# Check return
|
||||
compare_containers(arrayOutVal(), [-2, -1, 0, 0, 1, 2])
|
||||
compare_containers(arrayOutConstRef(), [-2, -1, 0, 0, 1, 2])
|
||||
compare_containers(arrayOutRef(), [-2, -1, 0, 0, 1, 2])
|
||||
compare_containers(arrayOutPtr(), [-2, -1, 0, 0, 1, 2])
|
||||
|
||||
# Check passing arguments
|
||||
ai = arrayInVal([9, 8, 7, 6, 5, 4])
|
||||
compare_containers(ai, [90, 80, 70, 60, 50, 40])
|
||||
|
||||
ai = arrayInConstRef([9, 8, 7, 6, 5, 4])
|
||||
compare_containers(ai, [90, 80, 70, 60, 50, 40])
|
||||
|
||||
ai = ArrayInt6([9, 8, 7, 6, 5, 4])
|
||||
arrayInRef(ai)
|
||||
compare_containers(ai, [90, 80, 70, 60, 50, 40])
|
||||
|
||||
ai = ArrayInt6([9, 8, 7, 6, 5, 4])
|
||||
arrayInPtr(ai)
|
||||
compare_containers(ai, [90, 80, 70, 60, 50, 40])
|
||||
|
||||
# fill
|
||||
ai.fill(111)
|
||||
compare_containers(ai, [111, 111, 111, 111, 111, 111])
|
||||
43
Examples/test-suite/python/cpp11_template_typedefs_runme.py
Normal file
43
Examples/test-suite/python/cpp11_template_typedefs_runme.py
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
from cpp11_template_typedefs import *
|
||||
|
||||
t = create_TypedefName()
|
||||
if type(t).__name__ != "SomeTypeInt5":
|
||||
raise RuntimeError("type(t) is '%s' and should be 'SomeTypeInt5'" % type(t).__name__)
|
||||
|
||||
if t.a != "hello":
|
||||
raise RuntimeError("t.a should be 'hello'")
|
||||
if t.b != 10:
|
||||
raise RuntimeError("t.b should be 10")
|
||||
if t.get_n() != 5:
|
||||
raise RuntimeError("t.get_n() should be 5")
|
||||
|
||||
t_bool = create_TypedefNameBool()
|
||||
if type(t_bool).__name__ != "SomeTypeBool5":
|
||||
raise RuntimeError("type(t_bool) is '%s' and should be 'SomeTypeBool5'" % type(t_bool).__name__)
|
||||
|
||||
if t_bool.a != "hello":
|
||||
raise RuntimeError("t_bool.a should be 'hello'")
|
||||
if t_bool.b != True:
|
||||
raise RuntimeError("t_bool.b should be True")
|
||||
if t_bool.get_n() != 15:
|
||||
raise RuntimeError("t_bool.get_n() should be 15")
|
||||
|
||||
if get_SomeType_b(t) != 10:
|
||||
raise RuntimeError("get_SomeType_b(t) should be 10")
|
||||
|
||||
if get_SomeType_b2(t) != 10:
|
||||
raise RuntimeError("get_SomeType_b2(t) should be 10")
|
||||
|
||||
t2 = SomeTypeInt4()
|
||||
t2.b = 0
|
||||
t3 = identity(t2)
|
||||
t3.b = 5
|
||||
if t2.b != 5:
|
||||
raise RuntimeError("t2.b should be 5")
|
||||
|
||||
if get_bucket_allocator1() != 1:
|
||||
raise RuntimeError("bucket_allocator1 should be 1")
|
||||
|
||||
# SWIG doesn't handle ::MyClass as a template argument. Skip this test.
|
||||
#if get_bucket_allocator2() != 2:
|
||||
# raise RuntimeError("bucket_allocator2 should be 2")
|
||||
32
Examples/test-suite/python/cpp11_type_aliasing_runme.py
Normal file
32
Examples/test-suite/python/cpp11_type_aliasing_runme.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
from cpp11_type_aliasing import *
|
||||
|
||||
if get_host_target().bits != 32:
|
||||
raise RuntimeError("get_host_target().bits should return 32")
|
||||
|
||||
if mult2(10) != 20:
|
||||
raise RuntimeError("mult2(10) should return 20")
|
||||
|
||||
int_ptr = allocate_int()
|
||||
inplace_mult2(int_ptr)
|
||||
if read_int(int_ptr) != 24:
|
||||
raise RuntimeError("read_int should return 24")
|
||||
free_int(int_ptr)
|
||||
|
||||
pair = PairSubclass(3, 4)
|
||||
if pair.first() != 3:
|
||||
raise RuntimeError("pair.first() should return 3")
|
||||
|
||||
if pair.second() != 4:
|
||||
raise RuntimeError("pair.second() should return 4")
|
||||
|
||||
if pair.a != 3:
|
||||
raise RuntimeError("pair.a should be 3")
|
||||
|
||||
if plus1(5) != 6:
|
||||
raise RuntimeError("plus1(5) should return 6")
|
||||
|
||||
if call(mult2_cb, 7) != 14:
|
||||
raise RuntimeError("call(mult2_cb, 7) should return 14")
|
||||
|
||||
if call(get_callback(), 7) != 14:
|
||||
raise RuntimeError("call(get_callback(), 7) should return 14")
|
||||
|
|
@ -13,5 +13,31 @@ else:
|
|||
StaticFunctionTest().static_func()
|
||||
StaticFunctionTest().static_func_2(1)
|
||||
StaticFunctionTest().static_func_3(1, 2)
|
||||
StaticMemberTest.static_int = 10
|
||||
assert StaticMemberTest.static_int == 10
|
||||
|
||||
if is_python_builtin():
|
||||
if not StaticMemberTest.static_int == 99: raise RuntimeError("static_int not 99")
|
||||
StaticMemberTest.static_int = 10
|
||||
if not StaticMemberTest.static_int == 10: raise RuntimeError("static_int not 10")
|
||||
|
||||
if not StaticBase.statty == 11: raise RuntimeError("statty not 11")
|
||||
if not StaticDerived.statty == 111: raise RuntimeError("statty not 111")
|
||||
StaticBase.statty = 22
|
||||
StaticDerived.statty = 222
|
||||
if not StaticBase.statty == 22: raise RuntimeError("statty not 22")
|
||||
if not StaticDerived.statty == 222: raise RuntimeError("statty not 222")
|
||||
|
||||
# Restore
|
||||
StaticMemberTest.static_int = 99
|
||||
StaticBase.statty = 11
|
||||
StaticDerived.statty = 111
|
||||
|
||||
if not cvar.StaticMemberTest_static_int == 99: raise RuntimeError("cvar static_int not 99")
|
||||
cvar.StaticMemberTest_static_int = 10
|
||||
if not cvar.StaticMemberTest_static_int == 10: raise RuntimeError("cvar static_int not 10")
|
||||
|
||||
if not cvar.StaticBase_statty == 11: raise RuntimeError("cvar statty not 11")
|
||||
if not cvar.StaticDerived_statty == 111: raise RuntimeError("cvar statty not 111")
|
||||
cvar.StaticBase_statty = 22
|
||||
cvar.StaticDerived_statty = 222
|
||||
if not cvar.StaticBase_statty == 22: raise RuntimeError("cvar statty not 22")
|
||||
if not cvar.StaticDerived_statty == 222: raise RuntimeError("cvar statty not 222")
|
||||
|
|
|
|||
6
Examples/test-suite/python/default_args_c_runme.py
Normal file
6
Examples/test-suite/python/default_args_c_runme.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import default_args_c
|
||||
|
||||
if default_args_c.foo1() != 1:
|
||||
raise RuntimeError("failed")
|
||||
if default_args_c.foo43() != 43:
|
||||
raise RuntimeError("failed")
|
||||
|
|
@ -136,5 +136,23 @@ def run(module_name):
|
|||
if default_args.CDA().cdefaultargs_test2() != 1:
|
||||
raise RuntimeError
|
||||
|
||||
if default_args.chartest1() != 'x':
|
||||
raise RuntimeError
|
||||
|
||||
if default_args.chartest2() != '\0':
|
||||
raise RuntimeError
|
||||
|
||||
if default_args.chartest3() != '\1':
|
||||
raise RuntimeError
|
||||
|
||||
if default_args.chartest4() != '\n':
|
||||
raise RuntimeError
|
||||
|
||||
if default_args.chartest5() != 'B':
|
||||
raise RuntimeError
|
||||
|
||||
if default_args.chartest6() != 'C':
|
||||
raise RuntimeError
|
||||
|
||||
if __name__ == "__main__":
|
||||
run('default_args')
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ class TargetLangOrphanPerson(OrphanPerson):
|
|||
class TargetLangOrphanChild(OrphanChild):
|
||||
|
||||
def __init__(self):
|
||||
Child.__init__(self)
|
||||
OrphanChild.__init__(self)
|
||||
|
||||
def id(self):
|
||||
identifier = "TargetLangOrphanChild"
|
||||
|
|
|
|||
13
Examples/test-suite/python/director_pass_by_value_runme.py
Normal file
13
Examples/test-suite/python/director_pass_by_value_runme.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import director_pass_by_value
|
||||
|
||||
passByVal = None
|
||||
class director_pass_by_value_Derived(director_pass_by_value.DirectorPassByValueAbstractBase):
|
||||
def virtualMethod(self, b):
|
||||
global passByVal
|
||||
passByVal = b
|
||||
|
||||
# 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())
|
||||
ret = passByVal.getVal();
|
||||
if ret != 0x12345678:
|
||||
raise RuntimeError("Bad return value, got " + hex(ret))
|
||||
37
Examples/test-suite/python/director_smartptr_runme.py
Normal file
37
Examples/test-suite/python/director_smartptr_runme.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
from director_smartptr import *
|
||||
|
||||
|
||||
class director_smartptr_MyBarFoo(Foo):
|
||||
|
||||
def ping(self):
|
||||
return "director_smartptr_MyBarFoo.ping()"
|
||||
|
||||
def pong(self):
|
||||
return "director_smartptr_MyBarFoo.pong();" + self.ping()
|
||||
|
||||
def upcall(self, fooBarPtr):
|
||||
return "override;" + fooBarPtr.FooBarDo()
|
||||
|
||||
def makeFoo(self):
|
||||
return Foo()
|
||||
|
||||
def check(got, expected):
|
||||
if (got != expected):
|
||||
raise RuntimeError, "Failed, got: " + got + " expected: " + expected
|
||||
|
||||
fooBar = FooBar()
|
||||
|
||||
myBarFoo = director_smartptr_MyBarFoo()
|
||||
check(myBarFoo.ping(), "director_smartptr_MyBarFoo.ping()")
|
||||
check(Foo.callPong(myBarFoo), "director_smartptr_MyBarFoo.pong();director_smartptr_MyBarFoo.ping()")
|
||||
check(Foo.callUpcall(myBarFoo, fooBar), "override;Bar::Foo2::Foo2Bar()")
|
||||
|
||||
myFoo = myBarFoo.makeFoo()
|
||||
check(myFoo.pong(), "Foo::pong();Foo::ping()")
|
||||
check(Foo.callPong(myFoo), "Foo::pong();Foo::ping()")
|
||||
check(myFoo.upcall(FooBar()), "Bar::Foo2::Foo2Bar()")
|
||||
|
||||
myFoo2 = Foo().makeFoo()
|
||||
check(myFoo2.pong(), "Foo::pong();Foo::ping()")
|
||||
check(Foo.callPong(myFoo2), "Foo::pong();Foo::ping()")
|
||||
check(myFoo2.upcall(FooBar()), "Bar::Foo2::Foo2Bar()")
|
||||
1
Examples/test-suite/python/empty_c_runme.py
Normal file
1
Examples/test-suite/python/empty_c_runme.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
import empty_c
|
||||
5
Examples/test-suite/python/exception_classname_runme.py
Normal file
5
Examples/test-suite/python/exception_classname_runme.py
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import exception_classname
|
||||
|
||||
a = exception_classname.Exception()
|
||||
if a.testfunc() != 42:
|
||||
raise RuntimeError("Not 42!")
|
||||
|
|
@ -6,3 +6,5 @@ if call2(ADD_BY_POINTER, 12, 13) != 25:
|
|||
raise RuntimeError
|
||||
if call3(ADD_BY_REFERENCE, 14, 15) != 29:
|
||||
raise RuntimeError
|
||||
if call1(ADD_BY_VALUE_C, 2, 3) != 5:
|
||||
raise RuntimeError
|
||||
|
|
|
|||
4
Examples/test-suite/python/keyword_rename_c_runme.py
Normal file
4
Examples/test-suite/python/keyword_rename_c_runme.py
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
import keyword_rename_c
|
||||
keyword_rename_c._in(1)
|
||||
keyword_rename_c._except(1)
|
||||
|
|
@ -71,3 +71,13 @@ if myStringyClass.ReadWriteString != "changed string":
|
|||
raise RuntimeError
|
||||
if myStringyClass.ReadOnlyString != "changed string":
|
||||
raise RuntimeError
|
||||
|
||||
# Check a proper AttributeError is raised for non-existent attributes, old versions used to raise unhelpful error:
|
||||
# AttributeError: type object 'object' has no attribute '__getattr__'
|
||||
try:
|
||||
x = myFoo.does_not_exist
|
||||
raise RuntimeError
|
||||
except AttributeError, e:
|
||||
if str(e).find("does_not_exist") == -1:
|
||||
raise RuntimeError
|
||||
|
||||
|
|
|
|||
|
|
@ -521,7 +521,6 @@ class li_boost_shared_ptr_runme:
|
|||
li_boost_shared_ptr.cvar.GlobalPointer = None
|
||||
|
||||
# plain reference
|
||||
kglobal
|
||||
|
||||
k = li_boost_shared_ptr.Klass("global reference")
|
||||
li_boost_shared_ptr.cvar.GlobalReference = k
|
||||
|
|
|
|||
|
|
@ -8,9 +8,8 @@ if d.bar() != 2:
|
|||
raise RuntimeError
|
||||
if bar_getter(b) != 1:
|
||||
raise RuntimeError
|
||||
# Fix reverted in rev 12953
|
||||
# if bar_getter(d) != 2:
|
||||
# raise RuntimeError
|
||||
if bar_getter(d) != 2:
|
||||
raise RuntimeError
|
||||
|
||||
b = BaseDefaultInt()
|
||||
d = DerivedDefaultInt()
|
||||
|
|
@ -23,8 +22,11 @@ if d2.bar2() != 4:
|
|||
raise RuntimeError
|
||||
if bar2_getter(b) != 3:
|
||||
raise RuntimeError
|
||||
# Fix reverted in rev 12953
|
||||
# if bar2_getter(d) != 4:
|
||||
# raise RuntimeError
|
||||
# if bar2_getter(d2) != 4:
|
||||
# raise RuntimeError
|
||||
# SWIG fix reverted in Subversion rev 12953
|
||||
# Testcase has now been modified to mask the problem by providing the default parameter 'int' in:
|
||||
# %shared_ptr(Space::BaseDefault<short, int>)
|
||||
# If this is not done then d fails to convert to BaseDefault<short>&
|
||||
if bar2_getter(d) != 4:
|
||||
raise RuntimeError
|
||||
if bar2_getter(d2) != 4:
|
||||
raise RuntimeError
|
||||
|
|
|
|||
9
Examples/test-suite/python/li_carrays_cpp_runme.py
Normal file
9
Examples/test-suite/python/li_carrays_cpp_runme.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
from li_carrays_cpp import *
|
||||
|
||||
d = doubleArray(10)
|
||||
|
||||
d[0] = 7
|
||||
d[5] = d[0] + 3
|
||||
|
||||
if d[5] + d[0] != 17:
|
||||
raise RuntimeError
|
||||
9
Examples/test-suite/python/li_cdata_cpp_runme.py
Normal file
9
Examples/test-suite/python/li_cdata_cpp_runme.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
from li_cdata_cpp import *
|
||||
|
||||
s = "ABC abc"
|
||||
m = malloc(256)
|
||||
memmove(m, s)
|
||||
ss = cdata(m, 7)
|
||||
if ss != "ABC abc":
|
||||
raise "failed"
|
||||
10
Examples/test-suite/python/li_cpointer_cpp_runme.py
Normal file
10
Examples/test-suite/python/li_cpointer_cpp_runme.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
from li_cpointer_cpp import *
|
||||
|
||||
|
||||
p = new_intp()
|
||||
intp_assign(p, 3)
|
||||
|
||||
if intp_value(p) != 3:
|
||||
raise RuntimeError
|
||||
|
||||
delete_intp(p)
|
||||
|
|
@ -1,7 +1,56 @@
|
|||
from li_std_vector_ptr import *
|
||||
|
||||
def check(val1, val2):
|
||||
if val1 != val2:
|
||||
raise RuntimeError("Values are not the same %s %s" % (val1, val2))
|
||||
ip1 = makeIntPtr(11)
|
||||
ip2 = makeIntPtr(22)
|
||||
|
||||
vi = IntPtrVector((ip1, ip2))
|
||||
displayVector(vi)
|
||||
check(getValueFromVector(vi, 0), 11)
|
||||
check(getValueFromVector(vi, 1), 22)
|
||||
|
||||
vA = APtrVector([makeA(33), makeA(34)])
|
||||
check(getVectorValueA(vA, 0), 33)
|
||||
|
||||
vB = BPtrVector([makeB(133), makeB(134)])
|
||||
check(getVectorValueB(vB, 0), 133)
|
||||
|
||||
vC = CPtrVector([makeC(1133), makeC(1134)])
|
||||
check(getVectorValueC(vC, 0), 1133)
|
||||
|
||||
|
||||
vA = [makeA(233), makeA(234)]
|
||||
check(getVectorValueA(vA, 0), 233)
|
||||
|
||||
vB = [makeB(333), makeB(334)]
|
||||
check(getVectorValueB(vB, 0), 333)
|
||||
|
||||
vC = [makeC(3333), makeC(3334)]
|
||||
check(getVectorValueC(vC, 0), 3333)
|
||||
|
||||
# mixed A and B should not be accepted
|
||||
vAB = [makeA(999), makeB(999)]
|
||||
try:
|
||||
check(getVectorValueA(vAB, 0), 999)
|
||||
raise RuntimeError("missed exception")
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
b111 = makeB(111)
|
||||
bNones = BPtrVector([None, b111, None])
|
||||
|
||||
bCount = 0
|
||||
noneCount = 0
|
||||
for b in bNones:
|
||||
if b == None:
|
||||
noneCount = noneCount + 1
|
||||
else:
|
||||
if b.val != 111:
|
||||
raise RuntimeError("b.val is wrong")
|
||||
bCount = bCount + 1
|
||||
|
||||
if bCount != 1:
|
||||
raise RuntimeError("bCount wrong")
|
||||
if noneCount != 2:
|
||||
raise RuntimeError("noneCount wrong")
|
||||
|
|
|
|||
10
Examples/test-suite/python/li_std_vector_runme.py
Normal file
10
Examples/test-suite/python/li_std_vector_runme.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
from li_std_vector import *
|
||||
|
||||
if typedef_test(101) != 101:
|
||||
raise RuntimeError
|
||||
|
||||
try:
|
||||
sv = StructVector([None, None])
|
||||
raise RuntimeError("Using None should result in a TypeError")
|
||||
except TypeError:
|
||||
pass
|
||||
77
Examples/test-suite/python/operator_overload_runme.py
Normal file
77
Examples/test-suite/python/operator_overload_runme.py
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
from operator_overload import *
|
||||
|
||||
# first check all the operators are implemented correctly from pure C++ code
|
||||
Op_sanity_check()
|
||||
|
||||
pop = Op(6)/Op(3)
|
||||
|
||||
# test routine:
|
||||
a=Op()
|
||||
b=Op(5)
|
||||
c=Op(b) # copy construct
|
||||
d=Op(2)
|
||||
dd=d # assignment operator
|
||||
|
||||
# test equality
|
||||
if not a!=b:
|
||||
raise RuntimeError("a!=b")
|
||||
if not b==c:
|
||||
raise RuntimeError("b==c")
|
||||
if not a!=d:
|
||||
raise RuntimeError("a!=d")
|
||||
if not d==dd:
|
||||
raise RuntimeError("d==dd")
|
||||
|
||||
# test <
|
||||
if not a<b:
|
||||
raise RuntimeError("a<b")
|
||||
if not a<=b:
|
||||
raise RuntimeError("a<=b")
|
||||
if not b<=c:
|
||||
raise RuntimeError("b<=c")
|
||||
if not b>=c:
|
||||
raise RuntimeError("b>=c")
|
||||
if not b>d:
|
||||
raise RuntimeError("b>d")
|
||||
if not b>=d:
|
||||
raise RuntimeError("b>=d")
|
||||
|
||||
# test +=
|
||||
e=Op(3)
|
||||
e+=d
|
||||
if not e==b:
|
||||
raise RuntimeError("e==b (%s==%s)" % (e.i, b.i))
|
||||
e-=c
|
||||
if not e==a:
|
||||
raise RuntimeError("e==a")
|
||||
e=Op(1)
|
||||
e*=b
|
||||
if not e==c:
|
||||
raise RuntimeError("e==c")
|
||||
e/=d
|
||||
if not e==d:
|
||||
raise RuntimeError("e==d")
|
||||
e%=c;
|
||||
if not e==d:
|
||||
raise RuntimeError("e==d")
|
||||
|
||||
# test +
|
||||
f=Op(1)
|
||||
g=Op(1)
|
||||
if not f+g==Op(2):
|
||||
raise RuntimeError("f+g==Op(2)")
|
||||
if not f-g==Op(0):
|
||||
raise RuntimeError("f-g==Op(0)")
|
||||
if not f*g==Op(1):
|
||||
raise RuntimeError("f*g==Op(1)")
|
||||
if not f/g==Op(1):
|
||||
raise RuntimeError("f/g==Op(1)")
|
||||
if not f%g==Op(0):
|
||||
raise RuntimeError("f%g==Op(0)")
|
||||
|
||||
# test unary operators
|
||||
if not -a==a:
|
||||
raise RuntimeError("-a==a")
|
||||
if not -b==Op(-5):
|
||||
raise RuntimeError("-b==Op(-5)")
|
||||
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
import operbool
|
||||
assert not operbool.Test()
|
||||
if operbool.Test():
|
||||
raise RuntimeError("operbool failed")
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import overload_extendc
|
||||
import overload_extend2
|
||||
|
||||
f = overload_extendc.Foo()
|
||||
f = overload_extend2.Foo()
|
||||
if f.test(3) != 1:
|
||||
raise RuntimeError
|
||||
if f.test("hello") != 2:
|
||||
13
Examples/test-suite/python/overload_extend_c_runme.py
Normal file
13
Examples/test-suite/python/overload_extend_c_runme.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import overload_extend_c
|
||||
|
||||
f = overload_extend_c.Foo()
|
||||
if f.test() != 0:
|
||||
raise RuntimeError
|
||||
if f.test(3) != 1:
|
||||
raise RuntimeError
|
||||
if f.test("hello") != 2:
|
||||
raise RuntimeError
|
||||
if f.test(3, 2) != 5:
|
||||
raise RuntimeError
|
||||
if f.test(3.0) != 1003:
|
||||
raise RuntimeError
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
import sys
|
||||
from primitive_types import *
|
||||
|
||||
var_init()
|
||||
|
|
@ -436,3 +437,175 @@ if s != "hello":
|
|||
v = SetPos(1, 3)
|
||||
if v != 4:
|
||||
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
|
||||
overchar = 2 ** 7
|
||||
while ctypes.c_byte(overchar).value > 0:
|
||||
overchar *= 2
|
||||
minchar = -overchar
|
||||
maxchar = overchar - 1
|
||||
maxuchar = 2 * maxchar + 1
|
||||
overshort = overchar
|
||||
while ctypes.c_short(overshort).value > 0:
|
||||
overshort *= 2
|
||||
minshort = -overshort
|
||||
maxshort = overshort - 1
|
||||
maxushort = 2 * maxshort + 1
|
||||
overint = overshort
|
||||
while ctypes.c_int(overint).value > 0:
|
||||
overint *= 2
|
||||
minint = -overint
|
||||
maxint = overint - 1
|
||||
maxuint = 2 * maxint + 1
|
||||
overlong = overint
|
||||
while ctypes.c_long(overlong).value > 0:
|
||||
overlong *= 2
|
||||
minlong = -overlong
|
||||
maxlong = overlong - 1
|
||||
maxulong = 2 * maxlong + 1
|
||||
overllong = overlong
|
||||
while ctypes.c_longlong(overllong).value > 0:
|
||||
overllong *= 2
|
||||
minllong = -overllong
|
||||
maxllong = overllong - 1
|
||||
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"
|
||||
|
||||
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"""
|
||||
error = 0
|
||||
# Set the extreme valid value for var_*
|
||||
setattr(t, 'var_' + e, val)
|
||||
# Make sure it was set properly and works properly in the val_* and ref_* methods
|
||||
if getattr(t, 'var_' + e) != val or getattr(t, 'val_' + e)(val) != val or getattr(t, 'ref_' + e)(val) != val:
|
||||
error = 1
|
||||
# Make sure setting a more extreme value fails without changing the value
|
||||
try:
|
||||
a = getattr(t, 'var_' + e)
|
||||
setattr(t, 'var_' + e, val + delta)
|
||||
error = 1
|
||||
except OverflowError:
|
||||
if a != getattr(t, 'var_' + e):
|
||||
error = 1
|
||||
# Make sure the val_* and ref_* methods fail with a more extreme value
|
||||
try:
|
||||
getattr(t, 'val_' + e)(val + delta)
|
||||
error = 1
|
||||
except OverflowError:
|
||||
pass
|
||||
try:
|
||||
getattr(t, 'ref_' + e)(val + delta)
|
||||
error = 1
|
||||
except OverflowError:
|
||||
pass
|
||||
if error:
|
||||
raise RuntimeError, "bad " + e + " typemap"
|
||||
|
||||
def checkFull(t, e, maxval, minval):
|
||||
"""Check the maximum and minimum bounds for the type given by e"""
|
||||
checkType(t, e, maxval, 1)
|
||||
checkType(t, e, minval, -1)
|
||||
|
||||
checkFull(t, 'llong', maxllong, minllong)
|
||||
checkFull(t, 'long', maxlong, minlong)
|
||||
checkFull(t, 'int', maxint, minint)
|
||||
checkFull(t, 'short', maxshort, minshort)
|
||||
checkFull(t, 'schar', maxchar, minchar)
|
||||
checkFull(t, 'ullong', maxullong, 0)
|
||||
checkFull(t, 'ulong', maxulong, 0)
|
||||
checkFull(t, 'uint', maxuint, 0)
|
||||
checkFull(t, 'ushort', maxushort, 0)
|
||||
checkFull(t, 'uchar', maxuchar, 0)
|
||||
|
||||
def checkOverload(t, name, val, delta, prevval, limit):
|
||||
"""
|
||||
Check that overloading works
|
||||
t = Test object
|
||||
name = type name (e.g. ulong)
|
||||
val = max or min allowed value
|
||||
delta = +1 for max, -1 for min
|
||||
prevval = corresponding value for one smaller type
|
||||
limit = most extreme value for any type
|
||||
"""
|
||||
# If val == prevval, then the smaller typemap will win
|
||||
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"
|
||||
# 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"
|
||||
if val == limit:
|
||||
# Should raise NotImplementedError here since this is the largest integral type
|
||||
raise RuntimeError, "bad " + name + " typemap"
|
||||
except NotImplementedError:
|
||||
# NotImplementedError is expected only if this is the most extreme type
|
||||
if val != limit:
|
||||
raise RuntimeError, "bad " + name + " typemap"
|
||||
except TypeError:
|
||||
# TypeError is raised instead if swig is run with -O or -fastdispatch
|
||||
if val != limit:
|
||||
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)
|
||||
checkOverload(t, 'ushort', maxushort, +1, maxuchar, maxullong)
|
||||
checkOverload(t, 'uint', maxuint, +1, maxushort, maxullong)
|
||||
checkOverload(t, 'ulong', maxulong, +1, maxuint, maxullong)
|
||||
checkOverload(t, 'ullong', maxullong, +1, maxulong, maxullong)
|
||||
checkOverload(t, 'schar', minchar, -1, 0, minllong)
|
||||
checkOverload(t, 'short', minshort, -1, minchar, minllong)
|
||||
checkOverload(t, 'int', minint, -1, minshort, minllong)
|
||||
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"
|
||||
|
||||
|
||||
# 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"
|
||||
if minfunc() != minval:
|
||||
raise RuntimeError, "bad " + name + " typemap"
|
||||
if echofunc(maxval) != maxval:
|
||||
raise RuntimeError, "bad " + name + " typemap"
|
||||
if echofunc(minval) != minval:
|
||||
raise RuntimeError, "bad " + name + " typemap"
|
||||
error = 0
|
||||
try:
|
||||
echofunc(maxval + 1)
|
||||
error = 1
|
||||
except OverflowError:
|
||||
pass
|
||||
if error == 1:
|
||||
raise RuntimeError, "bad " + name + " typemap"
|
||||
try:
|
||||
echofunc(minval - 1)
|
||||
error = 1
|
||||
except OverflowError:
|
||||
pass
|
||||
if error == 1:
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,10 @@ from collections import *
|
|||
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)
|
||||
|
||||
assert issubclass(Mapii, MutableMapping)
|
||||
assert issubclass(Multimapii, MutableMapping)
|
||||
assert issubclass(IntSet, MutableSet)
|
||||
|
|
|
|||
|
|
@ -20,3 +20,10 @@ if grabpath() != os.path.dirname(mypath):
|
|||
|
||||
if grabstaticpath() != os.path.basename(mypath):
|
||||
raise RuntimeError("grabstaticpath failed")
|
||||
|
||||
clearstaticpath()
|
||||
if grabstaticpath() != None:
|
||||
raise RuntimeError("Resetting staticfuncpath failed")
|
||||
Test.static_func()
|
||||
if grabstaticpath() != os.path.basename(mypath):
|
||||
raise RuntimeError("grabstaticpath failed")
|
||||
|
|
|
|||
94
Examples/test-suite/python/python_builtin_runme.py
Normal file
94
Examples/test-suite/python/python_builtin_runme.py
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
from python_builtin import *
|
||||
|
||||
if is_python_builtin():
|
||||
# Test 0 for default tp_hash
|
||||
vs = ValueStruct(1234)
|
||||
h = hash(vs)
|
||||
d = dict()
|
||||
d[h] = "hi"
|
||||
if h not in d:
|
||||
raise RuntimeError("h should be in d")
|
||||
h2 = hash(ValueStruct.inout(vs))
|
||||
if h != h2:
|
||||
raise RuntimeError("default tp_hash not working")
|
||||
|
||||
# Test 1 for tp_hash
|
||||
if hash(SimpleValue(222)) != 222:
|
||||
raise RuntimeError("tp_hash not working")
|
||||
|
||||
# Test 2 for tp_hash
|
||||
try:
|
||||
# Was incorrectly raising: SystemError: error return without exception set
|
||||
h = hash(BadHashFunctionReturnType())
|
||||
raise RuntimeError("Missing TypeError")
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
# Test 3 for tp_hash
|
||||
passed = False
|
||||
try:
|
||||
h = hash(ExceptionHashFunction())
|
||||
except RuntimeError, e:
|
||||
passed = str(e).find("oops") != -1
|
||||
pass
|
||||
|
||||
if not passed:
|
||||
raise RuntimeError("did not catch exception in hash()")
|
||||
|
||||
# Test 4 for tp_dealloc (which is handled differently to other slots in the SWIG source)
|
||||
d = Dealloc1()
|
||||
if cvar.Dealloc1CalledCount != 0:
|
||||
raise RuntimeError("count should be 0")
|
||||
del d
|
||||
if cvar.Dealloc1CalledCount != 1:
|
||||
raise RuntimeError("count should be 1")
|
||||
|
||||
d = Dealloc2()
|
||||
if cvar.Dealloc2CalledCount != 0:
|
||||
raise RuntimeError("count should be 0")
|
||||
del d
|
||||
if cvar.Dealloc2CalledCount != 1:
|
||||
raise RuntimeError("count should be 1")
|
||||
|
||||
d = Dealloc3()
|
||||
if cvar.Dealloc3CalledCount != 0:
|
||||
raise RuntimeError("count should be 0")
|
||||
del d
|
||||
if cvar.Dealloc3CalledCount != 1:
|
||||
raise RuntimeError("count should be 1")
|
||||
|
||||
# Test 5 for python:compare feature
|
||||
m10 = MyClass(10)
|
||||
m20 = MyClass(20)
|
||||
m15 = MyClass(15)
|
||||
|
||||
if not m10 < m15:
|
||||
raise RuntimeError("m10 < m15")
|
||||
if not m10 < m20:
|
||||
raise RuntimeError("m10 < m20")
|
||||
if not m15 < m20:
|
||||
raise RuntimeError("m15 < m20")
|
||||
|
||||
if m10 > m15:
|
||||
raise RuntimeError("m10 > m15")
|
||||
if m10 > m20:
|
||||
raise RuntimeError("m10 > m20")
|
||||
if m15 > m20:
|
||||
raise RuntimeError("m15 > m20")
|
||||
|
||||
if MyClass.less_than_counts != 6:
|
||||
raise RuntimeError("python:compare feature not working")
|
||||
|
||||
sa = SimpleArray(5)
|
||||
elements = [x for x in sa]
|
||||
if elements != [0, 10, 20, 30, 40]:
|
||||
raise RuntimeError("Iteration not working")
|
||||
if len(sa) != 5:
|
||||
raise RuntimeError("len not working")
|
||||
for i in range(5):
|
||||
if sa[i] != i*10:
|
||||
raise RuntimeError("indexing not working")
|
||||
subslice = sa[1:3]
|
||||
elements = [x for x in subslice]
|
||||
if elements != [10, 20]:
|
||||
raise RuntimeError("slice not working")
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
import python_destructor_exception
|
||||
from StringIO import StringIO
|
||||
import sys
|
||||
|
||||
def error_function():
|
||||
python_destructor_exception.ClassWithThrowingDestructor().GetBlah()
|
||||
|
||||
def runtest():
|
||||
attributeErrorOccurred = False
|
||||
try:
|
||||
error_function()
|
||||
except AttributeError, e:
|
||||
attributeErrorOccurred = True
|
||||
return attributeErrorOccurred
|
||||
|
||||
def test1():
|
||||
stderr_saved = sys.stderr
|
||||
buffer = StringIO()
|
||||
attributeErrorOccurred = False
|
||||
try:
|
||||
# Suppress stderr while making this call to suppress the output shown by PyErr_WriteUnraisable
|
||||
sys.stderr = buffer
|
||||
|
||||
attributeErrorOccurred = runtest()
|
||||
finally:
|
||||
sys.stderr.flush()
|
||||
sys.stderr = stderr_saved
|
||||
|
||||
if not attributeErrorOccurred:
|
||||
raise RuntimeError("attributeErrorOccurred failed")
|
||||
if not buffer.getvalue().count("I am the ClassWithThrowingDestructor dtor doing bad things") >= 1:
|
||||
raise RuntimeError("ClassWithThrowingDestructor dtor doing bad things failed")
|
||||
|
||||
class VectorHolder(object):
|
||||
def __init__(self, v):
|
||||
self.v = v
|
||||
def gen(self):
|
||||
for e in self.v:
|
||||
yield e
|
||||
|
||||
# See issue #559, #560, #573 - In Python 3.5, test2() call to the generator 'gen' was
|
||||
# resulting in the following (not for -builtin where there is no call to SWIG_Python_CallFunctor
|
||||
# as SwigPyObject_dealloc is not used):
|
||||
#
|
||||
# StopIteration
|
||||
#
|
||||
# During handling of the above exception, another exception occurred:
|
||||
# ...
|
||||
# SystemError: <built-in function delete_VectorInt> returned a result with an error set
|
||||
|
||||
def addup():
|
||||
sum = 0
|
||||
for i in VectorHolder(python_destructor_exception.VectorInt([1, 2, 3])).gen():
|
||||
sum = sum + i
|
||||
return sum
|
||||
|
||||
def test2():
|
||||
sum = addup()
|
||||
|
||||
if sum != 6:
|
||||
raise RuntimeError("Sum is incorrect")
|
||||
|
||||
# These two tests are different are two different ways to recreate essentially the same problem
|
||||
# reported by Python 3.5 that an exception was already set when destroying a wrapped object
|
||||
test1()
|
||||
test2()
|
||||
100
Examples/test-suite/python/python_docstring_runme.py
Normal file
100
Examples/test-suite/python/python_docstring_runme.py
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
from python_docstring import *
|
||||
import inspect
|
||||
|
||||
def check(got, expected):
|
||||
expected_list = expected.split("\n")
|
||||
got_list = got.split("\n")
|
||||
|
||||
if expected_list != got_list:
|
||||
raise RuntimeError("\n" + "Expected: " + str(expected_list) + "\n" + "Got : " + str(got_list))
|
||||
|
||||
# When getting docstrings, use inspect.getdoc(x) instead of x.__doc__ otherwise the different options
|
||||
# such as -O, -builtin, -classic produce different initial indentation.
|
||||
|
||||
check(inspect.getdoc(DocStrings.docstring1),
|
||||
" line 1\n"
|
||||
"line 2\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"line 3"
|
||||
)
|
||||
|
||||
check(inspect.getdoc(DocStrings.docstring2),
|
||||
"line 1\n"
|
||||
" line 2\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
" line 3"
|
||||
)
|
||||
|
||||
check(inspect.getdoc(DocStrings.docstring3),
|
||||
"line 1\n"
|
||||
" line 2\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
" line 3"
|
||||
)
|
||||
|
||||
check(inspect.getdoc(DocStrings.docstring4),
|
||||
"line 1\n"
|
||||
" line 2\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
" line 3"
|
||||
)
|
||||
|
||||
check(inspect.getdoc(DocStrings.docstring5),
|
||||
"line 1\n"
|
||||
" line 2\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
" line 3"
|
||||
)
|
||||
|
||||
check(inspect.getdoc(DocStrings.docstring6),
|
||||
"line 1\n"
|
||||
" line 2\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
" line 3"
|
||||
)
|
||||
|
||||
check(inspect.getdoc(DocStrings.docstring7),
|
||||
"line 1\n"
|
||||
"line 2\n"
|
||||
"line 3"
|
||||
)
|
||||
|
||||
check(inspect.getdoc(DocStrings.docstringA),
|
||||
"first line\n"
|
||||
"second line"
|
||||
)
|
||||
|
||||
check(inspect.getdoc(DocStrings.docstringB),
|
||||
"first line\n"
|
||||
"second line"
|
||||
)
|
||||
|
||||
check(inspect.getdoc(DocStrings.docstringC),
|
||||
"first line\n"
|
||||
"second line"
|
||||
)
|
||||
|
||||
# One line doc special case, use __doc__
|
||||
check(DocStrings.docstringX.__doc__,
|
||||
" one line docs"
|
||||
)
|
||||
|
||||
check(inspect.getdoc(DocStrings.docstringX),
|
||||
"one line docs"
|
||||
)
|
||||
|
||||
check(inspect.getdoc(DocStrings.docstringY),
|
||||
"one line docs"
|
||||
)
|
||||
11
Examples/test-suite/python/python_extranative_runme.py
Normal file
11
Examples/test-suite/python/python_extranative_runme.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import python_extranative
|
||||
|
||||
vs = python_extranative.make_vector_string()
|
||||
if not isinstance(vs, python_extranative.VectorString):
|
||||
# will be of type tuple if extranative not working
|
||||
raise RuntimeError("Not of type VectorString")
|
||||
|
||||
for s1, s2 in zip(vs, ["one", "two"]):
|
||||
if s1 != s2:
|
||||
raise RuntimeError("Mismatch: " + s1 + " " + s2)
|
||||
|
||||
7
Examples/test-suite/python/python_moduleimport_runme.py
Normal file
7
Examples/test-suite/python/python_moduleimport_runme.py
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import python_moduleimport
|
||||
|
||||
if python_moduleimport.simple_function(99) != 99:
|
||||
raise RuntimeError("simple_function")
|
||||
|
||||
if python_moduleimport.extra_import_variable != "custom import of _python_moduleimport":
|
||||
raise RuntimeError("custom import")
|
||||
35
Examples/test-suite/python/python_pickle_runme.py
Normal file
35
Examples/test-suite/python/python_pickle_runme.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import python_pickle
|
||||
|
||||
import pickle
|
||||
import sys
|
||||
|
||||
def is_new_style_class(cls):
|
||||
return hasattr(cls, "__class__")
|
||||
|
||||
def check(p):
|
||||
msg = p.msg
|
||||
if msg != "hi there":
|
||||
raise RuntimeError("Bad, got: " + msg)
|
||||
|
||||
if not is_new_style_class(python_pickle.PickleMe):
|
||||
sys.exit(0)
|
||||
|
||||
python_pickle.cvar.debug = False
|
||||
|
||||
p = python_pickle.PickleMe("hi there")
|
||||
check(p)
|
||||
|
||||
r = p.__reduce__()
|
||||
if python_pickle.cvar.debug:
|
||||
print "__reduce__ returned:", 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__()
|
||||
#pickle_string = pickle.dumps(nfp)
|
||||
#print pickle_string
|
||||
#newp = pickle.loads(pickle_string)
|
||||
#print newp.msg
|
||||
79
Examples/test-suite/python/python_strict_unicode_runme.py
Normal file
79
Examples/test-suite/python/python_strict_unicode_runme.py
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
import python_strict_unicode
|
||||
from sys import version_info
|
||||
|
||||
test_bytes = 'hello \x01world\x99'
|
||||
BYTES = 'BYTES'
|
||||
test_unicode = u'h\udce9llo w\u00f6rld'
|
||||
|
||||
# Python < 2.6 rejects the b prefix for byte string literals as a SyntaxError,
|
||||
# so instead create Python3 bytes objects by encoding unicode strings as
|
||||
# latin-1, which maps code points 0-255 directly to the corresponding bytes.
|
||||
if version_info[0] >= 3:
|
||||
test_bytes = test_bytes.encode('latin-1')
|
||||
BYTES = BYTES.encode('latin-1')
|
||||
|
||||
# Test that byte string inputs and outputs work as expected
|
||||
bdbl = python_strict_unicode.double_str(test_bytes)
|
||||
if bdbl != test_bytes + test_bytes:
|
||||
raise RuntimeError("Failed to double string")
|
||||
if type(bdbl) != type(BYTES):
|
||||
raise RuntimeError("Wrong type output for string")
|
||||
bout = python_strict_unicode.same_str(test_bytes)
|
||||
if bout != test_bytes:
|
||||
raise RuntimeError("Failed to copy char*")
|
||||
if type(bout) != type(BYTES):
|
||||
raise RuntimeError("Wrong type output for char*")
|
||||
|
||||
# Test that unicode string inputs and outputs work as expected
|
||||
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''):
|
||||
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''):
|
||||
raise RuntimeError("Wrong type output for wchar_t*")
|
||||
|
||||
# Test that overloading is handled properly
|
||||
bovr = python_strict_unicode.overload(test_bytes)
|
||||
if bovr != BYTES:
|
||||
raise RuntimeError("Failed to return bytes from overload")
|
||||
if type(bovr) != type(BYTES):
|
||||
raise RuntimeError("Wrong type output from overload")
|
||||
uovr = python_strict_unicode.overload(test_unicode)
|
||||
if uovr != u'UNICODE':
|
||||
raise RuntimeError("Failed to return unicode from overload")
|
||||
if type(uovr) != type(u''):
|
||||
raise RuntimeERror("Wrong type output from overload")
|
||||
|
||||
# Test that bytes aren't accepted as wide strings and unicode isn't accepted as narrow strings
|
||||
try:
|
||||
python_strict_unicode.double_str(test_unicode)
|
||||
error = 1
|
||||
except TypeError:
|
||||
error = 0
|
||||
if error:
|
||||
raise RuntimeError("Unicode accepted for string")
|
||||
try:
|
||||
python_strict_unicode.same_str(test_unicode)
|
||||
error = 1
|
||||
except TypeError:
|
||||
error = 0
|
||||
if error:
|
||||
raise RuntimeError("Unicode accepted for char*")
|
||||
try:
|
||||
python_strict_unicode.double_wstr(test_bytes)
|
||||
error = 1
|
||||
except TypeError:
|
||||
error = 0
|
||||
if error:
|
||||
raise RuntimeError("Bytes accepted for wstring")
|
||||
try:
|
||||
python_strict_unicode.same_wstr(test_bytes)
|
||||
error = 1
|
||||
except TypeError:
|
||||
error = 0
|
||||
if error:
|
||||
raise RuntimeError("Bytes accepted for wchar_t*")
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
from rename_rstrip_encoder import *
|
||||
|
||||
s = SomeThing()
|
||||
a = AnotherThing()
|
||||
a.DoClsX()
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
from template_default_arg_overloaded_extend import *
|
||||
|
||||
def check(flag):
|
||||
if not flag:
|
||||
raise RuntimeError("failed")
|
||||
|
||||
rs = ResultSet()
|
||||
|
||||
check(rs.go_get_method(0, SearchPoint()) == -1)
|
||||
check(rs.go_get_method(0, SearchPoint(), 100) == 100)
|
||||
|
||||
check(rs.go_get_template(0, SearchPoint()) == -2)
|
||||
check(rs.go_get_template(0, SearchPoint(), 100) == 100)
|
||||
|
||||
check(rs.over() == "over(int)")
|
||||
check(rs.over(10) == "over(int)")
|
||||
check(rs.over(SearchPoint()) == "over(giai2::SearchPoint, int)")
|
||||
check(rs.over(SearchPoint(), 10) == "over(giai2::SearchPoint, int)")
|
||||
check(rs.over(True, SearchPoint()) == "over(bool, gaia2::SearchPoint, int)")
|
||||
check(rs.over(True, SearchPoint(), 10) == "over(bool, gaia2::SearchPoint, int)")
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
from template_default_arg_overloaded import *
|
||||
|
||||
def check(expected, got):
|
||||
if expected != got:
|
||||
raise RuntimeError("Expected: " + str(expected) + " got: " + str(got))
|
||||
|
||||
|
||||
pl = PropertyList()
|
||||
check(1, pl.setInt("int", 10))
|
||||
check(1, pl.setInt("int", 10, False))
|
||||
|
||||
check(2, pl.set("int", pl))
|
||||
check(2, pl.set("int", pl, False))
|
||||
|
||||
check(3, pl.setInt("int", 10, "int"))
|
||||
check(3, pl.setInt("int", 10, "int", False))
|
||||
|
||||
|
||||
pl = PropertyListGlobal()
|
||||
check(1, pl.setIntGlobal("int", 10))
|
||||
check(1, pl.setIntGlobal("int", 10, False))
|
||||
|
||||
check(2, pl.set("int", pl))
|
||||
check(2, pl.set("int", pl, False))
|
||||
|
||||
check(3, pl.setIntGlobal("int", 10, "int"))
|
||||
check(3, pl.setIntGlobal("int", 10, "int", False))
|
||||
|
||||
|
||||
check(1, GoopIntGlobal(10))
|
||||
check(1, GoopIntGlobal(10, True))
|
||||
|
||||
check(2, goopGlobal(3))
|
||||
check(2, goopGlobal())
|
||||
|
||||
check(3, GoopIntGlobal("int", False))
|
||||
check(3, GoopIntGlobal("int"))
|
||||
|
||||
|
||||
check(1, GoopInt(10))
|
||||
check(1, GoopInt(10, True))
|
||||
|
||||
check(2, goop(3))
|
||||
check(2, goop())
|
||||
|
||||
check(3, GoopInt("int", False))
|
||||
check(3, GoopInt("int"))
|
||||
20
Examples/test-suite/python/typemap_documentation_runme.py
Normal file
20
Examples/test-suite/python/typemap_documentation_runme.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import typemap_documentation
|
||||
|
||||
f = typemap_documentation.Foo()
|
||||
f.x = 55
|
||||
b = typemap_documentation.Bar()
|
||||
b.y = 44
|
||||
|
||||
if 55 != typemap_documentation.GrabVal(f):
|
||||
raise RuntimeError("bad value")
|
||||
|
||||
try:
|
||||
typemap_documentation.GrabVal(b)
|
||||
raise RuntimeError("unexpected exception")
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
if 55 != typemap_documentation.GrabValFooBar(f):
|
||||
raise RuntimeError("bad f value")
|
||||
if 44 != typemap_documentation.GrabValFooBar(b):
|
||||
raise RuntimeError("bad b value")
|
||||
|
|
@ -12,3 +12,16 @@ if sys.version_info[0:2] >= (3, 1):
|
|||
raise ValueError('Test comparison mismatch')
|
||||
if unicode_strings.non_utf8_std_string() != test_string:
|
||||
raise ValueError('Test comparison mismatch')
|
||||
|
||||
def check(s1, s2):
|
||||
if s1 != s2:
|
||||
raise RuntimeError("{} != {}".format(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):
|
||||
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")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue