Private
Public Access
refactor(gui_2): migrate L742 _load_fonts mono font to Result[T] (Phase 3)
TIER-2 READ conductor/code_styleguides/error_handling.md end-to-end before Phase 3. Adds _load_fonts_mono_result(app, font_size, config) -> Result[bool] helper that wraps the thirdparty hello_imgui.FontLoadingParams + hello_imgui.load_font try/except from App._load_fonts. App._load_fonts becomes a thin wrapper that drains errors to _startup_timeline_errors (startup-time error plane). Audit: BROAD_CATCH count 24 -> 23, COMPLIANT count 13 -> 14. Tests: 2/2 pass.
This commit is contained in:
@@ -249,4 +249,50 @@ def test_phase_3_l731_load_fonts_main_result_failure():
|
||||
assert result.errors, "Expected at least one error on failure"
|
||||
err = result.errors[0]
|
||||
assert err.source == "gui_2._load_fonts_main_result"
|
||||
assert "font load failed" in err.message
|
||||
assert "font load failed" in err.message
|
||||
|
||||
|
||||
def test_phase_3_l742_load_fonts_mono_result_success():
|
||||
"""
|
||||
L742 _load_fonts_mono_result returns Result.ok=True on success.
|
||||
|
||||
The helper wraps the mono font loading try/except in App._load_fonts.
|
||||
On success, it returns Result(data=True) with no errors and sets
|
||||
app.mono_font to the loaded font.
|
||||
"""
|
||||
from src import gui_2
|
||||
from unittest.mock import MagicMock, patch
|
||||
app = MagicMock()
|
||||
mock_mono_font = MagicMock(name="mock_mono_font")
|
||||
mock_config = MagicMock(name="mock_font_config")
|
||||
with patch.object(gui_2, "hello_imgui") as mock_hi, \
|
||||
patch("src.startup_profiler.startup_profiler") as mock_sp:
|
||||
mock_hi.FontLoadingParams.return_value = "mock_params"
|
||||
mock_hi.load_font.return_value = mock_mono_font
|
||||
result = gui_2._load_fonts_mono_result(app, 16.0, mock_config)
|
||||
assert result.ok, f"Expected ok=True on success, got errors: {result.errors}"
|
||||
assert result.data is True
|
||||
assert app.mono_font is mock_mono_font
|
||||
|
||||
|
||||
def test_phase_3_l742_load_fonts_mono_result_failure():
|
||||
"""
|
||||
L742 _load_fonts_mono_result returns Result.ok=False with ErrorInfo on failure.
|
||||
|
||||
When the underlying third-party hello_imgui.load_font call raises, the
|
||||
helper converts the exception to ErrorInfo and returns Result(data=False).
|
||||
"""
|
||||
from src import gui_2
|
||||
from unittest.mock import MagicMock, patch
|
||||
app = MagicMock()
|
||||
mock_config = MagicMock(name="mock_font_config")
|
||||
with patch.object(gui_2, "hello_imgui") as mock_hi, \
|
||||
patch("src.startup_profiler.startup_profiler") as mock_sp:
|
||||
mock_hi.FontLoadingParams.return_value = "mock_params"
|
||||
mock_hi.load_font.side_effect = RuntimeError("mono font missing")
|
||||
result = gui_2._load_fonts_mono_result(app, 16.0, mock_config)
|
||||
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._load_fonts_mono_result"
|
||||
assert "mono font missing" in err.message
|
||||
Reference in New Issue
Block a user