From 6e38dd2aeedaedfdfb3992ca40be6362788e33dc Mon Sep 17 00:00:00 2001 From: Timothy Willard <9395586+TimothyWillard@users.noreply.github.com> Date: Mon, 25 Nov 2024 13:56:24 -0500 Subject: [PATCH] Assume unitless numbers are in default unit Bug in `MemoryParamType.convert` was failing if a unit was not given with a value. Similar to `DurationParamType` it assumes that numbers without a unit are given in the default unit of the type. --- flepimop/gempyor_pkg/src/gempyor/shared_cli.py | 2 +- .../tests/shared_cli/test_memory_param_type_class.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/flepimop/gempyor_pkg/src/gempyor/shared_cli.py b/flepimop/gempyor_pkg/src/gempyor/shared_cli.py index 230839784..4d613496e 100644 --- a/flepimop/gempyor_pkg/src/gempyor/shared_cli.py +++ b/flepimop/gempyor_pkg/src/gempyor/shared_cli.py @@ -318,7 +318,7 @@ def convert( if (m := self._regex.match(value)) is None: self.fail(f"{value!r} is not a valid memory size.", param, ctx) number, _, _, unit = m.groups() - unit = unit.lower() + unit = self._unit if unit is None else unit.lower() if unit == self._unit: result = float(number) else: diff --git a/flepimop/gempyor_pkg/tests/shared_cli/test_memory_param_type_class.py b/flepimop/gempyor_pkg/tests/shared_cli/test_memory_param_type_class.py index f3c60e504..53c3558ce 100644 --- a/flepimop/gempyor_pkg/tests/shared_cli/test_memory_param_type_class.py +++ b/flepimop/gempyor_pkg/tests/shared_cli/test_memory_param_type_class.py @@ -57,6 +57,10 @@ def test_convert_acts_as_identity(unit: str, as_int: bool, number: int | float) ("kb", True, "2tb", 2147483648), ("mb", False, "0.1gb", 0.1 * 1024.0), ("mb", True, "0.1gb", 103), + ("gb", False, "4", 4.0), + ("gb", True, "4", 4), + ("mb", False, "1234.56", 1234.56), + ("mb", True, "1234.56", 1235), ), ) def test_exact_results_for_select_inputs(