import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'packages' / 'agromatrix-tools')) from agromatrix_tools import tool_dictionary from agromatrix_tools.normalize import parse_quantity, convert def test_synonym_match(): res = tool_dictionary.normalize_crop('озима пшениця', trace_id='t1') assert res['status'] == 'ok' assert res['normalized_id'] == 'crop_wheat_winter' def test_fuzzy_suggestions(): res = tool_dictionary.normalize_operation('посив', trace_id='t2') assert res['suggestions'] def test_pending_unknown(): res = tool_dictionary.normalize_field('невідоме поле', trace_id='t3') assert res['status'] == 'pending' def test_unit_conversion(): value, unit = parse_quantity('2,5 т') assert unit in ['т', 't'] from_dict = 't' to = 'kg' # simulate conversion assert convert(2.5, from_dict, to, [{'id':'t','to_base':{'base':'kg','factor':1000}}, {'id':'kg'}]) == 2500