fix(leakage): accept display flow units
This commit is contained in:
@@ -124,7 +124,9 @@ def _worker_evaluate(raw_ratios: np.ndarray) -> float:
|
|||||||
class LeakageIdentifier:
|
class LeakageIdentifier:
|
||||||
FLOW_UNIT_TO_M3S = {
|
FLOW_UNIT_TO_M3S = {
|
||||||
"m3/s": 1.0,
|
"m3/s": 1.0,
|
||||||
|
"m³/s": 1.0,
|
||||||
"m3/h": 1.0 / 3600.0,
|
"m3/h": 1.0 / 3600.0,
|
||||||
|
"m³/h": 1.0 / 3600.0,
|
||||||
"L/s": 1.0 / 1000.0,
|
"L/s": 1.0 / 1000.0,
|
||||||
"L/min": 1.0 / 60000.0,
|
"L/min": 1.0 / 60000.0,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
Reference in New Issue
Block a user