Files
yiyezhqiu-refactored/tests/ui/test_inspection_controller.py
T

141 lines
5.6 KiB
Python

import pytest
from dx_productivity.domain.models import AttributeRecord, NetRecord, RunPaths
from dx_productivity.ui.inspection_controller import InspectionController
from dx_productivity.ui.inspection_page import InspectionPage
def _controller(qtbot, tmp_path, snapshot):
page = InspectionPage()
qtbot.addWidget(page)
paths = RunPaths(snapshot.run_id, tmp_path, tmp_path / "request.json",
tmp_path / "result.tsv", tmp_path / "locate.tsv", tmp_path / "apply-status.json")
controller = InspectionController(page, run_paths=paths)
controller.load_snapshot(snapshot)
return controller, page, paths
def _run_check(page, kind):
index = page.check_type_combo.findData(kind)
assert index >= 0
page.check_type_combo.setCurrentIndex(index)
page.run_button.click()
def test_network_buttons_and_cross_page_rows_publish_location_without_writes(
qtbot, tmp_path, snapshot_factory
):
snapshot = snapshot_factory(nets=(NetRecord("N1", (1,)), NetRecord("N2", (1, 2))))
controller, page, paths = _controller(qtbot, tmp_path, snapshot)
_run_check(page, "solitary")
assert page.model.rowCount() == 1
assert page.model.item(0, 1).text() == "N1"
page.table.doubleClicked.emit(page.model.index(0, 1))
assert paths.locate.read_text(encoding="utf-8") == "net|N1|1\n"
_run_check(page, "list")
assert page.model.rowCount() == 2
page.net_name_edit.setText(" n2 ")
_run_check(page, "cross")
assert page.model.rowCount() == 2
assert page.model.item(1, 2).text() == "2"
page.table.doubleClicked.emit(page.model.index(1, 1))
assert paths.locate.read_text(encoding="utf-8") == "net|N2|2\n"
assert not paths.result.exists()
assert not paths.apply_request.exists()
@pytest.mark.parametrize("attribute_name", ["Value", "Value1"])
def test_attribute_omission_buttons_and_include_missing_filter(
qtbot, tmp_path, component_factory, snapshot_factory, attribute_name
):
empty = component_factory(refdes="R1", attributes=(AttributeRecord(attribute_name, "", True),))
absent = component_factory(bridge_id="c0002", stable_uid="uid-c2", full_path="ROOT\\C2", refdes="C1")
controller, page, paths = _controller(qtbot, tmp_path, snapshot_factory(components=(empty, absent)))
_run_check(page, attribute_name)
assert page.model.rowCount() == 1
assert page.model.item(0, 1).text() == f"R1 {attribute_name}"
page.include_missing_checkbox.setChecked(True)
_run_check(page, attribute_name)
assert page.model.rowCount() == 2
page.table.doubleClicked.emit(page.model.index(1, 1))
assert paths.locate.read_text(encoding="utf-8") == "c0002\n"
assert not paths.result.exists()
def test_cross_page_empty_and_unknown_query_clear_old_results(qtbot, tmp_path, snapshot_factory):
controller, page, paths = _controller(qtbot, tmp_path, snapshot_factory(nets=(NetRecord("N2", (1, 2)),)))
_run_check(page, "list")
_run_check(page, "cross")
assert page.model.rowCount() == 0
assert "请输入" in page.summary_label.text()
page.net_name_edit.setText("missing")
_run_check(page, "cross")
assert page.model.rowCount() == 0
assert "missing" in page.summary_label.text()
def test_missing_network_data_reports_limitation(qtbot, tmp_path, snapshot_factory):
controller, page, paths = _controller(qtbot, tmp_path, snapshot_factory())
_run_check(page, "solitary")
assert page.model.rowCount() == 0
assert "未包含网络数据" in page.summary_label.text()
assert not paths.locate.exists()
def test_inspection_actions_wait_for_a_design_snapshot(qtbot, snapshot_factory):
page = InspectionPage()
qtbot.addWidget(page)
controller = InspectionController(page)
assert not page.run_button.isEnabled()
assert not page.check_type_combo.isEnabled()
assert not page.net_name_edit.isEnabled()
assert not page.include_missing_checkbox.isEnabled()
controller.load_snapshot(snapshot_factory())
assert page.run_button.isEnabled()
assert page.check_type_combo.isEnabled()
assert page.net_name_edit.isEnabled()
assert page.include_missing_checkbox.isEnabled()
def test_network_navigation_has_live_list_and_locator(qtbot, tmp_path, fixture_path, monkeypatch):
import json
from dx_productivity.ui.app import create_main_window
monkeypatch.setenv("LOCALAPPDATA", str(tmp_path / "local"))
request = tmp_path / "request.json"
data = json.loads((fixture_path / "request-basic.json").read_text(encoding="utf-8"))
data["nets"] = [{"name": "N1", "pages": [1]}, {"name": "N2", "pages": [1, 2]}]
request.write_text(json.dumps(data), encoding="utf-8")
window = create_main_window(request)
qtbot.addWidget(window)
window.set_active_page(4)
page = window.pages.currentWidget()
assert isinstance(page, InspectionPage)
assert page.model.rowCount() == 2
assert page.check_type_combo.findData("Value") == -1
_run_check(page, "solitary")
assert page.model.rowCount() == 1
page.net_name_edit.setText("N2")
_run_check(page, "cross")
assert page.model.rowCount() == 2
page.table.doubleClicked.emit(page.model.index(1, 1))
assert (tmp_path / "locate.tsv").read_text(encoding="utf-8") == "net|N2|2\n"
assert window.page_title.text() == "网络工具"
def test_refresh_recomputes_the_visible_inspection(qtbot, tmp_path, snapshot_factory):
controller, page, paths = _controller(qtbot, tmp_path, snapshot_factory(nets=(NetRecord("old", (1,)),)))
_run_check(page, "list")
controller.load_snapshot(snapshot_factory(snapshot_id="new", nets=(NetRecord("new", (2,)),)))
assert page.model.rowCount() == 1
assert page.model.item(0, 1).text() == "new"