diff --git a/Whatsapp_Chat_Exporter/utility.py b/Whatsapp_Chat_Exporter/utility.py index fc97d33..04a0c67 100644 --- a/Whatsapp_Chat_Exporter/utility.py +++ b/Whatsapp_Chat_Exporter/utility.py @@ -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]) diff --git a/tests/test_utility.py b/tests/test_utility.py index c4d57f2..8ea2af4 100644 --- a/tests/test_utility.py +++ b/tests/test_utility.py @@ -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):