Skip to content

Commit

Permalink
Assume unitless numbers are in default unit
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TimothyWillard committed Nov 25, 2024
1 parent 0fa1f9b commit 6e38dd2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion flepimop/gempyor_pkg/src/gempyor/shared_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 6e38dd2

Please sign in to comment.