test_calibrated_texture_extra: patch ct.replace_retry so the #570 test works without numpy #2101
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2101"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by Boost9898 on 2026-11-25T20:44:33Z.
Claimed in the coordination issue as: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7174081616
What and why
#570 added
test_export_file_replacement_failure_cleans_temporary_filetotests/test_calibrated_texture_extra.py. It fails onmaindb1a22d29wherever numpy isn't installed (OSError not raised).Without numpy,
_load_calibrated_texture()runscalibrated_texture.pyinsidemock.patch.dict(sys.modules, {"numpy": fake_np}). On exit,patch.dictrestoressys.modules, which also removesreplace_retry, imported during that load. The test patchesmock.patch("replace_retry.replace", ...), which imports and patches a fresh copy ofreplace_retry.ct.replace_retryis still the old one, soexport_filereplaces the file normally and nothing raises. Checked: with the fake numpy,ct.replace_retry is sys.modules["replace_retry"]isFalse.The test now patches
mock.patch.object(ct.replace_retry, "replace", ...), which is the moduleexport_filecalls, with or without numpy.tools/calibrated_texture.pyis unchanged.Tested
Apple M4, macOS 26.5.1, Python 3.14.8 and 3.12.10 (neither has numpy, so the stdlib shim path is used), CPU only, no game files.
tests/test_calibrated_texture_extra.py: the test fails onmaindb1a22d29. With this change, all 30 tests OK on both versions.tmp.unlink(...)cleanup inexport_fileremoved, the test fails again, so it still checks the cleanup.python -m compileall,git diff --checkandscripts/check_no_game_data.pyon the changed file: clean.GPUs tested: n/a (no GPU tests involved)
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator rule changes)Imported from ubiquitarianism/leonida. Originally posted by EdenBendheim on 2026-11-26T05:17:10Z.
Independent verification of head
4cfb025a080ca58927701721ac3042f476a5440capplied to current maina73a57e13(macOS 27.3, Apple M1 Max, CPU-only synthetic fixtures, no numpy/game data).test_calibrated_texture_extra.py29/30; reproducedtest_export_file_replacement_failure_cleans_temporary_filefailing withOSError not raised.This also resolves one of the two pre-existing failures in the full standalone test run for #2193. No defects found.
Imported from ubiquitarianism/leonida. Originally posted by Mby159 on 2026-11-26T08:04:16Z.
Independent Windows verification of head
4cfb025a080ca58927701721ac3042f476a5440capplied to current maina73a57e1339be072baf5522351c8ec7f1482b56b.Environment: Windows 11 (10.0.29712 SP0), AMD64, CPython 3.13.17, no NumPy (
import numpy→ModuleNotFoundError).Why this leg matters: the
checkjob in.github/workflows/ci.ymlruns onwindows-latestand executes eachtests/test_*.pysuite aspython -I "$t"; that leg has no NumPy, and this file is included in that loop, so it is exactly the configuration in which the file can go red. There is no completed CI run to cite for this head — its CI run has been sittingqueuedsince 2026-11-25T20:44Z without starting (onlyno-game-datahas completed, successfully) — so everything below was measured locally in the exact configuration that step uses (python -I, no NumPy).Measured, same command in both cases (
python -I tests/test_calibrated_texture_extra.py):a73a57e1339bRan 30 tests→FAILED (failures=1)Ran 30 tests→OKThe single main failure is
test_export_file_replacement_failure_cleans_temporary_file→AssertionError: OSError not raised.Why it fails, confirmed by direct probe on this tree:
calibrated_textureinsidemock.patch.dict(sys.modules, {"numpy": fake_np}); that import pulls inreplace_retry, soreplace_retryenterssys.modulesinside the patch.dict block.sys.modulesto its pre-block content, which removesreplace_retryagain — whilecalibrated_texture.replace_retrykeeps the original module object.mock.patch("replace_retry.replace", ...)resolves its string target by importingreplace_retryonce more, yielding a different module object (ct.replace_retry is sys.modules["replace_retry"]→False), so the patch lands on an objectct.export_filenever calls.OSErrortherefore never fires, andassertRaisesRegexfails withOSError not raised.mock.patch.object(ct.replace_retry, "replace", ...)patches the object the code actually holds, so the failure path is genuinely exercised and the temporary-file cleanup assertion becomes meaningful.I had derived this same one-line fix on my own tree before finding this PR, so this is a confirmation rather than a new proposal — the change matches what I measured and is correct as written. No defects found in it.
Caveat: the local interpreter is CPython 3.13.17 while the
checkleg pins 3.12, so that version axis is not covered here. The mechanism above isunittest.mockmodule-identity behaviour and does not depend on the interpreter version.Imported from ubiquitarianism/leonida. Originally posted by wavehs on 2026-11-26T18:09:54Z.
Verified independently on
mainbd6ba97ab(macOS 27.2.1 arm64, Python 3.15.2, numpy absent, so the stdlib shim path runs), with the PR diff applied:Before (unmodified main):
After:
Ran 30 tests ... OK.Cause confirmed: without the patch,
ct.replace_retry is sys.modules["replace_retry"]isFalse—mock.patch.dict(sys.modules, {"numpy": fake_np})in_load_calibrated_texture()removes the sibling modules imported duringexec_module, so patching by module name hits a second copy.Negative control: with
tmp.unlink(missing_ok=True)removed fromexport_file, the fixed test fails again (FAILED), so it still checks the temp-file cleanup.This matters for CI, not only locally: the
check(Windows) andmacos-pythonjobs run the stdlib loop before theirpip install -r tests/requirements.txt, so numpy is absent there (stdlib-tests-linuxinstalls numpy first and is unaffected). The change is test-only.AI-assisted (verification run only).
Imported from ubiquitarianism/leonida. Originally posted by Andretuta on 2026-11-27T06:24:41Z.
I reproduced the failure on native Windows with CPython 3.13.14 and no NumPy. On
mainatd1dff7949, the replacement test failed withOSError not raised. With4cfb025a0merged in, all 30 tests intest_calibrated_texture_extra.pypassed. The suite passed again in the two-worker runner from #2193 alongside the other Windows fixes.AI-assisted testing.