test_numpy_config.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. """
  2. Check the numpy config is valid.
  3. """
  4. from unittest.mock import patch
  5. import pytest
  6. import numpy as np
  7. pytestmark = pytest.mark.skipif(
  8. not hasattr(np.__config__, "_built_with_meson"),
  9. reason="Requires Meson builds",
  10. )
  11. class TestNumPyConfigs:
  12. REQUIRED_CONFIG_KEYS = [
  13. "Compilers",
  14. "Machine Information",
  15. "Python Information",
  16. ]
  17. @patch("numpy.__config__._check_pyyaml")
  18. @pytest.mark.thread_unsafe(reason="unittest.mock.patch updates global state")
  19. def test_pyyaml_not_found(self, mock_yaml_importer):
  20. mock_yaml_importer.side_effect = ModuleNotFoundError()
  21. with pytest.warns(UserWarning):
  22. np.show_config()
  23. def test_dict_mode(self):
  24. config = np.show_config(mode="dicts")
  25. assert isinstance(config, dict)
  26. assert all(key in config for key in self.REQUIRED_CONFIG_KEYS), (
  27. "Required key missing,"
  28. " see index of `False` with `REQUIRED_CONFIG_KEYS`"
  29. )
  30. def test_invalid_mode(self):
  31. with pytest.raises(AttributeError):
  32. np.show_config(mode="foo")
  33. def test_warn_to_add_tests(self):
  34. assert len(np.__config__.DisplayModes) == 2, (
  35. "New mode detected,"
  36. " please add UT if applicable and increment this count"
  37. )