From 19fcec84d8d7d21e796c7624e521b60d28ee21ed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:45:59 +0200 Subject: Adding upstream version 16.2.11+ds. Signed-off-by: Daniel Baumann --- src/boost/libs/python/test/test_enum.py | 85 +++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 src/boost/libs/python/test/test_enum.py (limited to 'src/boost/libs/python/test/test_enum.py') diff --git a/src/boost/libs/python/test/test_enum.py b/src/boost/libs/python/test/test_enum.py new file mode 100644 index 000000000..e4ad70bd5 --- /dev/null +++ b/src/boost/libs/python/test/test_enum.py @@ -0,0 +1,85 @@ +# Copyright David Abrahams 2004. Distributed under the Boost +# Software License, Version 1.0. (See accompanying +# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +''' +>>> from enum_ext import * + +>>> identity(color.red) # in case of duplicated enums it always take the last enum +enum_ext.color.blood + +>>> identity(color.green) +enum_ext.color.green + +>>> identity(color.blue) +enum_ext.color.blue + +>>> identity(color(1)) # in case of duplicated enums it always take the last enum +enum_ext.color.blood + +>>> identity(color(2)) +enum_ext.color.green + +>>> identity(color(3)) +enum_ext.color(3) + +>>> identity(color(4)) +enum_ext.color.blue + + --- check export to scope --- + +>>> identity(red) +enum_ext.color.blood + +>>> identity(green) +enum_ext.color.green + +>>> identity(blue) +enum_ext.color.blue + +>>> try: identity(1) +... except TypeError: pass +... else: print('expected a TypeError') + +>>> c = colorized() +>>> c.x +enum_ext.color.blood +>>> c.x = green +>>> c.x +enum_ext.color.green +>>> red == blood +True +>>> red == green +False +>>> hash(red) == hash(blood) +True +>>> hash(red) == hash(green) +False +''' + +# pickling of enums only works with Python 2.3 or higher +exercise_pickling = ''' +>>> import pickle +>>> p = pickle.dumps(color.green, pickle.HIGHEST_PROTOCOL) +>>> l = pickle.loads(p) +>>> identity(l) +enum_ext.color.green +''' + +def run(args = None): + import sys + import doctest + import pickle + + if args is not None: + sys.argv = args + self = sys.modules.get(__name__) + if (hasattr(pickle, "HIGHEST_PROTOCOL")): + self.__doc__ += exercise_pickling + return doctest.testmod(self) + +if __name__ == '__main__': + print("running...") + import sys + status = run()[0] + if (status == 0): print("Done.") + sys.exit(status) -- cgit v1.2.3