Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
test_numpy_config.py48 linesDownload Raw Back to tests
1"""
2Check the numpy config is valid.
3"""
4from unittest.mock import patch
5
6import pytest
7
8import numpy as np
9
10pytestmark = pytest.mark.skipif(
11    not hasattr(np.__config__, "_built_with_meson"),
12    reason="Requires Meson builds",
13)
14
15
16class TestNumPyConfigs:
17    REQUIRED_CONFIG_KEYS = [
18        "Compilers",
19        "Machine Information",
20        "Python Information",
21    ]
22
23    @patch("numpy.__config__._check_pyyaml")
24    @pytest.mark.thread_unsafe(reason="unittest.mock.patch updates global state")
25    def test_pyyaml_not_found(self, mock_yaml_importer):
26        mock_yaml_importer.side_effect = ModuleNotFoundError()
27        with pytest.warns(UserWarning):
28            np.show_config()
29
30    def test_dict_mode(self):
31        config = np.show_config(mode="dicts")
32
33        assert isinstance(config, dict)
34        assert all(key in config for key in self.REQUIRED_CONFIG_KEYS), (
35            "Required key missing,"
36            " see index of `False` with `REQUIRED_CONFIG_KEYS`"
37        )
38
39    def test_invalid_mode(self):
40        with pytest.raises(AttributeError):
41            np.show_config(mode="foo")
42
43    def test_warn_to_add_tests(self):
44        assert len(np.__config__.DisplayModes) == 2, (
45            "New mode detected,"
46            " please add UT if applicable and increment this count"
47        )
48 
codekingpro/portable-devtools · Team Ai