1
0

test_reloading.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from __future__ import division, absolute_import, print_function
  2. import sys
  3. from numpy.testing import assert_raises, assert_, assert_equal
  4. from numpy.compat import pickle
  5. if sys.version_info[:2] >= (3, 4):
  6. from importlib import reload
  7. else:
  8. from imp import reload
  9. def test_numpy_reloading():
  10. # gh-7844. Also check that relevant globals retain their identity.
  11. import numpy as np
  12. import numpy._globals
  13. _NoValue = np._NoValue
  14. VisibleDeprecationWarning = np.VisibleDeprecationWarning
  15. ModuleDeprecationWarning = np.ModuleDeprecationWarning
  16. reload(np)
  17. assert_(_NoValue is np._NoValue)
  18. assert_(ModuleDeprecationWarning is np.ModuleDeprecationWarning)
  19. assert_(VisibleDeprecationWarning is np.VisibleDeprecationWarning)
  20. assert_raises(RuntimeError, reload, numpy._globals)
  21. reload(np)
  22. assert_(_NoValue is np._NoValue)
  23. assert_(ModuleDeprecationWarning is np.ModuleDeprecationWarning)
  24. assert_(VisibleDeprecationWarning is np.VisibleDeprecationWarning)
  25. def test_novalue():
  26. import numpy as np
  27. for proto in range(2, pickle.HIGHEST_PROTOCOL + 1):
  28. assert_equal(repr(np._NoValue), '<no value>')
  29. assert_(pickle.loads(pickle.dumps(np._NoValue,
  30. protocol=proto)) is np._NoValue)