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