Skip to content

Commit 233cfc0

Browse files
Jammy2211claude
andcommitted
fix(inversion): review findings (#566)
Move the no-module-level-jax import guard into its own test module: the module-level skip in test_jax_active_set.py (applied when jax is absent) also skipped the guard, contradicting its comment, so the guard never ran on the NumPy-only env it exists for. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 8fe4343 commit 233cfc0

2 files changed

Lines changed: 28 additions & 22 deletions

File tree

‎test_autoarray/util/test_jax_active_set.py‎

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,13 @@
1515
"""
1616

1717
import importlib
18-
import sys
1918

2019
import numpy as np
2120
import pytest
2221

2322

24-
def test__jax_active_set_module_never_imports_jax_at_module_level(monkeypatch):
25-
# Library unit tests are NumPy-only: importing the module must succeed even when jax is
26-
# unimportable. A None entry in sys.modules makes any `import jax` raise ImportError, so a
27-
# module-level import would fail this reload.
28-
monkeypatch.setitem(sys.modules, "jax", None)
29-
monkeypatch.setitem(sys.modules, "jaxnnls", None)
30-
31-
module = importlib.reload(importlib.import_module("autoarray.util.jax_active_set"))
32-
33-
for name in (
34-
"masked_solve",
35-
"certify",
36-
"active_set_search",
37-
"solve_certified",
38-
"solve_certified_with_fallback",
39-
):
40-
assert hasattr(module, name)
41-
42-
43-
# jax is an `[optional]` extra and is absent on the NumPy-only matrix env: every test below the import test
44-
# skips there, while the import test above still runs.
23+
# jax is an `[optional]` extra and is absent on the NumPy-only matrix env: every test in this module skips
24+
# there. The no-module-level-jax-import guard lives in `test_jax_active_set_import.py` so it still runs.
4525
if importlib.util.find_spec("jax") is None:
4626
pytestmark = pytest.mark.skip(reason="requires jax (the [optional] extras)")
4727

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
Import guard for `autoarray.util.jax_active_set`, kept apart from `test_jax_active_set.py` because that module
3+
skips wholesale when jax is absent, and this test must run exactly there.
4+
"""
5+
6+
import importlib
7+
import sys
8+
9+
10+
def test__jax_active_set_module_never_imports_jax_at_module_level(monkeypatch):
11+
# Library unit tests are NumPy-only: importing the module must succeed even when jax is
12+
# unimportable. A None entry in sys.modules makes any `import jax` raise ImportError, so a
13+
# module-level import would fail this reload.
14+
monkeypatch.setitem(sys.modules, "jax", None)
15+
monkeypatch.setitem(sys.modules, "jaxnnls", None)
16+
17+
module = importlib.reload(importlib.import_module("autoarray.util.jax_active_set"))
18+
19+
for name in (
20+
"masked_solve",
21+
"certify",
22+
"active_set_search",
23+
"solve_certified",
24+
"solve_certified_with_fallback",
25+
):
26+
assert hasattr(module, name)

0 commit comments

Comments
 (0)