"""Current one-project UI fixtures; queries must settle before assertions.""" import os os.environ.setdefault('QT_QPA_PLATFORM', 'offscreen') from types import SimpleNamespace from pathlib import Path import subprocess import pytest from dx_productivity.trial_task_center.logging_setup import configure_logging from dx_productivity.trial_task_center.store import TaskStore from dx_productivity.trial_task_center.service import TaskCenterService from dx_productivity.trial_task_center.quick_run import QuickRunPreparer from dx_productivity.trial_task_center.ui.main_window import TrialTaskCenterWindow @pytest.fixture def ui(qtbot, tmp_path): root = tmp_path/'projects' for name in ('Board-A','Board-B'): project=root/name/'board.prj';project.parent.mkdir(parents=True) project.write_text('KEY FrontEndSnapshot "DxD"\nKEY iCDBDir "database"\n') data=tmp_path/'data' calls=[] def worker(command, timeout): queue=Path(command[3]);job=command[-1];calls.append(job) with (queue/'status.tsv').open('a',encoding='utf-8') as stream: stream.write(f'{job}\tno_match\tbatch_closed\tNo matching components\n') return subprocess.CompletedProcess(command,0,'','') preparer=QuickRunPreparer(data,process_runner=worker, cscript_resolver=lambda:Path('cscript.exe'),sheet_discoverer=lambda _path:(('MAIN','1'),)) store=TaskStore(tmp_path/'tasks.db') service=TaskCenterService(store,configure_logging(data),quick_run_preparer=preparer) tasks=service.create_project_tasks(root) service.add_rule(tasks[0].task_id,'OLD','NEW') window=TrialTaskCenterWindow(service) qtbot.addWidget(window);window.show() def settle(): qtbot.waitUntil(lambda:not window._workers and not window._task_query.busy and not window._context_query.busy and not window._feedback_query.busy and not window._log_presenter.query.busy,timeout=5000) def open_task(task): window.open_task(task.task_id) qtbot.waitUntil(lambda:not window._context_query.busy and not window._loading,timeout=5000) assert window._context and window._context.task.task_id==task.task_id open_task(tasks[0]) yield SimpleNamespace(window=window,service=service,store=store,tasks=tasks, calls=calls,settle=settle,open=open_task,data=data) settle();window.plan_panel.discard_all();window.close();store.close()