]> Raphaël G. Git Repositories - youtubedl/blobdiff - test/test_utils.py
debian/changelog: Start new release.
[youtubedl] / test / test_utils.py
index 84553b94386236352e9ad856782c4b3428f3587b..51eb0b6b936c7ea5d21cfef9bdc0b70f2ee7663a 100644 (file)
@@ -9,6 +9,8 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
 
 
 # Various small unit tests
 
 
 # Various small unit tests
+import io
+import json
 import xml.etree.ElementTree
 
 #from youtube_dl.utils import htmlentity_transform
 import xml.etree.ElementTree
 
 #from youtube_dl.utils import htmlentity_transform
@@ -21,6 +23,7 @@ from youtube_dl.utils import (
     orderedSet,
     PagedList,
     parse_duration,
     orderedSet,
     PagedList,
     parse_duration,
+    read_batch_urls,
     sanitize_filename,
     shell_quote,
     smuggle_url,
     sanitize_filename,
     shell_quote,
     smuggle_url,
@@ -31,7 +34,11 @@ from youtube_dl.utils import (
     unified_strdate,
     unsmuggle_url,
     url_basename,
     unified_strdate,
     unsmuggle_url,
     url_basename,
+    urlencode_postdata,
     xpath_with_ns,
     xpath_with_ns,
+    parse_iso8601,
+    strip_jsonp,
+    uppercase_escape,
 )
 
 if sys.version_info < (3, 0):
 )
 
 if sys.version_info < (3, 0):
@@ -250,5 +257,32 @@ class TestUtil(unittest.TestCase):
     def test_struct_unpack(self):
         self.assertEqual(struct_unpack(u'!B', b'\x00'), (0,))
 
     def test_struct_unpack(self):
         self.assertEqual(struct_unpack(u'!B', b'\x00'), (0,))
 
+    def test_read_batch_urls(self):
+        f = io.StringIO(u'''\xef\xbb\xbf foo
+            bar\r
+            baz
+            # More after this line\r
+            ; or after this
+            bam''')
+        self.assertEqual(read_batch_urls(f), [u'foo', u'bar', u'baz', u'bam'])
+
+    def test_urlencode_postdata(self):
+        data = urlencode_postdata({'username': 'foo@bar.com', 'password': '1234'})
+        self.assertTrue(isinstance(data, bytes))
+
+    def test_parse_iso8601(self):
+        self.assertEqual(parse_iso8601('2014-03-23T23:04:26+0100'), 1395612266)
+        self.assertEqual(parse_iso8601('2014-03-23T22:04:26+0000'), 1395612266)
+        self.assertEqual(parse_iso8601('2014-03-23T22:04:26Z'), 1395612266)
+
+    def test_strip_jsonp(self):
+        stripped = strip_jsonp('cb ([ {"id":"532cb",\n\n\n"x":\n3}\n]\n);')
+        d = json.loads(stripped)
+        self.assertEqual(d, [{"id": "532cb", "x": 3}])
+
+    def test_uppercase_escpae(self):
+        self.assertEqual(uppercase_escape(u'aä'), u'aä')
+        self.assertEqual(uppercase_escape(u'\\U0001d550'), u'𝕐')
+
 if __name__ == '__main__':
     unittest.main()
 if __name__ == '__main__':
     unittest.main()