You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.9 KiB

  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """Contains test cases for the utils.py module."""
  4. from __future__ import unicode_literals
  5. import sys
  6. import os.path
  7. import unittest
  8. PATH = os.path.realpath(os.path.abspath(__file__))
  9. sys.path.insert(0, os.path.dirname(os.path.dirname(PATH)))
  10. try:
  11. from youtube_dl_gui import utils
  12. except ImportError as error:
  13. print error
  14. sys.exit(1)
  15. class TestToBytes(unittest.TestCase):
  16. """Test case for the to_bytes method."""
  17. def test_to_bytes_bytes(self):
  18. self.assertEqual(utils.to_bytes("596.00B"), 596.00)
  19. self.assertEqual(utils.to_bytes("133.55B"), 133.55)
  20. def test_to_bytes_kilobytes(self):
  21. self.assertEqual(utils.to_bytes("1.00KiB"), 1024.00)
  22. self.assertEqual(utils.to_bytes("5.55KiB"), 5683.20)
  23. def test_to_bytes_megabytes(self):
  24. self.assertEqual(utils.to_bytes("13.64MiB"), 14302576.64)
  25. self.assertEqual(utils.to_bytes("1.00MiB"), 1048576.00)
  26. def test_to_bytes_gigabytes(self):
  27. self.assertEqual(utils.to_bytes("1.00GiB"), 1073741824.00)
  28. self.assertEqual(utils.to_bytes("1.55GiB"), 1664299827.20)
  29. def test_to_bytes_terabytes(self):
  30. self.assertEqual(utils.to_bytes("1.00TiB"), 1099511627776.00)
  31. class TestFormatBytes(unittest.TestCase):
  32. """Test case for the format_bytes method."""
  33. def test_format_bytes_bytes(self):
  34. self.assertEqual(utils.format_bytes(518.00), "518.00B")
  35. def test_format_bytes_kilobytes(self):
  36. self.assertEqual(utils.format_bytes(1024.00), "1.00KiB")
  37. def test_format_bytes_megabytes(self):
  38. self.assertEqual(utils.format_bytes(1048576.00), "1.00MiB")
  39. def test_format_bytes_gigabytes(self):
  40. self.assertEqual(utils.format_bytes(1073741824.00), "1.00GiB")
  41. def test_format_bytes_terabytes(self):
  42. self.assertEqual(utils.format_bytes(1099511627776.00), "1.00TiB")
  43. def main():
  44. unittest.main()
  45. if __name__ == "__main__":
  46. main()