Persist recovered ferrite Z by comparing against the raw JSON.
ComponentModel validation already fills impedance from quoted ohm@freq, so snapshotting the in-memory specs skipped the write.
This commit is contained in:
@@ -182,8 +182,9 @@ def _load_component_models(
|
||||
from backend.periscopex.ferrite_z import find_mpn_pdf, recover_bead_specs
|
||||
|
||||
pdf = find_mpn_pdf(model.mpn, *pdf_dirs)
|
||||
before_z = getattr(specs, "impedance_ohm", None)
|
||||
before_h = getattr(specs, "value_henries", None)
|
||||
raw_specs = raw.get("specs") if isinstance(raw.get("specs"), dict) else {}
|
||||
before_z = raw_specs.get("impedance_ohm")
|
||||
before_h = raw_specs.get("value_henries")
|
||||
filled = recover_bead_specs(specs, extra_text=json.dumps(raw), pdf_path=pdf)
|
||||
if filled.impedance_ohm != before_z or filled.value_henries != before_h:
|
||||
try:
|
||||
|
||||
@@ -220,6 +220,30 @@ def test_bead_mpn_datasheet_pdf_fills_z(tmp_path: Path):
|
||||
assert "100" in (persisted["specs"].get("value_formatted") or "")
|
||||
|
||||
|
||||
def test_bead_live_json_persist_unstuffs_henries(tmp_path: Path):
|
||||
models = tmp_path / "models"
|
||||
models.mkdir()
|
||||
payload = {
|
||||
"mpn": "BLM21PG121SN1D",
|
||||
"specs": {
|
||||
"specs_type": "inductor",
|
||||
"component_subtype": "passive.ferrite_bead",
|
||||
"value_henries": 120.0,
|
||||
"value_formatted": "120 ohm @ 100 MHz",
|
||||
"package": "0805",
|
||||
"current_rating_a": "3A",
|
||||
"dcr_ohms": 0.03,
|
||||
},
|
||||
}
|
||||
(models / "BLM21PG121SN1D.json").write_text(json.dumps(payload) + "\n")
|
||||
loaded = _load_component_models(models)
|
||||
assert loaded["BLM21PG121SN1D"].impedance_ohm == 120.0
|
||||
assert loaded["BLM21PG121SN1D"].value_henries is None
|
||||
persisted = json.loads((models / "BLM21PG121SN1D.json").read_text())
|
||||
assert persisted["specs"]["impedance_ohm"] == 120.0
|
||||
assert persisted["specs"]["value_henries"] is None
|
||||
|
||||
|
||||
def test_bead_mpn_datasheet_pdf_without_z_does_not_invent(tmp_path: Path):
|
||||
models = tmp_path / "models"
|
||||
models.mkdir()
|
||||
|
||||
Reference in New Issue
Block a user