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

134 lines
5.5 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 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)
page.solitary_button.click()
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"
page.net_list_button.click()
assert page.model.rowCount() == 2
page.net_name_edit.setText(" n2 ")
page.cross_page_button.click()
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("button_name,attribute_name", [
("value_miss_button", "Value"), ("value1_miss_button", "Value1"),
])
def test_attribute_omission_buttons_and_include_missing_filter(
qtbot, tmp_path, component_factory, snapshot_factory, button_name, 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)))
getattr(page, button_name).click()
assert page.model.rowCount() == 1
assert page.model.item(0, 1).text() == f"R1 {attribute_name}"
page.include_missing_checkbox.setChecked(True)
getattr(page, button_name).click()
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)),)))
page.net_list_button.click()
page.cross_page_button.click()
assert page.model.rowCount() == 0
assert "请输入" in page.summary_label.text()
page.net_name_edit.setText("missing")
page.cross_page_button.click()
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())
page.solitary_button.click()
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.solitary_button.isEnabled()
assert not page.value_miss_button.isEnabled()
assert not page.cross_page_button.isEnabled()
controller.load_snapshot(snapshot_factory())
assert page.solitary_button.isEnabled()
assert page.value_miss_button.isEnabled()
assert page.cross_page_button.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.navigation.setCurrentRow(4)
page = window.pages.currentWidget()
assert isinstance(page, InspectionPage)
assert page.model.rowCount() == 2
assert page.value_miss_button.isHidden()
page.solitary_button.click()
assert page.model.rowCount() == 1
page.net_name_edit.setText("N2")
page.cross_page_button.click()
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,)),)))
page.net_list_button.click()
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"