test_functors.py 930 B

123456789101112131415161718192021222324252627282930313233343536373839
  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 functools
  9. import dill
  10. dill.settings['recurse'] = True
  11. def f(a, b, c): # without keywords
  12. pass
  13. def g(a, b, c=2): # with keywords
  14. pass
  15. def h(a=1, b=2, c=3): # without args
  16. pass
  17. def test_functools():
  18. fp = functools.partial(f, 1, 2)
  19. gp = functools.partial(g, 1, c=2)
  20. hp = functools.partial(h, 1, c=2)
  21. bp = functools.partial(int, base=2)
  22. assert dill.pickles(fp, safe=True)
  23. assert dill.pickles(gp, safe=True)
  24. assert dill.pickles(hp, safe=True)
  25. assert dill.pickles(bp, safe=True)
  26. if __name__ == '__main__':
  27. test_functools()