File size: 1,437 Bytes
1bb570d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | from __future__ import annotations
import importlib.util
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
SPEC = importlib.util.spec_from_file_location(
"convert_wisemoor", ROOT / "scripts/convert_wisemoor_to_training_candidates.py"
)
assert SPEC and SPEC.loader
MODULE = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(MODULE)
def test_wisemoor_description_survives_candidate_conversion():
record = {
"product_id": 7,
"name": "Observed formula",
"description": "A source-observed floral woody description.",
"notes": ["source note"],
"slug": "observed-formula",
"source_url": "https://example.test/formula/7",
"formula": {"formula_rows": [
{"ingredient": "benzyl acetate", "amount": 40},
{"ingredient": "linalool", "amount": 30},
{"ingredient": "vanillin", "amount": 30},
]},
}
candidate, audit = MODULE.convert_record(
record,
mapping={
"benzyl acetate": "140-11-4",
"linalool": "78-70-6",
"vanillin": "121-33-5",
},
min_row_coverage=1.0,
min_amount_coverage=1.0,
min_resolved_components=3,
)
assert audit["accepted"] is True
assert candidate["description"] == record["description"]
assert candidate["metadata"]["description_provenance"] == "source_observed_wisemoor_product_text"
|