feat(workflows): Update CI configuration and enhance testing conditions
- Added workflow_run triggers for "Deploy Development" and "Deploy Production" to ensure tests run only after successful deployments. - Updated Python version in CI from 3.12 to 3.11 for better compatibility with the Debian 12 ARM64 runner. - Enhanced job conditions to skip tests on failed workflow runs. - Improved frontend build process by updating Node.js setup and ensuring correct directory navigation. - Refined CSV parsing logic to handle custom and unknown source units, enhancing conversion flexibility. - Added new tests for custom source unit handling in CSV conversions, ensuring accurate processing.
This commit is contained in:
1 parent
d6d7e738a5
commit
0d0ab62674
5 files changed
+53
-9
No files matched your search
@@ -83,12 +83,17 @@ def factor_source_to_canonical(module: str, db_field: str, source_unit: str | No
|
||||
"""
|
||||
Multiplikator: CSV-Zahl * Faktor → Wert in kanonischer DB-Einheit.
|
||||
Unbekannte/None/leer/Passthrough → 1.0
|
||||
|
||||
``source_unit`` ``custom`` / ``none``: kein Registry-Faktor (1.0); freie Skalierung nur über
|
||||
``conversion_factor`` in type_conversions (JSON).
|
||||
"""
|
||||
if source_unit is None:
|
||||
return 1.0
|
||||
su = str(source_unit).strip().lower()
|
||||
if not su:
|
||||
return 1.0
|
||||
if su in ("custom", "none"):
|
||||
return 1.0
|
||||
cu = get_canonical_unit(module, db_field)
|
||||
if not cu:
|
||||
return 1.0
|
||||
|
||||
@@ -312,8 +312,11 @@ def convert_value(
|
||||
- decimal_separator: ".", ",", "auto" — bei auto Heuristik EU/US-Mischformen.
|
||||
- formats: [ "yyyy-mm-dd", "%d.%m.%y", ... ] — weitere strptime-/Alias-Ketten.
|
||||
- dayfirst: true|false — nur für dateutil-Fallback; Standard: true dann false.
|
||||
- source_unit: z. B. "kj", "kg" — Quelleinheit; Ziel aus Modul-Feld (unit in module_registry);
|
||||
Faktor wird serverseitig ermittelt. Optional zusätzlich conversion_factor (legacy/zusätzlich).
|
||||
- source_unit: Registry-IDs (z. B. "kj", "kg") oder "custom"/"none" — letztere ohne
|
||||
vordefinierten Faktor; beliebige Skalierung dann nur über conversion_factor.
|
||||
- conversion_factor: Zusätzlicher Multiplikator nach dem Parsen (und nach source_unit);
|
||||
für nicht vordefinierte Umrechnungen source_unit weglassen oder "custom" setzen und
|
||||
hier den Faktor angeben.
|
||||
"""
|
||||
if spec is None:
|
||||
return raw.strip() if raw else None
|
||||
@@ -331,7 +334,7 @@ def convert_value(
|
||||
v = _float_from_spec(raw, spec)
|
||||
if module:
|
||||
su = spec.get("source_unit")
|
||||
if su is not None:
|
||||
if su is not None and str(su).strip() != "":
|
||||
v = float(v) * factor_source_to_canonical(module, db_field, str(su))
|
||||
factor = spec.get("conversion_factor")
|
||||
if factor is not None:
|
||||
|
||||
@@ -86,6 +86,19 @@ def test_convert_protein_kg_to_g():
|
||||
assert abs(g - 100.0) < 0.001
|
||||
|
||||
|
||||
def test_convert_custom_source_unit_only_conversion_factor():
|
||||
"""Nicht vordefinierte Umrechnung: conversion_factor (optional mit source_unit: custom)."""
|
||||
spec = {"type": "float", "source_unit": "custom", "conversion_factor": 2.5, "decimal_separator": "."}
|
||||
k = convert_value("100", "kcal", spec, module="nutrition")
|
||||
assert abs(k - 250.0) < 0.001
|
||||
|
||||
|
||||
def test_convert_unknown_source_unit_uses_conversion_factor_only():
|
||||
spec = {"type": "float", "source_unit": "exotic_unit", "conversion_factor": 0.5, "decimal_separator": "."}
|
||||
k = convert_value("200", "kcal", spec, module="nutrition")
|
||||
assert abs(k - 100.0) < 0.001
|
||||
|
||||
|
||||
def test_build_row_source_unit_without_module_no_factor():
|
||||
"""Ohne module bleibt source_unit wirkungslos (Abwärtskompatibilität)."""
|
||||
spec = {"type": "float", "source_unit": "kj", "decimal_separator": "."}
|
||||
|
||||
Reference in new issue
Block a user