from pathlib import Path import pytest from dx_productivity.trial_task_center.errors import TaskCenterError from dx_productivity.trial_task_center.inventory import read_component_inventory def test_inventory_reads_distinct_uids_on_same_sheet(tmp_path): project = tmp_path / 'board.prj' inventory = tmp_path / 'components.tsv' inventory.write_text( 'project_path\tschematic_name\tsheet_number\tuid\trefdes\told_part\told_value\n' f'{project}\tMAIN\t1\tu1\tR1\tOLD\tV1\n' f'{project}\tMAIN\t1\tu2\tR2\tOLD\tV2\n', encoding='utf-8') rows = read_component_inventory(inventory, project, (('MAIN', '1'),)) assert [(row.uid, row.refdes, row.old_value) for row in rows] == [ ('u1', 'R1', 'V1'), ('u2', 'R2', 'V2')] def test_inventory_rejects_forged_sheet_or_duplicate_uid(tmp_path): project = tmp_path / 'board.prj' inventory = tmp_path / 'components.tsv' inventory.write_text( 'project_path\tschematic_name\tsheet_number\tuid\trefdes\told_part\told_value\n' f'{project}\tOTHER\t1\tu1\tR1\tOLD\tV1\n', encoding='utf-8') with pytest.raises(TaskCenterError): read_component_inventory(inventory, project, (('MAIN', '1'),)) inventory.write_text( 'project_path\tschematic_name\tsheet_number\tuid\trefdes\told_part\told_value\n' f'{project}\tMAIN\t1\tu1\tR1\tOLD\tV1\n' f'{project}\tMAIN\t1\tu1\tR1\tOLD\tV1\n', encoding='utf-8') with pytest.raises(TaskCenterError): read_component_inventory(inventory, project, (('MAIN', '1'),))