feat(test): expose live_gui_workspace as a separate fixture
This commit is contained in:
+15
-2
@@ -398,10 +398,11 @@ def app_instance() -> Generator[App, None, None]:
|
||||
app.shutdown()
|
||||
|
||||
class _LiveGuiHandle:
|
||||
def __init__(self, process: subprocess.Popen, gui_script: str) -> None:
|
||||
def __init__(self, process: subprocess.Popen, gui_script: str, workspace: Path = None) -> None:
|
||||
"""[SDM: tests/conftest.py:_LiveGuiHandle] [C: tests/conftest.py:live_gui fixture]"""
|
||||
self._process = process
|
||||
self._gui_script = gui_script
|
||||
self._workspace = workspace
|
||||
self._lock = threading.Lock()
|
||||
self._respawn_count = 0
|
||||
|
||||
@@ -427,6 +428,11 @@ class _LiveGuiHandle:
|
||||
"""[M: tests/conftest.py:live_gui fixture]"""
|
||||
return self._gui_script
|
||||
|
||||
@property
|
||||
def workspace(self) -> Path | None:
|
||||
"""[M: tests/conftest.py:live_gui fixture] Absolute path to the live_gui workspace (pytest tmp dir)."""
|
||||
return self._workspace
|
||||
|
||||
def is_alive(self) -> bool:
|
||||
"""Returns True if the subprocess is running."""
|
||||
return self._process is not None and self._process.poll() is None
|
||||
@@ -608,7 +614,7 @@ def live_gui(request, tmp_path_factory) -> Generator["_LiveGuiHandle", None, Non
|
||||
diag.finalize("Live GUI Startup Telemetry", "PASS", "Hook server successfully initialized.")
|
||||
|
||||
try:
|
||||
yield _LiveGuiHandle(process, gui_script)
|
||||
yield _LiveGuiHandle(process, gui_script, temp_workspace)
|
||||
finally:
|
||||
print(f"\n[Fixture] Finally block triggered: Shutting down {gui_script}...")
|
||||
# Reset the GUI state before shutting down
|
||||
@@ -646,3 +652,10 @@ def _check_live_gui_health(request, live_gui) -> Generator[None, None, None]:
|
||||
handle = live_gui
|
||||
handle.ensure_alive()
|
||||
yield
|
||||
|
||||
@pytest.fixture
|
||||
def live_gui_workspace(live_gui) -> Path:
|
||||
"""[SDM: tests/conftest.py:live_gui_workspace] [C: tests/test_rag_phase4_*.py, tests/test_saved_presets_sim.py, etc.]"""
|
||||
handle = live_gui
|
||||
return handle.workspace
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
"""Tests for the live_gui_workspace fixture (Phase 3, Task 3.2)."""
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def test_live_gui_workspace_is_path(live_gui_workspace) -> None:
|
||||
"""The live_gui_workspace fixture yields a Path object."""
|
||||
assert isinstance(live_gui_workspace, Path)
|
||||
|
||||
|
||||
def test_live_gui_workspace_exists(live_gui_workspace) -> None:
|
||||
"""The workspace path was created and exists on disk."""
|
||||
assert live_gui_workspace.exists()
|
||||
|
||||
|
||||
def test_live_gui_workspace_is_a_directory(live_gui_workspace) -> None:
|
||||
"""The workspace is a directory (not a file)."""
|
||||
assert live_gui_workspace.is_dir()
|
||||
|
||||
|
||||
def test_live_gui_workspace_in_tmp_dir(live_gui_workspace) -> None:
|
||||
"""The workspace is in pytest's tmp dir, NOT in the project tree."""
|
||||
# Should be under the system temp dir (e.g. AppData/Local/Temp on Windows)
|
||||
path_str = str(live_gui_workspace).lower()
|
||||
assert 'temp' in path_str or 'tmp' in path_str, f"Workspace not in tmp dir: {live_gui_workspace}"
|
||||
|
||||
|
||||
def test_live_gui_workspace_writable(live_gui_workspace) -> None:
|
||||
"""Tests can write to the workspace."""
|
||||
test_file = live_gui_workspace / "test_write.txt"
|
||||
test_file.write_text("hello", encoding="utf-8")
|
||||
assert test_file.read_text(encoding="utf-8") == "hello"
|
||||
Reference in New Issue
Block a user