diff --git a/app/algorithms/leakage/identifier.py b/app/algorithms/leakage/identifier.py index c2044b1..6115d89 100644 --- a/app/algorithms/leakage/identifier.py +++ b/app/algorithms/leakage/identifier.py @@ -122,12 +122,14 @@ def _worker_evaluate(raw_ratios: np.ndarray) -> float: class LeakageIdentifier: - FLOW_UNIT_TO_M3S = { - "m3/s": 1.0, - "m3/h": 1.0 / 3600.0, - "L/s": 1.0 / 1000.0, - "L/min": 1.0 / 60000.0, - } + FLOW_UNIT_TO_M3S = { + "m3/s": 1.0, + "m³/s": 1.0, + "m3/h": 1.0 / 3600.0, + "m³/h": 1.0 / 3600.0, + "L/s": 1.0 / 1000.0, + "L/min": 1.0 / 60000.0, + } @classmethod def _flow_to_m3s(cls, value: float, unit: str) -> float: diff --git a/tests/unit/test_leakage_flow_units.py b/tests/unit/test_leakage_flow_units.py new file mode 100644 index 0000000..eea74a5 --- /dev/null +++ b/tests/unit/test_leakage_flow_units.py @@ -0,0 +1,50 @@ +import pytest +import importlib.util +import sys +import types +from pathlib import Path + + +def _load_leakage_identifier(): + algorithms_package = types.ModuleType("app.algorithms") + algorithms_package.__path__ = [] + utils_module = types.ModuleType("app.algorithms._utils") + utils_module._cleanup_temp_files = lambda *args, **kwargs: None + sys.modules["app.algorithms"] = algorithms_package + sys.modules["app.algorithms._utils"] = utils_module + + module_path = ( + Path(__file__).resolve().parents[2] + / "app" + / "algorithms" + / "leakage" + / "identifier.py" + ) + spec = importlib.util.spec_from_file_location( + "tests_leakage_identifier_under_test", module_path + ) + module = importlib.util.module_from_spec(spec) + assert spec and spec.loader + spec.loader.exec_module(module) + return module.LeakageIdentifier + + +@pytest.mark.parametrize( + ("unit", "expected"), + [ + ("m3/s", 1.0), + ("m³/s", 1.0), + ("m3/h", 3600.0), + ("m³/h", 3600.0), + ], +) +def test_leakage_identifier_accepts_display_flow_units(unit, expected): + LeakageIdentifier = _load_leakage_identifier() + + assert LeakageIdentifier._flow_from_m3s(1.0, unit) == expected + + +def test_leakage_identifier_accepts_display_flow_units_for_input(): + LeakageIdentifier = _load_leakage_identifier() + + assert LeakageIdentifier._flow_to_m3s(3600.0, "m³/h") == 1.0