data_size_to_bytes_test.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import pytest
  2. import free_disk
  3. # pylint: disable=protected-access; tests
  4. @pytest.mark.parametrize(
  5. ("data_size_with_unit", "expected_bytes"),
  6. [
  7. ("123", 123),
  8. ("123B", 123),
  9. ("123.0B", 123),
  10. ("1kB", 1000),
  11. ("2kB", 2000),
  12. ("2.5kB", 2500),
  13. ("2KB", 2000),
  14. ("8MB", 8 * (10**6)),
  15. ("8.5MB", 8.5 * (10**6)),
  16. ("32GB", 32 * (10**9)),
  17. ("9TB", 9 * (10**12)),
  18. ("3KiB", 3 * (1024**1)),
  19. ("40MiB", 40 * (1024**2)),
  20. ("512GiB", 512 * (1024**3)),
  21. ("7TiB", 7 * (1024**4)),
  22. ("123 B", 123),
  23. ("123\tB", 123),
  24. ("123.0 B", 123),
  25. ("1 kB", 1000),
  26. ("1 MiB", 1024**2),
  27. ],
  28. )
  29. def test__data_size_to_bytes(data_size_with_unit: str, expected_bytes: int) -> None:
  30. assert expected_bytes == free_disk._data_size_to_bytes(data_size_with_unit)
  31. @pytest.mark.parametrize("data_size_with_unit", ["abcdef", "123G"])
  32. def test__data_size_to_bytes_fail(data_size_with_unit: str) -> None:
  33. with pytest.raises(ValueError):
  34. free_disk._data_size_to_bytes(data_size_with_unit)