Skip to content

tests/test_amd_swizzle: skip the numpy tests without numpy instead of failing - #6686

Merged
shayderrr merged 1 commit into
ItsNotRexed:mainfrom
DeSunShine:amd-swizzle-numpy-skip
Nov 23, 2026
Merged

shayderrr merged 1 commit into
ItsNotRexed:mainfrom
DeSunShine:amd-swizzle-numpy-skip

Conversation

@DeSunShine

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: new TEST item, #6603 (comment)

Depends on: none. Touches the same file as #4951 (the __main__ block, a different part), whichever lands first.

What and why

tests/test_amd_swizzle.py handles a missing numpy at import (A = None, HAVE_NUMPY = False, lines 25-31), and its __main__ block skips the numpy tests. Under pytest, though, the nine module-level tests still ran. They called A.load / A.offsets on None, ran the numpy-importing CLI in a subprocess, or imported numpy directly. Without numpy, 7 of them fail with AttributeError: 'NoneType' / ModuleNotFoundError: numpy. CI installs numpy, so only a contributor's machine sees this. I found it on native Windows with Python 3.12 and 3.15.

The change adds a needs_numpy marker, pytest.mark.skipif(not HAVE_NUMPY), which is a no-op when pytest isn't importable. The module-level tests carry it. The AmdSwizzleCliGuardTests unittest class fakes numpy and keeps running. With numpy, nothing changes.

Tested

Windows 11, no numpy:

  • python -m pytest tests/test_amd_swizzle.py: was 7 failed. Now 4 passed, 10 skipped ("numpy is not installed"), on Python 3.12 and 3.15.
  • python -I tests/test_amd_swizzle.py: OK (4 tests).

No GPU involved.

AI-assisted: yes (Claude Code)

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

… failing

Without numpy the file sets A = None / HAVE_NUMPY = False, but the nine
module-level pytest tests still called A.load / A.offsets, ran the
numpy-importing CLI, or imported numpy, so 7 of them failed (seen on native
Windows, Python 3.12 and 3.15). They are now skipped without numpy, as the
__main__ block already skips them; the CLI guard tests fake numpy and still
run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@wasonidas

Copy link
Copy Markdown

Independent Windows CPU check of e956e93f63e5b04192f9cfe7f46a3c3e844754c7, Python 3.12.10 and 3.15.2, pytest 9.2.0.

  • With pinned NumPy and Pillow: 14 passed, plus 8 subtests.
  • Without NumPy: 4 CLI guard tests passed (including 8 subtests), and exactly 10 NumPy-dependent items skipped. The same held in the Python 3.12 pytest-only environment without Pillow.
  • The same no-NumPy environment on parent 1cc6e3c1, with Pillow installed, had 10 failures and 4 passes. The standalone python -I tests/test_amd_swizzle.py still passed with and without NumPy.

The fallback cases remain exercised. Synthetic inputs only. AI-assisted.

@x2Tweek x2Tweek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the diff for #6686 (tests/test_amd_swizzle.py: skip numpy tests when numpy is absent).

The change adds a needs_numpy skip decorator to the tests that require numpy, so they are skipped instead of failing when numpy is not installed. The pytest import is already present and conditionally handled at the top of the file (try: import pytest ... except ImportError: pytest = None), and HAVE_NUMPY is already computed from the amd_swizzle import. The decorator logic (if pytest is not None: ... else: def needs_numpy(fn): return fn) matches this pattern.

Tests that fake numpy internally (the CLI guard tests) still run, as intended.

This is a clean, minimal, CPU-only test fix. No game files, no GPU, no build needed.

AI-assisted.

🤖 Generated with Claude Code

@memorypressure

Copy link
Copy Markdown

Verified with and without numpy: without numpy the 10 numpy-dependent tests skip and the 4 fake-numpy CLI guards still pass (4 passed/10 skipped vs 7 failed on unmodified main); with numpy the result set is identical to main's, including 6 host-specific failures tied to the Windows-default AMD_SWIZZLE_HEADER path — the skips mask nothing. python -I is green. Flag: no CI checks reported. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@kapitche

Copy link
Copy Markdown
Contributor

Tested e956e93 merged with main e0816d6 on Linux/Python 3.12.16: pass

Test-only (@needs_numpy skip marks on module-level tests in tests/test_amd_swizzle.py).

  • With numpy (repo .venv): python -I -m pytest -q tests/test_amd_swizzle.py: 14 passed, 8 subtests passed. python -I tests/test_amd_swizzle.py prints ok for both tests in its __main__ path.
  • Without numpy, simulated by putting a stub numpy package that raises ModuleNotFoundError(name="numpy") on the path (run without -I so PYTHONPATH applies): with the PR, python -m pytest -q tests/test_amd_swizzle.py: 4 passed, 10 skipped, 8 subtests passed. With the file restored from upstream/main under the same stub (control): 5 failed, 9 passed. Restored with git checkout HEAD --.

I did not run it on an interpreter that really lacks numpy (bare python3 here is 3.10 and has neither numpy nor pytest).

@shayderrr shayderrr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

tests/test_amd_swizzle.py defines a needs_numpy marker — pytest.mark.skipif(not HAVE_NUMPY, reason="numpy is not installed") under pytest, a no-op decorator otherwise — and applies it to the module-level tests that import or exercise numpy (test_symbols_and_xor, test_rejects_code, the detile/preview tests, and the parametrized test_cli_previews_uncompressed_r8_and_rg8). CLI guard tests that fake numpy are deliberately left unmarked and continue to run without it.

Why merge

The __main__ block already skipped these tests without numpy; aligning pytest with that behavior removes nine spurious failures in a bare test environment while keeping dependency-free coverage.

Verdict: Approve

@shayderrr

Copy link
Copy Markdown
Collaborator

Summary

tests/test_amd_swizzle.py defines a needs_numpy marker — pytest.mark.skipif(not HAVE_NUMPY, reason="numpy is not installed") under pytest, a no-op decorator otherwise — and applies it to the module-level tests that import or exercise numpy (test_symbols_and_xor, test_rejects_code, the detile/preview tests, and the parametrized test_cli_previews_uncompressed_r8_and_rg8). CLI guard tests that fake numpy are deliberately left unmarked and continue to run without it.

Why merge

The __main__ block already skipped these tests without numpy; aligning pytest with that behavior removes nine spurious failures in a bare test environment while keeping dependency-free coverage.

Verdict: Approve

@shayderrr
shayderrr merged commit 8bcf3eb into ItsNotRexed:main Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants