utils_test.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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(1024) == '1 kB'
  23. def test_1023b(self):
  24. assert human_readable_file_size(1023) == '1023 B'
  25. def test_units(self):
  26. assert human_readable_file_size((2 ** 10) ** 0) == '1 B'
  27. assert human_readable_file_size((2 ** 10) ** 1) == '1 kB'
  28. assert human_readable_file_size((2 ** 10) ** 2) == '1 MB'
  29. assert human_readable_file_size((2 ** 10) ** 3) == '1 GB'
  30. assert human_readable_file_size((2 ** 10) ** 4) == '1 TB'
  31. assert human_readable_file_size((2 ** 10) ** 5) == '1 PB'
  32. assert human_readable_file_size((2 ** 10) ** 6) == '1 EB'