feat: Stoff-Bezeichnungen editieren und BLS-Glossar fuellen
Kryptische Schluessel bleiben Identitaet; Namen/Einheit sind aenderbar. Nur ENERCC/PROT625/FAT/CHO schreiben die Makro-Haupttabelle. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
e452d9a8fe
commit
94ddf84262
13 files changed
+586
-29
No files matched your search
@@ -0,0 +1,40 @@
|
||||
from bls.attribute_labels import (
|
||||
apply_official_name,
|
||||
fill_placeholder_labels,
|
||||
label_is_placeholder,
|
||||
official_label,
|
||||
)
|
||||
|
||||
|
||||
def test_official_macro_labels():
|
||||
assert official_label("ENERCC")["name_de"].startswith("Energie")
|
||||
assert official_label("cho")["name_de"].startswith("Kohlenhydrate")
|
||||
assert label_is_placeholder("ENERCC", "ENERCC")
|
||||
assert label_is_placeholder("", "FAT")
|
||||
assert not label_is_placeholder("Fett", "FAT")
|
||||
assert apply_official_name("FAT", "FAT") == "Fett"
|
||||
assert apply_official_name("FAT", "Fett gesamt") == "Fett gesamt"
|
||||
|
||||
|
||||
def test_fill_placeholder_labels_skips_custom_names():
|
||||
class _Cur:
|
||||
def __init__(self):
|
||||
self.rows = [
|
||||
{"id": 1, "attr_key": "FAT", "name_de": "FAT", "unit": None, "category": None},
|
||||
{"id": 2, "attr_key": "EPA", "name_de": "Mein EPA", "unit": "g", "category": None},
|
||||
]
|
||||
self.updated = []
|
||||
|
||||
def execute(self, sql, params=None):
|
||||
self.last = (sql, params)
|
||||
if "UPDATE" in sql:
|
||||
self.updated.append(params)
|
||||
|
||||
def fetchall(self):
|
||||
return self.rows
|
||||
|
||||
cur = _Cur()
|
||||
stats = fill_placeholder_labels(cur)
|
||||
assert stats["updated"] == 1
|
||||
assert cur.updated[0][0] == "Fett"
|
||||
assert cur.updated[0][3] == 1
|
||||
@@ -30,6 +30,18 @@ def test_parse_components_dynamic():
|
||||
assert "NA" in keys
|
||||
|
||||
|
||||
def test_parse_components_official_bezeichnung_and_empty_name():
|
||||
data = _xlsx([
|
||||
["Component code", "Bezeichnung", "English", "Einheit"],
|
||||
["PROT625", "", "Protein", "g/100g"],
|
||||
["FAT", "Fett", "Fat", "g/100g"],
|
||||
])
|
||||
attrs = parse_components_xlsx(data)
|
||||
by_key = {a["attr_key"]: a for a in attrs}
|
||||
assert by_key["PROT625"]["name_de"] == "Protein (N×6,25)"
|
||||
assert by_key["FAT"]["name_de"] == "Fett"
|
||||
|
||||
|
||||
def test_parse_foods_keeps_bls_code():
|
||||
data = _xlsx([
|
||||
["BLS Code", "Name", "Food name", "ENERCC Energie [kcal/100g]", "ENERCC Herkunft", "ENERCC Referenz"],
|
||||
|
||||
Reference in new issue
Block a user