utils_test.py 1.5 KB

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