- pyproject.toml: add [tool.ruff] config suppressing E402/W293 globally, F841/E741/E702 in tests, E741 in scripts - inventory.py: split semicolon import (E702) - recipes.py: fix logger -> log (F821 undefined name) - shopping.py: rename l -> lnk in list comprehension (E741) - format_conversion.py: noqa F841 on CUDA flag (used as future hook) - backfill_keywords.py: rename done -> _done (F841) - ingest_purplecarrot.py: drop == True comparison (E712) - Auto-fix: I001 import sorting, F401 unused imports across all files
23 lines
1.1 KiB
Python
23 lines
1.1 KiB
Python
import sys
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).parents[2]))
|
|
|
|
def test_normalize_ingredient_name():
|
|
from scripts.pipeline.build_ingredient_index import normalize_name
|
|
assert normalize_name("Ground Beef (85% lean)") == "ground beef"
|
|
assert normalize_name(" Olive Oil ") == "olive oil"
|
|
assert normalize_name("Cheddar Cheese, shredded") == "cheddar cheese"
|
|
|
|
def test_derive_elements_from_usda_row():
|
|
from scripts.pipeline.build_ingredient_index import derive_elements
|
|
row = {"fat_pct": 20.0, "protein_pct": 17.0, "moisture_pct": 60.0,
|
|
"sodium_mg_per_100g": 65.0, "glutamate_mg": 2.8, "starch_pct": 0.0}
|
|
elements = derive_elements(row)
|
|
assert "Richness" in elements # high fat
|
|
assert "Depth" in elements # notable glutamate
|
|
|
|
def test_derive_binding_score():
|
|
from scripts.pipeline.build_ingredient_index import derive_binding_score
|
|
assert derive_binding_score({"protein_pct": 12.0, "starch_pct": 68.0}) == 3 # flour
|
|
assert derive_binding_score({"protein_pct": 1.0, "starch_pct": 0.5}) == 0 # water
|