From afc915f490ffbfff27d2a8597e07b57e86082ee1 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 28 Feb 2022 19:40:35 +0000 Subject: [PATCH] Turn on Python annotations testing again Testing is skipped where there is no support for it, that is, using -builtin or -fastproxy. How to add this support in needs determining, it's not clear how to do so. --- .../python/python_annotations_c_runme.py | 41 ++++++++++--------- Examples/test-suite/python_annotations_c.i | 14 +++++++ 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/Examples/test-suite/python/python_annotations_c_runme.py b/Examples/test-suite/python/python_annotations_c_runme.py index c69105ca1..3110d8f83 100644 --- a/Examples/test-suite/python/python_annotations_c_runme.py +++ b/Examples/test-suite/python/python_annotations_c_runme.py @@ -1,28 +1,31 @@ import sys -# Disable as no __annotations__ support with -fastproxy and -builtin atm -if False: # sys.version_info[0:2] >= (3, 2): +if sys.version_info[0:2] >= (3, 2): from python_annotations_c import * - anno = MakeShort.__annotations__ - if anno != {'x': 'int', 'return': 'Space::Template< short >'}: - raise RuntimeError("annotations mismatch: {}".format(anno)) + # No __annotations__ support with -builtin or -fastproxy + annotations_supported = not(is_python_builtin() or is_python_fastproxy()) - anno = global_ints.__annotations__ - if anno != {'ri': 'int &', 't': 'TemplateShort', 'return': 'int *'}: - raise RuntimeError("annotations mismatch: {}".format(anno)) + if annotations_supported: + anno = MakeShort.__annotations__ + if anno != {'x': 'int', 'return': 'Space::Template< short >'}: + raise RuntimeError("annotations mismatch: {}".format(anno)) - ts = MakeShort(10) + anno = global_ints.__annotations__ + if anno != {'ri': 'int &', 't': 'TemplateShort', 'return': 'int *'}: + raise RuntimeError("annotations mismatch: {}".format(anno)) - anno = MakeShort.__annotations__ - if anno != {'x': 'int', 'return': 'Space::Template< short >'}: - raise RuntimeError("annotations mismatch: {}".format(anno)) + ts = MakeShort(10) - anno = ts.mymethod.__annotations__ - if anno != {'arg2': 'int', 'tt': 'TemplateShort', 'return': 'void'}: - raise RuntimeError("annotations mismatch: {}".format(anno)) + anno = MakeShort.__annotations__ + if anno != {'x': 'int', 'return': 'Space::Template< short >'}: + raise RuntimeError("annotations mismatch: {}".format(anno)) - # No annotations - anno = no_annotations.__annotations__ - if anno != {}: - 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_annotations_c.i b/Examples/test-suite/python_annotations_c.i index dc590d6f5..8ecf4c6b0 100644 --- a/Examples/test-suite/python_annotations_c.i +++ b/Examples/test-suite/python_annotations_c.i @@ -24,3 +24,17 @@ int *no_annotations(int &ri, const char *c) { return NULL; } %} %template(TemplateShort) Space::Template; %template(MakeShort) makeT; + +%inline %{ +#ifdef SWIGPYTHON_BUILTIN +int is_python_builtin() { return 1; } +#else +int is_python_builtin() { return 0; } +#endif + +#if defined SWIGPYTHON_FASTPROXY +int is_python_fastproxy() { return 1; } +#else +int is_python_fastproxy() { return 0; } +#endif +%}