]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/python/test/map_indexing_suite.py
1 # Copyright Joel de Guzman 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)
6 #####################################################################
7 # Check an object that we will use as container element
8 #####################################################################
10 >>> from map_indexing_suite_ext import *
11 >>> assert "map_indexing_suite_IntMap_entry" in dir()
12 >>> assert "map_indexing_suite_TestMap_entry" in dir()
13 >>> assert "map_indexing_suite_XMap_entry" in dir()
14 >>> assert "map_indexing_suite_AMap_entry" in dir()
18 >>> x.reset() # a member function that modifies X
21 >>> x.foo() # another member function that modifies X
25 # test that a string is implicitly convertible
27 >>> x_value('bochi bochi')
30 #####################################################################
32 #####################################################################
33 >>> def print_xmap(xmap):
41 #####################################################################
42 # Setting (adding entries)
43 #####################################################################
45 >>> xm['joel'] = 'apple'
46 >>> xm['tenji'] = 'orange'
47 >>> xm['mariel'] = 'grape'
48 >>> xm['tutit'] = 'banana'
49 >>> xm['kim'] = 'kiwi'
52 [ (joel, apple) (kim, kiwi) (mariel, grape) (tenji, orange) (tutit, banana) ]
54 #####################################################################
56 #####################################################################
57 >>> xm['joel'] = 'pineapple'
59 [ (joel, pineapple) (kim, kiwi) (mariel, grape) (tenji, orange) (tutit, banana) ]
61 #####################################################################
63 #####################################################################
66 [ (kim, kiwi) (mariel, grape) (tenji, orange) (tutit, banana) ]
68 #####################################################################
70 #####################################################################
71 >>> xm['joel'] = 'apple'
73 [ (joel, apple) (kim, kiwi) (mariel, grape) (tenji, orange) (tutit, banana) ]
75 #####################################################################
77 #####################################################################
91 #####################################################################
92 # Calling a mutating function of a container element
93 #####################################################################
94 >>> xm['joel'].reset()
98 #####################################################################
99 # Copying a container element
100 #####################################################################
101 >>> x = X(xm['mariel'])
107 >>> xm['mariel'] # should not be changed to 'foo'
110 #####################################################################
111 # Referencing a container element
112 #####################################################################
119 >>> xm['mariel'] # should be changed to 'foo'
122 >>> xm['mariel'] = 'grape' # take it back
123 >>> xm['joel'] = 'apple' # take it back
125 #####################################################################
127 #####################################################################
128 >>> assert 'joel' in xm
129 >>> assert 'mariel' in xm
130 >>> assert 'tenji' in xm
131 >>> assert 'tutit' in xm
132 >>> assert 'kim' in xm
133 >>> assert not 'X' in xm
134 >>> assert not 12345 in xm
136 #####################################################################
137 # Some references to the container elements
138 #####################################################################
141 >>> z1 = xm['mariel']
157 #####################################################################
158 # Delete some container element
159 #####################################################################
163 [ (joel, apple) (kim, kiwi) (mariel, grape) (tutit, banana) ]
167 [ (joel, apple) (kim, kiwi) (mariel, grape) ]
169 #####################################################################
170 # Show that the references are still valid
171 #####################################################################
176 >>> z2 # proxy detached
178 >>> z3 # proxy detached
183 #####################################################################
184 # Show that iteration allows mutable access to the elements
185 #####################################################################
189 [ (joel, reset) (kim, reset) (mariel, reset) ]
191 #####################################################################
193 #####################################################################
196 >>> tm["joel"] = X("aaa")
197 >>> tm["kimpo"] = X("bbb")
199 [ (joel, aaa) (kimpo, bbb) ]
200 >>> for el in tm: #doctest: +NORMALIZE_WHITESPACE
201 ... print(el.key(), end=' ')
205 #####################################################################
206 # Test custom converter...
207 #####################################################################
217 #####################################################################
219 #####################################################################
223 from __future__
import print_function
225 def run(args
= None):
231 return doctest
.testmod(sys
.modules
.get(__name__
))
233 if __name__
== '__main__':
237 if (status
== 0): print("Done.")