utils_test.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. from __future__ import absolute_import
  2. from __future__ import unicode_literals
  3. import unittest
  4. from compose.cli.utils import human_readable_file_size
  5. from compose.utils import unquote_path
  6. class UnquotePathTest(unittest.TestCase):
  7. def test_no_quotes(self):
  8. assert unquote_path('hello') == 'hello'
  9. def test_simple_quotes(self):
  10. assert unquote_path('"hello"') == 'hello'
  11. def test_uneven_quotes(self):
  12. assert unquote_path('"hello') == '"hello'
  13. assert unquote_path('hello"') == 'hello"'
  14. def test_nested_quotes(self):
  15. assert unquote_path('""hello""') == '"hello"'
  16. assert unquote_path('"hel"lo"') == 'hel"lo'
  17. assert unquote_path('"hello""') == 'hello"'
  18. class HumanReadableFileSizeTest(unittest.TestCase):
  19. def test_100b(self):
  20. assert human_readable_file_size(100) == '100 B'
  21. def test_1kb(self):
  22. assert human_readable_file_size(1000) == '1 kB'
  23. assert human_readable_file_size(1024) == '1.024 kB'
  24. def test_1023b(self):
  25. assert human_readable_file_size(1023) == '1.023 kB'
  26. def test_999b(self):
  27. assert human_readable_file_size(999) == '999 B'
  28. def test_units(self):
  29. assert human_readable_file_size((10 ** 3) ** 0) == '1 B'
  30. assert human_readable_file_size((10 ** 3) ** 1) == '1 kB'
  31. assert human_readable_file_size((10 ** 3) ** 2) == '1 MB'
  32. assert human_readable_file_size((10 ** 3) ** 3) == '1 GB'
  33. assert human_readable_file_size((10 ** 3) ** 4) == '1 TB'
  34. assert human_readable_file_size((10 ** 3) ** 5) == '1 PB'
  35. assert human_readable_file_size((10 ** 3) ** 6) == '1 EB'