data_size_to_bytes_test.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import pytest
  2. import free_disk
  3. @pytest.mark.parametrize(
  4. ("data_size_with_unit", "expected_bytes"),
  5. [
  6. ("123", 123),
  7. ("123B", 123),
  8. ("123.0B", 123),
  9. ("1kB", 1000),
  10. ("2kB", 2000),
  11. ("2.5kB", 2500),
  12. ("2KB", 2000),
  13. ("8MB", 8 * (10 ** 6)),
  14. ("8.5MB", 8.5 * (10 ** 6)),
  15. ("32GB", 32 * (10 ** 9)),
  16. ("9TB", 9 * (10 ** 12)),
  17. ("3KiB", 3 * (1024 ** 1)),
  18. ("40MiB", 40 * (1024 ** 2)),
  19. ("512GiB", 512 * (1024 ** 3)),
  20. ("7TiB", 7 * (1024 ** 4)),
  21. ("123 B", 123),
  22. ("123\tB", 123),
  23. ("123.0 B", 123),
  24. ("1 kB", 1000),
  25. ("1 MiB", 1024 ** 2),
  26. ],
  27. )
  28. def test_data_size_to_bytes(data_size_with_unit, expected_bytes):
  29. assert expected_bytes == free_disk.data_size_to_bytes(data_size_with_unit)
  30. @pytest.mark.parametrize("data_size_with_unit", ["abcdef", "123G",])
  31. def test_data_size_to_bytes_fail(data_size_with_unit):
  32. with pytest.raises(ValueError):
  33. free_disk.data_size_to_bytes(data_size_with_unit)