Skip to content

Commit f883969

Browse files
committed
BUG: Fix test_impossible_feature_enable failing without BASELINE_FEAT
If the build has no baseline features set, the test ended up setting e.g. NPY_ENABLE_CPU_FEATURES="ASIMDHP, None". This actually made the execution succeed, as the warning for decoding "None" overrode the error for the real feature. Fix the error handling there by removing the errorneous "return 0;", add a test for this, and avoid passing "None" by accident.
1 parent e1bf1d6 commit f883969

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

numpy/_core/src/common/npy_cpu_features.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,6 @@ npy__cpu_check_env(int disable, const char *env) {
325325
) < 0) {
326326
return -1;
327327
}
328-
return 0;
329328
}
330329

331330
#define NOTSUPP_BODY \

numpy/_core/tests/test_cpu_features.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,15 +311,25 @@ def test_impossible_feature_enable(self):
311311
err_type = "RuntimeError"
312312
self._expect_error(msg, err_type)
313313

314-
# Ensure that only the bad feature gets reported
315-
feats = f"{bad_feature}, {self.BASELINE_FEAT}"
314+
# Ensure that it fails even when providing garbage in addition
315+
feats = f"{bad_feature}, Foobar"
316316
self.env['NPY_ENABLE_CPU_FEATURES'] = feats
317317
msg = (
318318
f"You cannot enable CPU features \\({bad_feature}\\), since they "
319319
"are not supported by your machine."
320320
)
321321
self._expect_error(msg, err_type)
322322

323+
if self.BASELINE_FEAT is not None:
324+
# Ensure that only the bad feature gets reported
325+
feats = f"{bad_feature}, {self.BASELINE_FEAT}"
326+
self.env['NPY_ENABLE_CPU_FEATURES'] = feats
327+
msg = (
328+
f"You cannot enable CPU features \\({bad_feature}\\), since "
329+
"they are not supported by your machine."
330+
)
331+
self._expect_error(msg, err_type)
332+
323333
is_linux = sys.platform.startswith('linux')
324334
is_cygwin = sys.platform.startswith('cygwin')
325335
machine = platform.machine()

0 commit comments

Comments
 (0)