diff options
author | Ganesh Kathiresan <ganesh3597@gmail.com> | 2023-01-24 15:49:43 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-24 11:19:43 +0100 |
commit | 04823c1a95e23c55432a78c7c7414c040279c2e1 (patch) | |
tree | f5a885b5fe175131cefe770213c9d9eab95f054c /numpy/tests | |
parent | 172a1942893b5ce55abccd836fdd9f00235a6767 (diff) | |
download | numpy-04823c1a95e23c55432a78c7c7414c040279c2e1.tar.gz |
BLD: Meson `__config__` generation (#22769)
Add functionality to autogenerate build information for a Meson-based build.
In order to add new information, do the following:
- Add the information as an argument in `numpy/meson.build`
- Modify `__config__.py.in` to accept the new argument
Note that SIMD information is added to config, but is WIP/empty,
because `__cpu*` lists are not yet populated as meson does not build
SIMD features yet.
There are two display modes:
- `stdout`: Uses `PyYaml` to display in a human friendly
format. Uses `json` if `PyYaml` is not installed
- `dicts`: Returns a `dict` object
Things will work fine without `pyyaml` installed, an unobtrusive
warning is displayed that the printed output will look better
with `pyyaml`.
[ci skip]
Diffstat (limited to 'numpy/tests')
-rw-r--r-- | numpy/tests/test_numpy_config.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/numpy/tests/test_numpy_config.py b/numpy/tests/test_numpy_config.py new file mode 100644 index 000000000..82c1ad70b --- /dev/null +++ b/numpy/tests/test_numpy_config.py @@ -0,0 +1,44 @@ +""" +Check the numpy config is valid. +""" +import numpy as np +import pytest +from unittest.mock import Mock, patch + +pytestmark = pytest.mark.skipif( + not hasattr(np.__config__, "_built_with_meson"), + reason="Requires Meson builds", +) + + +class TestNumPyConfigs: + REQUIRED_CONFIG_KEYS = [ + "Compilers", + "Machine Information", + "Python Information", + ] + + @patch("numpy.__config__._check_pyyaml") + def test_pyyaml_not_found(self, mock_yaml_importer): + mock_yaml_importer.side_effect = ModuleNotFoundError() + with pytest.warns(UserWarning): + np.show_config() + + def test_dict_mode(self): + config = np.show_config(mode="dicts") + + assert isinstance(config, dict) + assert all([key in config for key in self.REQUIRED_CONFIG_KEYS]), ( + "Required key missing," + " see index of `False` with `REQUIRED_CONFIG_KEYS`" + ) + + def test_invalid_mode(self): + with pytest.raises(AttributeError): + np.show_config(mode="foo") + + def test_warn_to_add_tests(self): + assert len(np.__config__.DisplayModes) == 2, ( + "New mode detected," + " please add UT if applicable and increment this count" + ) |