test_deprecated_objects.py 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. """
  2. Tests making sure that deprecated objects properly raise a deprecation warning
  3. when imported/created.
  4. """
  5. import sys
  6. import pytest
  7. from joblib.my_exceptions import _deprecated_names as _deprecated_exceptions
  8. from joblib.format_stack import _deprecated_names as _deprecated_format_utils
  9. @pytest.mark.xfail(sys.version_info < (3, 7), reason="no module-level getattr")
  10. def test_deprecated_joblib_exceptions():
  11. assert 'JoblibException' in _deprecated_exceptions
  12. for name in _deprecated_exceptions:
  13. msg = ('{} is deprecated and will be removed from joblib in '
  14. '0.16'.format(name))
  15. with pytest.warns(DeprecationWarning, match=msg):
  16. exec('from joblib.my_exceptions import {}'.format(name))
  17. @pytest.mark.xfail(sys.version_info < (3, 7), reason="no module-level getattr")
  18. def test_deprecated_formatting_utilities(capsys):
  19. assert 'safe_repr' in _deprecated_format_utils
  20. assert 'eq_repr' in _deprecated_format_utils
  21. for name in _deprecated_format_utils:
  22. msg = ('{} is deprecated and will be removed from joblib in '
  23. '0.16'.format(name))
  24. with pytest.warns(DeprecationWarning, match=msg):
  25. exec('from joblib.format_stack import {}'.format(name))