Skip to content

Commit

Permalink
BUG: Fix test_impossible_feature_enable failing without BASELINE_FEAT
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Vogtinator committed Mar 28, 2024
1 parent e1bf1d6 commit f883969
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 0 additions & 1 deletion numpy/_core/src/common/npy_cpu_features.c
Expand Up @@ -325,7 +325,6 @@ npy__cpu_check_env(int disable, const char *env) {
) < 0) {
return -1;
}
return 0;
}

#define NOTSUPP_BODY \
Expand Down
14 changes: 12 additions & 2 deletions numpy/_core/tests/test_cpu_features.py
Expand Up @@ -311,15 +311,25 @@ def test_impossible_feature_enable(self):
err_type = "RuntimeError"
self._expect_error(msg, err_type)

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

if self.BASELINE_FEAT is not None:
# Ensure that only the bad feature gets reported
feats = f"{bad_feature}, {self.BASELINE_FEAT}"
self.env['NPY_ENABLE_CPU_FEATURES'] = feats
msg = (
f"You cannot enable CPU features \\({bad_feature}\\), since "
"they are not supported by your machine."
)
self._expect_error(msg, err_type)

is_linux = sys.platform.startswith('linux')
is_cygwin = sys.platform.startswith('cygwin')
machine = platform.machine()
Expand Down

0 comments on commit f883969

Please sign in to comment.