# tests/integration/test_grounding_offset.py """Tests intégration pour la propagation d'offset multi-écrans (QW1).""" import pytest from unittest.mock import patch, MagicMock from core.execution import input_handler @pytest.fixture def mock_screen(): """Mock une capture mss : retourne un PIL Image factice + offsets.""" from PIL import Image img = Image.new("RGB", (1920, 1080), color="white") return img def test_capture_screen_default_returns_composite_when_no_idx(mock_screen): """_capture_screen() sans monitor_idx → composite, offset (0, 0).""" with patch("core.execution.input_handler.mss") as mock_mss: ctx = mock_mss.mss.return_value.__enter__.return_value ctx.monitors = [{"left": 0, "top": 0, "width": 3840, "height": 1080}] ctx.grab.return_value = MagicMock(size=(3840, 1080), bgra=b"\x00" * (3840 * 1080 * 4)) with patch("core.execution.input_handler.PILImage.frombytes", return_value=mock_screen): screen, w, h, ox, oy = input_handler._capture_screen() assert (w, h, ox, oy) == (3840, 1080, 0, 0) def test_capture_screen_targets_specific_monitor_with_offset(mock_screen): """_capture_screen(monitor_idx=1) → cible monitors[2] (mss skip [0]), offset = monitor.left.""" with patch("core.execution.input_handler.mss") as mock_mss: ctx = mock_mss.mss.return_value.__enter__.return_value # mss layout : [0]=composite, [1]=primary, [2]=secondary ctx.monitors = [ {"left": 0, "top": 0, "width": 3840, "height": 1080}, {"left": 0, "top": 0, "width": 1920, "height": 1080}, {"left": 1920, "top": 0, "width": 1920, "height": 1080}, ] ctx.grab.return_value = MagicMock(size=(1920, 1080), bgra=b"\x00" * (1920 * 1080 * 4)) with patch("core.execution.input_handler.PILImage.frombytes", return_value=mock_screen): screen, w, h, ox, oy = input_handler._capture_screen(monitor_idx=1) assert (w, h, ox, oy) == (1920, 1080, 1920, 0)