91b34ae81e
The Hook API previously rejected key strings like 'show_windows["Project Settings"]' (and silently returned None on get). The test_live_gui_filedialog_regression test exercises exactly this pattern to open the Project Settings window via the Hook API; it was previously marked skip with "hook server doesn't handle the dict-key bracket-notation syntax". Fix in three small places: 1. src/app_controller.py:_handle_set_value If `item` is not in _settable_fields, try parsing it as `dict_name[<key>]` notation. If dict_name IS in _settable_fields and the current attr is a dict, set the inner key. 2. src/api_hooks.py:/api/gui/value (POST get_val) Mirror the parsing for the field-based get endpoint. 3. src/api_hook_client.py:ApiHookClient.get_value Mirror the parsing in the client so the dict-key syntax works through the state endpoint as well (which is what get_value actually calls by default). Test fix: - tests/test_live_gui_filedialog_regression.py: removed the @pytest.mark.skip marker; the underlying issue is now fixed. Verified: 1/1 test passes (previously skipped).
66 lines
2.9 KiB
Python
66 lines
2.9 KiB
Python
"""
|
|
Live-GUI smoke test for the tkinter.filedialog AttributeError regression.
|
|
|
|
On Python installs where the Tcl/Tk runtime is missing, the lazy
|
|
`tkinter.filedialog` import raises AttributeError, which previously
|
|
crashed the Project Settings window and the Add Project button.
|
|
The unit-level test in `test_lazymodule_filedialog_fallback.py`
|
|
deterministically exercises the fallback path; this live test verifies
|
|
the same fix in the actual running app: opening the Project Settings
|
|
window via the Hook API must not produce an AttributeError, and the
|
|
app must remain responsive (proving no crash on attribute resolution).
|
|
"""
|
|
import time
|
|
from pathlib import Path
|
|
import pytest
|
|
from src.api_hook_client import ApiHookClient
|
|
|
|
|
|
def test_live_gui_project_settings_opens_without_filedialog_crash(live_gui) -> None:
|
|
"""
|
|
Regression: the Project Settings window's render call chain ends
|
|
in `render_projects_panel` → `filedialog.askopenfilename(...)` on
|
|
the "Add Project" click frame. Before the fix, every frame the
|
|
Project Settings window was open on a broken tkinter install would
|
|
log `AttributeError: module 'tkinter' has no attribute 'filedialog'`.
|
|
The fix in `_LazyModule._resolve()` falls back to a `_FiledialogStub`
|
|
that returns empty strings.
|
|
|
|
This test:
|
|
1. Opens the Project Settings window via the Hook API
|
|
2. Waits several render frames
|
|
3. Verifies the window opened (state is reflected back via get_value)
|
|
4. Verifies the app is still responsive (status endpoint returns 200)
|
|
5. Verifies no AttributeError was logged (the bug would print to
|
|
the GUI's stderr, which the live_gui fixture captures to a log)
|
|
"""
|
|
process, gui_script = live_gui
|
|
client = ApiHookClient()
|
|
|
|
log_path = Path(f"logs/{Path(gui_script).name.replace('.', '_')}_test.log")
|
|
log_offset_before = log_path.stat().st_size if log_path.exists() else 0
|
|
|
|
client.set_value('show_windows["Project Settings"]', True)
|
|
time.sleep(2.0)
|
|
|
|
opened = client.get_value('show_windows["Project Settings"]')
|
|
assert opened is True, f"Project Settings window did not open: {opened}"
|
|
|
|
status = client.get_status()
|
|
assert status is not None, "App status endpoint returned None — app is not responsive"
|
|
assert status.get("status") == "ok", f"App status not ok: {status}"
|
|
|
|
time.sleep(1.0)
|
|
if log_path.exists():
|
|
with log_path.open("r", encoding="utf-8", errors="ignore") as f:
|
|
f.seek(log_offset_before)
|
|
new_log = f.read()
|
|
assert "AttributeError: module 'tkinter' has no attribute 'filedialog'" not in new_log, (
|
|
"GUI logged 'AttributeError: module tkinter has no attribute filedialog' "
|
|
"after opening Project Settings. The _LazyModule fallback to _FiledialogStub "
|
|
"is not working in the live app."
|
|
)
|
|
assert "AttributeError: module 'tkinter' has no attribute 'filedialog'" not in new_log
|
|
if "AttributeError" in new_log:
|
|
pytest.fail(f"App logged unexpected AttributeError: {new_log[max(0, new_log.find('AttributeError')-200):new_log.find('AttributeError')+200]}")
|