Coverage for nilearn/_utils/tests/test_common.py: 0%
21 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-20 10:58 +0200
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-20 10:58 +0200
1import numpy as np
2import pytest
4from nilearn._utils import all_classes, all_functions, all_modules
5from nilearn._utils.helpers import is_matplotlib_installed
8@pytest.mark.parametrize("func", [all_modules, all_functions, all_classes])
9def test_all_modules_error(func):
10 with pytest.raises(
11 ValueError,
12 match=(
13 "`modules_to_ignore` and "
14 "`modules_to_consider` cannot "
15 "be both specified."
16 ),
17 ):
18 func(modules_to_ignore=["foo"], modules_to_consider=["bar"])
21@pytest.mark.skipif(
22 not is_matplotlib_installed(),
23 reason="This test requires matplotlib to be installed.",
24)
25@pytest.mark.parametrize("func", [all_functions, all_classes])
26def test_private_vs_public(func):
27 public_only = set(func(return_private=False))
28 private_and_public = set(func(return_private=True))
29 assert public_only.issubset(private_and_public)
30 assert np.all(
31 [elt[0].startswith("_") for elt in private_and_public - public_only]
32 )
35@pytest.mark.skipif(
36 not is_matplotlib_installed(),
37 reason="This test requires matplotlib to be installed.",
38)
39def test_number_public_functions():
40 """Check that number of public functions is stable.
42 If it changes, it means that we have added or removed a public function.
43 If this is intentional, then the number should be updated in the test.
44 Otherwise it means that the public API of nilearn has changed by mistake.
45 """
46 assert len({_[0] for _ in all_functions()}) == 261
49@pytest.mark.skipif(
50 not is_matplotlib_installed(),
51 reason="This test requires matplotlib to be installed.",
52)
53def test_number_public_classes():
54 """Check that number of public classes is stable.
56 If it changes, it means that we have added or removed a public function.
57 If this is intentional, then the number should be updated in the test.
58 Otherwise it means that the public API of nilearn has changed by mistake.
59 """
60 assert len({_[0] for _ in all_classes()}) == 67