Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/python/test/pickle2.py @ 29

Last change on this file since 29 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 1.5 KB
Line 
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)
4r'''>>> import pickle2_ext
5    >>> import pickle
6    >>> pickle2_ext.world.__module__
7    'pickle2_ext'
8    >>> pickle2_ext.world.__safe_for_unpickling__
9    1
10    >>> pickle2_ext.world.__name__
11    'world'
12    >>> pickle2_ext.world('Hello').__reduce__()
13    (<class 'pickle2_ext.world'>, ('Hello',), (0,))
14    >>> for number in (24, 42):
15    ...   wd = pickle2_ext.world('California')
16    ...   wd.set_secret_number(number)
17    ...   pstr = pickle.dumps(wd)
18    ...   wl = pickle.loads(pstr)
19    ...   print wd.greet(), wd.get_secret_number()
20    ...   print wl.greet(), wl.get_secret_number()
21    Hello from California! 24
22    Hello from California! 24
23    Hello from California! 42
24    Hello from California! 0
25
26# Now show that the __dict__ is not taken care of.
27    >>> wd = pickle2_ext.world('California')
28    >>> wd.x = 1
29    >>> wd.__dict__
30    {'x': 1}
31    >>> try: pstr = pickle.dumps(wd)
32    ... except RuntimeError, err: print err[0]
33    ...
34    Incomplete pickle support (__getstate_manages_dict__ not set)
35'''
36
37def run(args = None):
38    import sys
39    import doctest
40
41    if args is not None:
42        sys.argv = args
43    return doctest.testmod(sys.modules.get(__name__))
44   
45if __name__ == '__main__':
46    print "running..."
47    import sys
48    status = run()[0]
49    if (status == 0): print "Done."
50    sys.exit(status)
Note: See TracBrowser for help on using the repository browser.