diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2023-04-05 20:21:34 +0100 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2023-04-26 18:18:15 +0100 |
commit | b2fd91bc41050ec4dd8fbb13b71abb796bc6c8b7 (patch) | |
tree | 9c81d693d53c46a44a1afa59fc527df18556f535 /Examples/test-suite/python/cpp11_std_array_runme.py | |
parent | 6098b26f3ece2096e14695fd02b040bd0658d2ac (diff) | |
download | swig-b2fd91bc41050ec4dd8fbb13b71abb796bc6c8b7.tar.gz |
Add support for all STL containers to be constructible from a Python set
Diffstat (limited to 'Examples/test-suite/python/cpp11_std_array_runme.py')
-rw-r--r-- | Examples/test-suite/python/cpp11_std_array_runme.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/Examples/test-suite/python/cpp11_std_array_runme.py b/Examples/test-suite/python/cpp11_std_array_runme.py index 9e11a3e5b..dbf9bcee3 100644 --- a/Examples/test-suite/python/cpp11_std_array_runme.py +++ b/Examples/test-suite/python/cpp11_std_array_runme.py @@ -56,6 +56,14 @@ def setslice_exception(swigarray, newval): # 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 + # Check std::array has similar behaviour to a Python list # except it is not resizable @@ -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)) |