Files
yiyezhqiu-refactored/tests/features/test_bom_pvcheck.py
T

148 lines
4.6 KiB
Python

"""Table-driven PVCheck tests using the legacy EFM's own comment examples."""
import pytest
from dx_productivity.features.bom import pv_check
# (part_number, description, expected_description_contains)
RESISTOR_CASES = [
# VBScript comments: '10A2=1.02R 12A0=1.2R 10A0=1R
("410000010A20", "1.02R 1% RES", False),
("410000010A20", "1.0R 1% RES", True),
("410000012A00", "1.2R", False),
("410000010A00", "1R", False),
# '10D2=0.00102R 12D0=0.0012R 10D0=0.001R
("410000010D20", "0.00102R", False),
("410000012D00", "0.0012R", False),
("410000010D00", "0.001R", False),
# '1002=10.2R 1000=10R 0000=0R
("410000010020", "10.2R", False),
("410000010000", "10R", False),
# '1012=102R
("410000010120", "102R", False),
# '1022=1.02K 1220=1.2K 1020=1K
("410000010220", "1.02K", False),
("410000012200", "1.2K", False),
("410000010200", "1K", False),
# '1032=10.2K 1030=10K
("410000010320", "10.2K", False),
("410000010300", "10K", False),
# '1042=102K
("410000010420", "102K", False),
# '1052=1.02M 1250=1.2M 1050=1M
("410000010520", "1.02M", False),
("410000012500", "1.2M", False),
("410000010500", "1M", False),
# '1062=10.2M 1060=10M
("410000010620", "10.2M", False),
("410000010600", "10M", False),
]
CAPACITOR_CASES = [
# '12B=0.12P 10B=0.1P
("430000012B00", "0.12P", False),
("430000010B00", "0.1P", False),
# '12A=1.2P 10A=1P
("430000012A00", "1.2P", False),
("430000010A00", "1P", False),
# '100=10P 101=100P
("430000010000", "10P", False),
("430000010100", "100P", False),
# '122=1.2N 102=1N 103=10N 104=100N
("430000012200", "1.2N", False),
("430000010200", "1N", False),
("430000010300", "10N", False),
("430000010400", "100N", False),
# '475=4.7U 105=1U 106=10U 107=100U 108=1000U
("430000047500", "4.7U", False),
("430000010500", "1U", False),
("430000010600", "10U", False),
("430000010700", "100U", False),
("430000010800", "1000U", False),
]
COIL_CASES = [
# '47D=4.7N 10D=1N 12C=12N 12B=120N
("480000047D00", "4.7N", False),
("480000010D00", "1N", False),
("480000012C00", "12N", False),
("480000012B00", "120N", False),
# '47A=4.7U 10A=1U 100=10U 101=100U
("480000047A00", "4.7U", False),
("480000010A00", "1U", False),
("480000010000", "10U", False),
("480000010100", "100U", False),
# '122=1.2M 102=1M 103=10M 104=100M
("480000012200", "1.2M", False),
("480000010200", "1M", False),
("480000010300", "10M", False),
("480000010400", "100M", False),
]
@pytest.mark.parametrize(
"part_number,description",
[(pn, desc) for pn, desc, flag in RESISTOR_CASES if not flag],
)
def test_resistor_matching_descriptions_pass(part_number, description):
mismatch, _ = pv_check(part_number, description)
assert mismatch is False
@pytest.mark.parametrize("part_number,description,should_flag", RESISTOR_CASES)
def test_resistor_flag_expectation(part_number, description, should_flag):
mismatch, _ = pv_check(part_number, description)
assert mismatch is should_flag
@pytest.mark.parametrize("part_number,description", [(p, d) for p, d, _ in CAPACITOR_CASES])
def test_capacitor_matching_descriptions_pass(part_number, description):
mismatch, _ = pv_check(part_number, description)
assert mismatch is False
@pytest.mark.parametrize("part_number,description", [(p, d) for p, d, _ in COIL_CASES])
def test_coil_matching_descriptions_pass(part_number, description):
mismatch, _ = pv_check(part_number, description)
assert mismatch is False
def test_wrong_value_is_flagged():
mismatch, reason = pv_check("410000010A20", "4.7R 1%")
assert mismatch is True
assert "1.02R" in reason
def test_precision_mismatch_is_flagged():
# tail 2200 => 1% expected; description says %1 but not 1%
mismatch, reason = pv_check("410000010A2200", "1.02R %1")
assert mismatch is True
assert "精度" in reason
def test_precision_match_passes():
mismatch, _ = pv_check("410000010A2200", "1.02R 1%")
assert mismatch is False
def test_xx_part_numbers_are_skipped():
mismatch, _ = pv_check("41XX00010A20", "anything")
assert mismatch is False
def test_use_descriptions_are_skipped():
mismatch, _ = pv_check("410000010A20", "USE AS JUMPER")
assert mismatch is False
def test_unknown_prefix_passes():
mismatch, _ = pv_check("990000010A20", "whatever")
assert mismatch is False
def test_short_description_passes():
# legacy guard: Len(PartVal) > 1
mismatch, _ = pv_check("410000010A20", "R")
assert mismatch is False