1# -*- coding: utf-8 -*- 2# Copyright Gottfried Ganßauge 2003..2006. Distributed under the Boost 3# Software License, Version 1.0. (See accompanying 4# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 6 7""" 8>>> from opaque_ext import * 9 10 11 Check for correct conversion 12 13>>> use(get()) 14 15 Check that None is converted to a NULL opaque pointer 16 17>>> useany(get()) 181 19>>> useany(None) 200 21 22 Check that we don't lose type information by converting NULL 23 opaque pointers to None 24 25>>> assert getnull() is None 26>>> useany(getnull()) 270 28 29>>> failuse(get()) 30Traceback (most recent call last): 31 ... 32RuntimeError: success 33 34 Check that there is no conversion from integers ... 35 36>>> try: use(0) 37... except TypeError: pass 38... else: print('expected a TypeError') 39 40 ... and from strings to opaque objects 41 42>>> try: use("") 43... except TypeError: pass 44... else: print('expected a TypeError') 45 46 Now check the same for another opaque pointer type 47 48>>> use2(get2()) 49>>> failuse2(get2()) 50Traceback (most recent call last): 51 ... 52RuntimeError: success 53>>> try: use2(0) 54... except TypeError: pass 55... else: print('expected a TypeError') 56>>> try: use2("") 57... except TypeError: pass 58... else: print('expected a TypeError') 59 60 Check that opaque types are distinct 61 62>>> try: use(get2()) 63... except TypeError: pass 64... else: print('expected a TypeError') 65>>> try: use2(get()) 66... except TypeError: pass 67... else: print('expected a TypeError') 68 69 This used to result in a segmentation violation 70 71>>> type(get()) != type (get2()) 721 73""" 74def run(args = None): 75 import sys 76 import doctest 77 78 if args is not None: 79 sys.argv = args 80 return doctest.testmod(sys.modules.get(__name__)) 81 82if __name__ == '__main__': 83 print("running...") 84 import sys 85 status = run()[0] 86 if (status == 0): print("Done.") 87 sys.exit(status) 88