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.

46 lines
1.6 KiB

  1. # -*- coding: utf-8 -*-
  2. # Various small unit tests
  3. import unittest
  4. #from youtube_dl.utils import htmlentity_transform
  5. from youtube_dl.utils import timeconvert
  6. from youtube_dl.utils import sanitize_filename
  7. from youtube_dl.utils import unescapeHTML
  8. from youtube_dl.utils import orderedSet
  9. class TestUtil(unittest.TestCase):
  10. def test_timeconvert(self):
  11. self.assertIsNone(timeconvert(''))
  12. self.assertIsNone(timeconvert('bougrg'))
  13. def test_sanitize_filename(self):
  14. self.assertEqual(sanitize_filename(u'abc'), u'abc')
  15. self.assertEqual(sanitize_filename(u'abc_d-e'), u'abc_d-e')
  16. self.assertEqual(sanitize_filename(u'123'), u'123')
  17. self.assertEqual(u'abc_de', sanitize_filename(u'abc/de'))
  18. self.assertIn(u'de', sanitize_filename(u'abc/de'))
  19. self.assertNotIn(u'/', sanitize_filename(u'abc/de///'))
  20. self.assertEqual(u'abc_de', sanitize_filename(u'abc\\de'))
  21. self.assertEqual(u'abc_de', sanitize_filename(u'abc\\de'))
  22. self.assertIn(u'de', sanitize_filename(u'abc\\de'))
  23. self.assertEqual(sanitize_filename(u'ä'), u'ä')
  24. self.assertEqual(sanitize_filename(u'кириллица'), u'кириллица')
  25. def test_ordered_set(self):
  26. self.assertEqual(orderedSet([1,1,2,3,4,4,5,6,7,3,5]), [1,2,3,4,5,6,7])
  27. self.assertEqual(orderedSet([]), [])
  28. self.assertEqual(orderedSet([1]), [1])
  29. #keep the list ordered
  30. self.assertEqual(orderedSet([135,1,1,1]), [135,1])
  31. def test_unescape_html(self):
  32. self.assertEqual(unescapeHTML(u"%20;"), u"%20;")