test_check.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. from dill import check
  9. import sys
  10. from dill.temp import capture
  11. #FIXME: this doesn't catch output... it's from the internal call
  12. def raise_check(func, **kwds):
  13. try:
  14. with capture('stdout') as out:
  15. check(func, **kwds)
  16. except Exception:
  17. e = sys.exc_info()[1]
  18. raise AssertionError(str(e))
  19. else:
  20. assert 'Traceback' not in out.getvalue()
  21. finally:
  22. out.close()
  23. f = lambda x:x**2
  24. def test_simple(verbose=None):
  25. raise_check(f, verbose=verbose)
  26. def test_recurse(verbose=None):
  27. raise_check(f, recurse=True, verbose=verbose)
  28. def test_byref(verbose=None):
  29. raise_check(f, byref=True, verbose=verbose)
  30. def test_protocol(verbose=None):
  31. raise_check(f, protocol=True, verbose=verbose)
  32. def test_python(verbose=None):
  33. raise_check(f, python=None, verbose=verbose)
  34. #TODO: test incompatible versions
  35. #TODO: test dump failure
  36. #TODO: test load failure
  37. if __name__ == '__main__':
  38. test_simple()
  39. test_recurse()
  40. test_byref()
  41. test_protocol()
  42. test_python()