test_config.py 1.2 KB

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