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