From 37817a610f6a44a31fddc4654865e89a40dcedfe Mon Sep 17 00:00:00 2001 From: Victor Kuznetsov Date: Mon, 8 Jun 2026 18:51:26 -0700 Subject: [PATCH] test(photomaker): stub face_analyser + analyze_faces in the control-flow test The previous commit added a real call into FaceAnalysis2 / analyze_faces inside restore_faces_photomaker, which broke the model-free control-flow test. Stub it: - monkeypatch _get_face_analyser to return a sentinel - install a fake `photomaker` module with analyze_faces returning a single 512-d zero embedding - add dtype=torch.float32 to the fake pipeline class so .to(device, dtype=...) works 11/11 green. Co-Authored-By: Claude Opus 4.8 (1M context) --- tests/test_photomaker_restore.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/test_photomaker_restore.py b/tests/test_photomaker_restore.py index 6a55d2f..63f5f58 100644 --- a/tests/test_photomaker_restore.py +++ b/tests/test_photomaker_restore.py @@ -100,8 +100,11 @@ class TestRestoreFacesPhotomakerControlFlow: size = photomaker_restore._PHOTOMAKER_FACE_SIZE fake_face = Image.fromarray(np.full((size, size, 3), fill_value, dtype=np.uint8)) + import torch + class _FakePipe: device = "cpu" + dtype = torch.float32 def __call__(self, **_kwargs): return SimpleNamespace(images=[fake_face]) @@ -119,8 +122,18 @@ class TestRestoreFacesPhotomakerControlFlow: assert np.array_equal(out, cleaned) def test_one_face_gets_composited_into_cleaned(self, monkeypatch): + import sys + import types + monkeypatch.setattr(photomaker_restore, "is_available", lambda: True) monkeypatch.setattr(photomaker_restore, "_get_pipeline", lambda: self._fake_pipeline_class(fill_value=210)) + # FaceAnalyser singleton: any non-None object; the test stubs analyze_faces below. + monkeypatch.setattr(photomaker_restore, "_get_face_analyser", lambda: object()) + # Stub `from photomaker import analyze_faces` inside the function: install a + # fake `photomaker` module that returns a single 512-d embedding per call. + fake_photomaker = types.ModuleType("photomaker") + fake_photomaker.analyze_faces = lambda _fa, _bgr: [{"embedding": np.zeros(512, dtype=np.float32)}] + monkeypatch.setitem(sys.modules, "photomaker", fake_photomaker) orig = np.full((400, 400, 3), 30, dtype=np.uint8) cleaned = np.full((400, 400, 3), 90, dtype=np.uint8)