Files
dxdesigner-part-replacement/tests/v1_1/test_target_table.py
T

96 lines
4.2 KiB
Python

import os
os.environ.setdefault('QT_QPA_PLATFORM', 'offscreen')
from pathlib import Path
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QApplication
from dx_productivity.trial_task_center.target_plan import ComponentTarget, TargetPlanRow
from dx_productivity.trial_task_center.ui.target_table import TargetTable
def test_edit_targets_and_nc_in_original_view_without_excel():
app = QApplication.instance() or QApplication([])
table = TargetTable()
rows = tuple(TargetPlanRow(ComponentTarget(Path('C:/board.prj'), 'MAIN', '1', uid,
refdes, 'OLD', value), False, 'NEW')
for uid, refdes, value in [('u1', 'R1', 'A/NC'), ('u2', 'R2', 'B')])
table.populate(rows)
table.model().setData(table.model().index(0, 0), Qt.CheckState.Checked, Qt.ItemDataRole.CheckStateRole)
table.model().setData(table.model().index(0, 6), 'NEW-2')
table.model().setData(table.model().index(0, 7), Qt.CheckState.Checked, Qt.ItemDataRole.CheckStateRole)
table.model().setData(table.model().index(0, 8), '100nF/10V')
table.model().setData(table.model().index(0, 9), Qt.CheckState.Unchecked, Qt.ItemDataRole.CheckStateRole)
edited = table.rows()
assert edited[0].target == rows[0].target
assert edited[0].enabled and edited[0].new_part_number == 'NEW-2'
assert edited[0].custom_value == '100nF/10V' and not edited[0].sync_nc
assert not edited[1].enabled and edited[1].target.uid == 'u2'
assert table.dirty
assert not table.model().flags(table.model().index(0, 3)) & Qt.ItemFlag.ItemIsEditable
table.close()
def test_table_lock_blocks_editing_and_selection():
app = QApplication.instance() or QApplication([])
table = TargetTable()
table.populate((TargetPlanRow(ComponentTarget(Path('C:/board.prj'), 'MAIN', '1',
'u1', 'R1', 'OLD', 'A')),))
table.set_plan_editable(False)
assert not table.model().flags(table.model().index(0, 0)) & Qt.ItemFlag.ItemIsUserCheckable
assert not table.model().flags(table.model().index(0, 6)) & Qt.ItemFlag.ItemIsEditable
table.close()
def test_target_table_find_filters_rows_and_bulk_actions_keep_hidden_rows(qtbot):
table = TargetTable()
qtbot.addWidget(table)
rows = (
TargetPlanRow(ComponentTarget(Path("board.prj"), "MAIN", "1", "u1", "R1", "OLD-A", "10nF")),
TargetPlanRow(ComponentTarget(Path("board.prj"), "MAIN", "2", "u2", "R2", "OLD-B", "22nF")),
TargetPlanRow(ComponentTarget(Path("board.prj"), "AUX", "1", "u3", "C1", "OLD-A", "10uF")),
)
table.populate(rows)
table.set_find_text("R2")
assert table.rowCount() == 1
table.selectRow(0)
table.apply_to_selected("NEW-R2")
table.set_find_text("")
assert table.rowCount() == 3
assert table.rows()[1].new_part_number == "NEW-R2"
assert table.rows()[0].new_part_number == ""
def test_target_table_find_next_selects_next_matching_row(qtbot):
table = TargetTable()
qtbot.addWidget(table)
rows = tuple(
TargetPlanRow(ComponentTarget(Path("board.prj"), "MAIN", str(index), f"u{index}", f"R{index}", "OLD", "V"))
for index in range(1, 4)
)
table.populate(rows)
table.set_find_text("R")
assert table.find_next() == 0
assert table.find_next() == 1
assert table.find_next() == 2
assert table.find_next() == 0
def test_header_sort_edit_and_bulk_actions_keep_uid_binding(qtbot):
table = TargetTable()
qtbot.addWidget(table)
rows = tuple(TargetPlanRow(ComponentTarget(Path('board.prj'), 'MAIN', '1', uid, ref, 'OLD', 'V'), enabled=True)
for uid, ref in [('u2', 'R2'), ('u1', 'R1')])
table.populate(rows)
assert table.isSortingEnabled()
table.sortByColumn(3, Qt.SortOrder.AscendingOrder)
assert table.model().index(0, 3).data() == 'R1'
table.model().setData(table.model().index(0, 6), 'NEW-R1')
table.selectRow(1)
table.apply_to_selected('NEW-R2')
assert {r.target.uid: r.new_part_number for r in table.rows()} == {'u1': 'NEW-R1', 'u2': 'NEW-R2'}
table.set_find_text('R1')
table.select_all_targets(False)
assert {r.target.uid: r.enabled for r in table.rows()} == {'u1': False, 'u2': True}