Fix test cases

This commit is contained in:
KnugiHK
2025-06-01 12:15:54 +08:00
parent 0ecfe6c59a
commit f89f53cf2d
2 changed files with 3 additions and 5 deletions

View File

@@ -123,11 +123,9 @@ def readable_to_bytes(size_str: str) -> int:
# If the string is purely numeric, assume it's in bytes
return int(size_str)
if not match:
raise ValueError("Invalid size format. Expected format like '10MB', '1024GB', or '512'.")
raise ValueError("Invalid size format for size_str. Expected format like '10MB', '1024GB', or '512'.")
unit = ''.join(filter(str.isalpha, size_str)).strip()
number = ''.join(c for c in size_str if c.isdigit() or c == '.').strip()
if unit not in SIZE_UNITS:
raise ValueError("Invalid input for size_str. Example: 1024GB")
return int(float(number) * SIZE_UNITS[unit])

View File

@@ -66,13 +66,13 @@ class TestReadableToBytes:
assert readable_to_bytes(" 1 MB") == 1024**2
def test_invalid_unit(self):
with pytest.raises(ValueError, match="Invalid input for size_str"):
with pytest.raises(ValueError, match="Invalid size format for size_str"):
readable_to_bytes("100X")
readable_to_bytes("A100")
readable_to_bytes("100$$$$$")
def test_invalid_number(self):
with pytest.raises(ValueError, match="Invalid input for size_str"):
with pytest.raises(ValueError, match="Invalid size format for size_str"):
readable_to_bytes("ABC KB")
def test_missing_unit(self):