From b29fc79969f463791ea86163dd980599c62ee134 Mon Sep 17 00:00:00 2001 From: helly25 Date: Fri, 6 Sep 2024 19:07:18 +0000 Subject: [PATCH] The `ActioByteSize` does not allow an empty string. That should lead to `argument flag: value cannot be empty.` covered in test: 'Unit only is invalid.'.' --- mbo/app/flags.py | 2 ++ mbo/app/flags_test.py | 25 +++++++++++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/mbo/app/flags.py b/mbo/app/flags.py index 9adb3ec..5115a4b 100644 --- a/mbo/app/flags.py +++ b/mbo/app/flags.py @@ -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) diff --git a/mbo/app/flags_test.py b/mbo/app/flags_test.py index 6febc64..a600972 100644 --- a/mbo/app/flags_test.py +++ b/mbo/app/flags_test.py @@ -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.", @@ -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],