Skip to content

Commit f8bf8e7

Browse files
Jammy2211Jammy2211
andauthored
test: skip NSS tests without optional dependency (#1312)
Co-authored-by: Jammy2211 <JNightingale2211@gmail.com>
1 parent 990398b commit f8bf8e7

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

test_autofit/non_linear/search/nest/nss/test_checkpoint.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121

2222

2323
pytestmark = pytest.mark.filterwarnings("ignore::FutureWarning")
24+
requires_nss = pytest.mark.skipif(
25+
not nss_search_module._HAS_NSS,
26+
reason="requires optional `nss` extra",
27+
)
2428

2529

2630
jax = pytest.importorskip("jax")
@@ -119,6 +123,7 @@ def test__save_checkpoint_is_atomic(tmp_path):
119123
assert path.read_bytes() == good_blob
120124

121125

126+
@requires_nss
122127
def test__nss_checkpoint_path_is_none_for_null_paths():
123128
"""Without a real output dir (NullPaths), checkpoint resolution returns None.
124129
@@ -131,6 +136,7 @@ def test__nss_checkpoint_path_is_none_for_null_paths():
131136
assert search.checkpoint_file is None
132137

133138

139+
@requires_nss
134140
def test__init_accepts_checkpoint_interval():
135141
search = af.NSS(checkpoint_interval=25)
136142
assert search.checkpoint_interval == 25
@@ -139,6 +145,7 @@ def test__init_accepts_checkpoint_interval():
139145
assert default.checkpoint_interval == 100
140146

141147

148+
@requires_nss
142149
def test__init_iterations_per_quick_update_no_longer_warns(caplog):
143150
"""Phase 1's no-op log when the kwarg is set is gone in Phase 3 (the kwarg
144151
is now actually wired). The warning text must not appear.
@@ -151,6 +158,7 @@ def test__init_iterations_per_quick_update_no_longer_warns(caplog):
151158
)
152159

153160

161+
@requires_nss
154162
def test__load_checkpoint_called_when_file_exists(tmp_path):
155163
"""Verify ``_load_checkpoint`` is invoked from ``_fit`` when a checkpoint
156164
file exists at the resolved path.

test_autofit/non_linear/search/nest/nss/test_search.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@
1717

1818

1919
pytestmark = pytest.mark.filterwarnings("ignore::FutureWarning")
20+
requires_nss = pytest.mark.skipif(
21+
not nss_search_module._HAS_NSS,
22+
reason="requires optional `nss` extra",
23+
)
2024

2125

26+
@requires_nss
2227
def test__explicit_params():
2328
search = af.NSS(
2429
n_live=500,
@@ -70,6 +75,7 @@ def test__chunked_update_strategy_factory():
7075
]
7176

7277

78+
@requires_nss
7379
def test__chunked_nss_algorithm_factory():
7480
"""``build_chunked_nss_algorithm`` returns a ``blackjax.SamplingAlgorithm``-
7581
shape NamedTuple with ``init`` and ``step`` attributes. This is what
@@ -106,12 +112,14 @@ def test__chunked_nss_algorithm_factory():
106112
assert isinstance(algo_unchunked, blackjax.SamplingAlgorithm)
107113

108114

115+
@requires_nss
109116
def test__identifier_fields():
110117
search = af.NSS()
111118
for field in ("n_live", "num_mcmc_steps", "num_delete", "termination", "seed"):
112119
assert field in search.__identifier_fields__
113120

114121

122+
@requires_nss
115123
def test__test_mode_loosens_termination():
116124
search = af.NSS(termination=-3.0)
117125
search.apply_test_mode()
@@ -124,6 +132,7 @@ def test__init_raises_when_nss_unavailable(monkeypatch):
124132
af.NSS()
125133

126134

135+
@requires_nss
127136
def test__init_warns_when_number_of_cores_gt_one(caplog):
128137
with caplog.at_level("WARNING"):
129138
af.NSS(number_of_cores=4)
@@ -157,6 +166,7 @@ def _make_synthetic_internal(n_live=20, ndim=2, seed=0):
157166
)
158167

159168

169+
@requires_nss
160170
def test__samples_info_from_synthetic_internal():
161171
search = af.NSS()
162172
internal = _make_synthetic_internal()
@@ -178,6 +188,7 @@ def test__samples_info_from_synthetic_internal():
178188
assert info["sampling_time"] == pytest.approx(10.0, abs=1e-12)
179189

180190

191+
@requires_nss
181192
def test__samples_via_internal_from_returns_nssamples():
182193
model = af.Model(af.m.MockClassx2)
183194
model.one = af.UniformPrior(lower_limit=-3.0, upper_limit=3.0)
@@ -201,6 +212,7 @@ def test__samples_via_internal_from_returns_nssamples():
201212
)
202213

203214

215+
@requires_nss
204216
def test__samples_weight_normalisation_handles_zero_total():
205217
"""When every log_weight is -inf (e.g. catastrophic underflow) we should
206218
not divide by zero. The implementation clamps via max-subtraction so this
@@ -222,6 +234,7 @@ def test__samples_weight_normalisation_handles_zero_total():
222234
assert np.allclose(weights, 1.0 / 10, atol=1e-12)
223235

224236

237+
@requires_nss
225238
def test__nssamples_log_evidence_error_property():
226239
model = af.Model(af.m.MockClassx2)
227240
model.one = af.UniformPrior(lower_limit=-3.0, upper_limit=3.0)

0 commit comments

Comments
 (0)