[PR #2101] test_calibrated_texture_extra: patch ct.replace_retry so the #570 test works without numpy #2106

Open
opened 2026-11-26 21:20:04 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2101
Author: @Boost9898
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/calibrated-texture-replace-cleanup


📝 Commits (1)

  • 4cfb025 test_calibrated_texture_extra: patch the replace_retry that calibrated_texture holds

📊 Changes

1 file changed (+1 additions, -1 deletions)

View changed files

📝 tests/test_calibrated_texture_extra.py (+1 -1)

📄 Description

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_file to tests/test_calibrated_texture_extra.py. It fails on main db1a22d29 wherever numpy isn't installed (OSError not raised).

Without numpy, _load_calibrated_texture() runs calibrated_texture.py inside mock.patch.dict(sys.modules, {"numpy": fake_np}). On exit, patch.dict restores sys.modules, which also removes replace_retry, imported during that load. The test patches mock.patch("replace_retry.replace", ...), which imports and patches a fresh copy of replace_retry. ct.replace_retry is still the old one, so export_file replaces the file normally and nothing raises. Checked: with the fake numpy, ct.replace_retry is sys.modules["replace_retry"] is False.

The test now patches mock.patch.object(ct.replace_retry, "replace", ...), which is the module export_file calls, with or without numpy. tools/calibrated_texture.py is 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 on main db1a22d29. With this change, all 30 tests OK on both versions.
  • Negative control: with the tmp.unlink(...) cleanup in export_file removed, the test fails again, so it still checks the cleanup.
  • python -m compileall, git diff --check and scripts/check_no_game_data.py on the changed file: clean.

GPUs tested: n/a (no GPU tests involved)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • 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 rule changes)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/2101 **Author:** [@Boost9898](https://github.com/Boost9898) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/calibrated-texture-replace-cleanup` --- ### 📝 Commits (1) - [`4cfb025`](https://github.com/ubiquitarianism/leonida/commit/4cfb025a080ca58927701721ac3042f476a5440c) test_calibrated_texture_extra: patch the replace_retry that calibrated_texture holds ### 📊 Changes **1 file changed** (+1 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_calibrated_texture_extra.py` (+1 -1) </details> ### 📄 Description 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_file` to `tests/test_calibrated_texture_extra.py`. It fails on `main` `db1a22d29` wherever numpy isn't installed (`OSError not raised`). Without numpy, `_load_calibrated_texture()` runs `calibrated_texture.py` inside `mock.patch.dict(sys.modules, {"numpy": fake_np})`. On exit, `patch.dict` restores `sys.modules`, which also removes `replace_retry`, imported during that load. The test patches `mock.patch("replace_retry.replace", ...)`, which imports and patches a fresh copy of `replace_retry`. `ct.replace_retry` is still the old one, so `export_file` replaces the file normally and nothing raises. Checked: with the fake numpy, `ct.replace_retry is sys.modules["replace_retry"]` is `False`. The test now patches `mock.patch.object(ct.replace_retry, "replace", ...)`, which is the module `export_file` calls, with or without numpy. `tools/calibrated_texture.py` is 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 on `main` `db1a22d29`. With this change, all 30 tests OK on both versions. - Negative control: with the `tmp.unlink(...)` cleanup in `export_file` removed, the test fails again, so it still checks the cleanup. - `python -m compileall`, `git diff --check` and `scripts/check_no_game_data.py` on the changed file: clean. GPUs tested: n/a (no GPU tests involved) AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] 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 rule changes) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#2106
No description provided.