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.

47 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.assertTrue(timeconvert('') is None)
  12. self.assertTrue(timeconvert('bougrg') is None)
  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.assertFalse(u'/' in sanitize_filename(u'abc/de///'))
  19. self.assertEqual(u'abc-de', sanitize_filename(u'abc/<>\\*|de'))
  20. self.assertEqual(u'xxx', sanitize_filename(u'xxx/<>\\*|'))
  21. self.assertEqual(u'yes no', sanitize_filename(u'yes? no'))
  22. self.assertEqual(u'this - that', sanitize_filename(u'this: that'))
  23. self.assertEqual(sanitize_filename(u'ä'), u'ä')
  24. self.assertEqual(sanitize_filename(u'кириллица'), u'кириллица')
  25. for forbidden in u'"\0\\/':
  26. self.assertTrue(forbidden not in sanitize_filename(forbidden))
  27. def test_ordered_set(self):
  28. self.assertEqual(orderedSet([1,1,2,3,4,4,5,6,7,3,5]), [1,2,3,4,5,6,7])
  29. self.assertEqual(orderedSet([]), [])
  30. self.assertEqual(orderedSet([1]), [1])
  31. #keep the list ordered
  32. self.assertEqual(orderedSet([135,1,1,1]), [135,1])
  33. def test_unescape_html(self):
  34. self.assertEqual(unescapeHTML(u"%20;"), u"%20;")