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"