1 # -*- coding: utf-8 -*-
3 # Various small unit tests
7 #from youtube_dl.utils import htmlentity_transform
8 from youtube_dl.utils import timeconvert
9 from youtube_dl.utils import sanitize_filename
10 from youtube_dl.utils import unescapeHTML
11 from youtube_dl.utils import orderedSet
14 class TestUtil(unittest.TestCase):
15 def test_timeconvert(self):
16 self.assertTrue(timeconvert('') is None)
17 self.assertTrue(timeconvert('bougrg') is None)
19 def test_sanitize_filename(self):
20 self.assertEqual(sanitize_filename(u'abc'), u'abc')
21 self.assertEqual(sanitize_filename(u'abc_d-e'), u'abc_d-e')
23 self.assertEqual(sanitize_filename(u'123'), u'123')
25 self.assertEqual(u'abc-de', sanitize_filename(u'abc/de'))
26 self.assertFalse(u'/' in sanitize_filename(u'abc/de///'))
28 self.assertEqual(u'abc-de', sanitize_filename(u'abc/<>\\*|de'))
29 self.assertEqual(u'xxx', sanitize_filename(u'xxx/<>\\*|'))
30 self.assertEqual(u'yes no', sanitize_filename(u'yes? no'))
31 self.assertEqual(u'this - that', sanitize_filename(u'this: that'))
33 self.assertEqual(sanitize_filename(u'ä'), u'ä')
34 self.assertEqual(sanitize_filename(u'кириллица'), u'кириллица')
36 for forbidden in u'"\0\\/':
37 self.assertTrue(forbidden not in sanitize_filename(forbidden))
39 def test_ordered_set(self):
40 self.assertEqual(orderedSet([1,1,2,3,4,4,5,6,7,3,5]), [1,2,3,4,5,6,7])
41 self.assertEqual(orderedSet([]), [])
42 self.assertEqual(orderedSet([1]), [1])
43 #keep the list ordered
44 self.assertEqual(orderedSet([135,1,1,1]), [135,1])
46 def test_unescape_html(self):
47 self.assertEqual(unescapeHTML(u"%20;"), u"%20;")