File size: 1,182 Bytes
059cd4a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
#!/usr/bin/env python
#
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
# Copyright (c) 2008-2016 California Institute of Technology.
# Copyright (c) 2016-2024 The Uncertainty Quantification Foundation.
# License: 3-clause BSD. The full license text is available at:
# - https://github.com/uqfoundation/dill/blob/master/LICENSE
import dill
dill.settings['recurse'] = True
def f(func):
def w(*args):
return f(*args)
return w
@f
def f2(): pass
# check when __main__ and on import
def test_decorated():
assert dill.pickles(f2)
import doctest
import logging
logging.basicConfig(level=logging.DEBUG)
class SomeUnreferencedUnpicklableClass(object):
def __reduce__(self):
raise Exception
unpicklable = SomeUnreferencedUnpicklableClass()
# This works fine outside of Doctest:
def test_normal():
serialized = dill.dumps(lambda x: x)
# should not try to pickle unpicklable object in __globals__
def tests():
"""
>>> serialized = dill.dumps(lambda x: x)
"""
return
#print("\n\nRunning Doctest:")
def test_doctest():
doctest.testmod()
if __name__ == '__main__':
test_decorated()
test_normal()
test_doctest()
|