Private
Public Access
refactor(gui_2): migrate L1222 _show_menus is_max to Result[T] (Phase 3)
TIER-2 READ conductor/code_styleguides/error_handling.md end-to-end before Phase 3. Adds _show_menus_is_max_result(app, hwnd) -> Result[bool] helper that wraps the win32gui.GetWindowPlacement try/except from App._show_menus. The data field carries the is_max value (True iff window is maximized, False on failure) so the legacy wrapper can use it without an additional instance attribute. App._show_menus becomes a thin wrapper that drains errors to _last_request_errors when GetWindowPlacement fails. Audit: BROAD_CATCH count 20 -> 19, COMPLIANT count 17 -> 18. Tests: 2/2 pass.
This commit is contained in:
@@ -419,4 +419,48 @@ def test_phase_3_l1197_show_menus_hwnd_result_failure():
|
||||
assert result.errors, "Expected at least one error on failure"
|
||||
err = result.errors[0]
|
||||
assert err.source == "gui_2._show_menus_hwnd_result"
|
||||
assert result.data == 0
|
||||
assert result.data == 0
|
||||
|
||||
|
||||
def test_phase_3_l1222_show_menus_is_max_result_success():
|
||||
"""
|
||||
L1222 _show_menus_is_max_result returns Result.ok=True with is_max=True.
|
||||
|
||||
The helper wraps the win32gui.GetWindowPlacement try/except in
|
||||
App._show_menus. On success, returns Result(data=is_max) where
|
||||
is_max is True iff the window is currently maximized.
|
||||
"""
|
||||
from src import gui_2
|
||||
from unittest.mock import MagicMock, patch
|
||||
app = MagicMock()
|
||||
mock_hwnd = 12345
|
||||
SW_SHOWMAXIMIZED = 3
|
||||
mock_placement = ("first", SW_SHOWMAXIMIZED)
|
||||
with patch.object(gui_2, "win32gui") as mock_w32, \
|
||||
patch.object(gui_2, "win32con") as mock_w32c:
|
||||
mock_w32.GetWindowPlacement.return_value = mock_placement
|
||||
mock_w32c.SW_SHOWMAXIMIZED = SW_SHOWMAXIMIZED
|
||||
result = gui_2._show_menus_is_max_result(app, mock_hwnd)
|
||||
assert result.ok, f"Expected ok=True on success, got errors: {result.errors}"
|
||||
assert result.data is True
|
||||
|
||||
|
||||
def test_phase_3_l1222_show_menus_is_max_result_failure():
|
||||
"""
|
||||
L1222 _show_menus_is_max_result returns Result.ok=False with is_max=False on failure.
|
||||
|
||||
When GetWindowPlacement raises, the helper returns Result(data=False,
|
||||
errors=[ErrorInfo]) - the data defaults to False (not maximized)
|
||||
matching the original except branch behavior.
|
||||
"""
|
||||
from src import gui_2
|
||||
from unittest.mock import MagicMock, patch
|
||||
app = MagicMock()
|
||||
with patch.object(gui_2, "win32gui") as mock_w32:
|
||||
mock_w32.GetWindowPlacement.side_effect = RuntimeError("win32 failed")
|
||||
result = gui_2._show_menus_is_max_result(app, 12345)
|
||||
assert not result.ok, f"Expected ok=False on failure, got data: {result.data}"
|
||||
assert result.errors, "Expected at least one error on failure"
|
||||
err = result.errors[0]
|
||||
assert err.source == "gui_2._show_menus_is_max_result"
|
||||
assert result.data is False
|
||||
Reference in New Issue
Block a user