data_size_to_bytes_test.py 961 B

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