]>
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)
4 from __future__
import print_function
7 #####################################################################
8 # Check an object that we will use as container element
9 #####################################################################
11 >>> from map_indexing_suite_ext import *
12 >>> assert "map_indexing_suite_IntMap_entry" in dir()
13 >>> assert "map_indexing_suite_TestMap_entry" in dir()
14 >>> assert "map_indexing_suite_XMap_entry" in dir()
15 >>> assert "map_indexing_suite_AMap_entry" in dir()
19 >>> x.reset() # a member function that modifies X
22 >>> x.foo() # another member function that modifies X
26 # test that a string is implicitly convertible
28 >>> x_value('bochi bochi')
31 #####################################################################
33 #####################################################################
34 >>> def print_xmap(xmap):
42 #####################################################################
43 # Setting (adding entries)
44 #####################################################################
46 >>> xm['joel'] = 'apple'
47 >>> xm['tenji'] = 'orange'
48 >>> xm['mariel'] = 'grape'
49 >>> xm['tutit'] = 'banana'
50 >>> xm['kim'] = 'kiwi'
53 [ (joel, apple) (kim, kiwi) (mariel, grape) (tenji, orange) (tutit, banana) ]
55 #####################################################################
57 #####################################################################
58 >>> xm['joel'] = 'pineapple'
60 [ (joel, pineapple) (kim, kiwi) (mariel, grape) (tenji, orange) (tutit, banana) ]
62 #####################################################################
64 #####################################################################
67 [ (kim, kiwi) (mariel, grape) (tenji, orange) (tutit, banana) ]
69 #####################################################################
71 #####################################################################
72 >>> xm['joel'] = 'apple'
74 [ (joel, apple) (kim, kiwi) (mariel, grape) (tenji, orange) (tutit, banana) ]
76 #####################################################################
78 #####################################################################
92 #####################################################################
93 # Calling a mutating function of a container element
94 #####################################################################
95 >>> xm['joel'].reset()
99 #####################################################################
100 # Copying a container element
101 #####################################################################
102 >>> x = X(xm['mariel'])
108 >>> xm['mariel'] # should not be changed to 'foo'
111 #####################################################################
112 # Referencing a container element
113 #####################################################################
120 >>> xm['mariel'] # should be changed to 'foo'
123 >>> xm['mariel'] = 'grape' # take it back
124 >>> xm['joel'] = 'apple' # take it back
126 #####################################################################
128 #####################################################################
129 >>> assert 'joel' in xm
130 >>> assert 'mariel' in xm
131 >>> assert 'tenji' in xm
132 >>> assert 'tutit' in xm
133 >>> assert 'kim' in xm
134 >>> assert not 'X' in xm
135 >>> assert not 12345 in xm
137 #####################################################################
138 # Some references to the container elements
139 #####################################################################
142 >>> z1 = xm['mariel']
158 #####################################################################
159 # Delete some container element
160 #####################################################################
164 [ (joel, apple) (kim, kiwi) (mariel, grape) (tutit, banana) ]
168 [ (joel, apple) (kim, kiwi) (mariel, grape) ]
170 #####################################################################
171 # Show that the references are still valid
172 #####################################################################
177 >>> z2 # proxy detached
179 >>> z3 # proxy detached
184 #####################################################################
185 # Show that iteration allows mutable access to the elements
186 #####################################################################
190 [ (joel, reset) (kim, reset) (mariel, reset) ]
192 #####################################################################
194 #####################################################################
197 >>> tm["joel"] = X("aaa")
198 >>> tm["kimpo"] = X("bbb")
200 [ (joel, aaa) (kimpo, bbb) ]
201 >>> for el in tm: #doctest: +NORMALIZE_WHITESPACE
202 ... print(el.key(), end='')
206 #####################################################################
207 # Test custom converter...
208 #####################################################################
218 #####################################################################
220 #####################################################################
225 def run(args
= None):
231 return doctest
.testmod(sys
.modules
.get(__name__
))
233 if __name__
== '__main__':
237 if (status
== 0): print("Done.")