Skip to content

Commit

Permalink
The ActioByteSize does not allow an empty string. That should lead …
Browse files Browse the repository at this point in the history
…to `argument flag: value cannot be empty.` covered in test: 'Unit only is invalid.'.'
  • Loading branch information
helly25 committed Sep 6, 2024
1 parent 6ed8527 commit b29fc79
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
2 changes: 2 additions & 0 deletions mbo/app/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,8 @@ def ParseByteSize(
f"value does not match pattern (not a valid byte size), got '{original}'."
)
number = match.group(1)
if number == "":
raise ValueError("value cannot be empty.")
if number == ".":
raise ValueError("value cannot be '.'.")
result = float(number) if number.find(".") > -1 else int(number)
Expand Down
25 changes: 17 additions & 8 deletions mbo/app/flags_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,22 +678,22 @@ def test_ActionDateTimeOrTimeDelta(self, test: FlagTestData):
@parameterized.expand(
[
FlagTestData(
test="Parse empty.",
expected="argument flag: value must not be empty.",
expected_error=argparse.ArgumentError,
test="Parse default None.",
expected=None,
action=ActionArgs(
action=mbo.app.flags.ActionByteSize,
nargs="?",
),
input=[""],
input=[],
),
FlagTestData(
test="Parse default None.",
expected=None,
test="Parse empty.",
expected="argument flag: value must not be empty.",
expected_error=argparse.ArgumentError,
action=ActionArgs(
action=mbo.app.flags.ActionByteSize,
nargs="?",
),
input=[],
input=[""],
),
FlagTestData(
test="Parse default value.",
Expand Down Expand Up @@ -723,6 +723,15 @@ def test_ActionDateTimeOrTimeDelta(self, test: FlagTestData):
),
input=["0"],
),
FlagTestData(
test="Unit only is invalid.",
expected="argument flag: value cannot be empty.",
expected_error=argparse.ArgumentError,
action=ActionArgs(
action=mbo.app.flags.ActionByteSize,
),
input=["B"],
),
FlagTestData(
test="Parse zero bytes.",
expected=[0, 0, 0, 0, 0],
Expand Down

0 comments on commit b29fc79

Please sign in to comment.