]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/python/test/list.py
1 # Copyright David Abrahams 2004. Distributed under the Boost
2 # Software License, Version 1.0. (See accompanying
3 # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
4 from __future__
import print_function
6 >>> from list_ext import *
14 >>> letters = listify_string('hello')
16 ['h', 'e', 'l', 'l', 'o']
23 >>> assert apply_object_list(identity, letters) is letters
25 5 is not convertible to a list
27 >>> try: result = apply_object_list(identity, 5)
28 ... except TypeError: pass
29 ... else: print('expected an exception, got', result, 'instead')
31 >>> assert apply_list_list(identity, letters) is letters
33 5 is not convertible to a list as a return value
35 >>> try: result = apply_list_list(len, letters)
36 ... except TypeError: pass
37 ... else: print('expected an exception, got', result, 'instead')
39 >>> append_object(letters, '.')
41 ['h', 'e', 'l', 'l', 'o', '.']
43 tuples do not automatically convert to lists when passed as arguments
45 >>> try: append_list(letters, (1,2))
46 ... except TypeError: pass
47 ... else: print('expected an exception')
49 >>> append_list(letters, [1,2])
51 ['h', 'e', 'l', 'l', 'o', '.', [1, 2]]
53 Check that subclass functions are properly called
55 >>> class mylist(list):
56 ... def append(self, o):
57 ... list.append(self, o)
58 ... if not hasattr(self, 'nappends'):
61 ... self.nappends += 1
64 >>> append_object(l2, 'hello')
65 >>> append_object(l2, 'world')
71 >>> def printer(*args):
72 ... for x in args: print( x,)
77 >>> exercise(letters, y, printer) #doctest: +NORMALIZE_WHITESPACE
79 ['h', 'e', 'l', 'l', 'o', '.', [1, 2], X(42), 5, X(3)]
80 number of X(42) instances: 1
83 ['h', 'e', 'l', 'l', 'o', '.', [1, 2], X(42), 5, X(3), 'x', 'y', 'z']
87 ['h', 'e', 'l', 'l', 666, 'o', '.', [1, 2], X(42), 5, X(3), 'x', 'y', 'z']
88 inserting with object as index:
89 ['h', 'e', 'l', 'l', 666, '---', 'o', '.', [1, 2], X(42), 5, X(3), 'x', 'y', 'z']
91 ['h', 'e', 'l', 'l', 666, '---', 'o', '.', [1, 2], X(42), 5, X(3), 'x', 'y']
92 ['h', 'e', 'l', 'l', 666, 'o', '.', [1, 2], X(42), 5, X(3), 'x', 'y']
93 ['h', 'e', 'l', 'l', 666, 'o', '.', [1, 2], X(42), X(3), 'x', 'y']
95 ['h', 'e', 'l', 'l', 666, 'o', '.', [1, 2], X(3), 'x', 'y']
97 ['h', 'e', 'l', 'l', 'o', '.', [1, 2], X(3), 'x', 'y']
99 ['y', 'x', X(3), [1, 2], '.', 'o', 'l', 'l', 'e', 'h']
101 ['.', 'e', 'h', 'l', 'l', 'o', 'x', 'y']
103 ['y', 'x', 'o', 'l', 'l', 'h', 'e', '.']
106 def run(args
= None):
112 return doctest
.testmod(sys
.modules
.get(__name__
))
114 if __name__
== '__main__':
118 if (status
== 0): print("Done.")