test_moduledict.py 1.2 KB

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