diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/test_YoutubeDL.py | 116 | ||||
| -rw-r--r-- | test/test_aes.py | 55 | ||||
| -rw-r--r-- | test/test_all_urls.py | 12 | ||||
| -rw-r--r-- | test/test_execution.py | 9 | ||||
| -rw-r--r-- | test/test_http.py | 49 | ||||
| -rw-r--r-- | test/test_netrc.py | 26 | ||||
| -rw-r--r-- | test/test_postprocessors.py | 17 | ||||
| -rw-r--r-- | test/test_subtitles.py | 13 | ||||
| -rw-r--r-- | test/test_unicode_literals.py | 11 | ||||
| -rw-r--r-- | test/test_utils.py | 76 | 
10 files changed, 354 insertions, 30 deletions
| diff --git a/test/test_YoutubeDL.py b/test/test_YoutubeDL.py index 055e42555..652519831 100644 --- a/test/test_YoutubeDL.py +++ b/test/test_YoutubeDL.py @@ -14,6 +14,9 @@ from test.helper import FakeYDL, assertRegexpMatches  from youtube_dl import YoutubeDL  from youtube_dl.extractor import YoutubeIE  from youtube_dl.postprocessor.common import PostProcessor +from youtube_dl.utils import match_filter_func + +TEST_URL = 'http://localhost/sample.mp4'  class YDL(FakeYDL): @@ -46,8 +49,8 @@ class TestFormatSelection(unittest.TestCase):          ydl = YDL()          ydl.params['prefer_free_formats'] = True          formats = [ -            {'ext': 'webm', 'height': 460, 'url': 'x'}, -            {'ext': 'mp4', 'height': 460, 'url': 'y'}, +            {'ext': 'webm', 'height': 460, 'url': TEST_URL}, +            {'ext': 'mp4', 'height': 460, 'url': TEST_URL},          ]          info_dict = _make_result(formats)          yie = YoutubeIE(ydl) @@ -60,8 +63,8 @@ class TestFormatSelection(unittest.TestCase):          ydl = YDL()          ydl.params['prefer_free_formats'] = True          formats = [ -            {'ext': 'webm', 'height': 720, 'url': 'a'}, -            {'ext': 'mp4', 'height': 1080, 'url': 'b'}, +            {'ext': 'webm', 'height': 720, 'url': TEST_URL}, +            {'ext': 'mp4', 'height': 1080, 'url': TEST_URL},          ]          info_dict['formats'] = formats          yie = YoutubeIE(ydl) @@ -74,9 +77,9 @@ class TestFormatSelection(unittest.TestCase):          ydl = YDL()          ydl.params['prefer_free_formats'] = False          formats = [ -            {'ext': 'webm', 'height': 720, 'url': '_'}, -            {'ext': 'mp4', 'height': 720, 'url': '_'}, -            {'ext': 'flv', 'height': 720, 'url': '_'}, +            {'ext': 'webm', 'height': 720, 'url': TEST_URL}, +            {'ext': 'mp4', 'height': 720, 'url': TEST_URL}, +            {'ext': 'flv', 'height': 720, 'url': TEST_URL},          ]          info_dict['formats'] = formats          yie = YoutubeIE(ydl) @@ -88,8 +91,8 @@ class TestFormatSelection(unittest.TestCase):          ydl = YDL()          ydl.params['prefer_free_formats'] = False          formats = [ -            {'ext': 'flv', 'height': 720, 'url': '_'}, -            {'ext': 'webm', 'height': 720, 'url': '_'}, +            {'ext': 'flv', 'height': 720, 'url': TEST_URL}, +            {'ext': 'webm', 'height': 720, 'url': TEST_URL},          ]          info_dict['formats'] = formats          yie = YoutubeIE(ydl) @@ -133,10 +136,10 @@ class TestFormatSelection(unittest.TestCase):      def test_format_selection(self):          formats = [ -            {'format_id': '35', 'ext': 'mp4', 'preference': 1, 'url': '_'}, -            {'format_id': '45', 'ext': 'webm', 'preference': 2, 'url': '_'}, -            {'format_id': '47', 'ext': 'webm', 'preference': 3, 'url': '_'}, -            {'format_id': '2', 'ext': 'flv', 'preference': 4, 'url': '_'}, +            {'format_id': '35', 'ext': 'mp4', 'preference': 1, 'url': TEST_URL}, +            {'format_id': '45', 'ext': 'webm', 'preference': 2, 'url': TEST_URL}, +            {'format_id': '47', 'ext': 'webm', 'preference': 3, 'url': TEST_URL}, +            {'format_id': '2', 'ext': 'flv', 'preference': 4, 'url': TEST_URL},          ]          info_dict = _make_result(formats) @@ -167,10 +170,10 @@ class TestFormatSelection(unittest.TestCase):      def test_format_selection_audio(self):          formats = [ -            {'format_id': 'audio-low', 'ext': 'webm', 'preference': 1, 'vcodec': 'none', 'url': '_'}, -            {'format_id': 'audio-mid', 'ext': 'webm', 'preference': 2, 'vcodec': 'none', 'url': '_'}, -            {'format_id': 'audio-high', 'ext': 'flv', 'preference': 3, 'vcodec': 'none', 'url': '_'}, -            {'format_id': 'vid', 'ext': 'mp4', 'preference': 4, 'url': '_'}, +            {'format_id': 'audio-low', 'ext': 'webm', 'preference': 1, 'vcodec': 'none', 'url': TEST_URL}, +            {'format_id': 'audio-mid', 'ext': 'webm', 'preference': 2, 'vcodec': 'none', 'url': TEST_URL}, +            {'format_id': 'audio-high', 'ext': 'flv', 'preference': 3, 'vcodec': 'none', 'url': TEST_URL}, +            {'format_id': 'vid', 'ext': 'mp4', 'preference': 4, 'url': TEST_URL},          ]          info_dict = _make_result(formats) @@ -185,8 +188,8 @@ class TestFormatSelection(unittest.TestCase):          self.assertEqual(downloaded['format_id'], 'audio-low')          formats = [ -            {'format_id': 'vid-low', 'ext': 'mp4', 'preference': 1, 'url': '_'}, -            {'format_id': 'vid-high', 'ext': 'mp4', 'preference': 2, 'url': '_'}, +            {'format_id': 'vid-low', 'ext': 'mp4', 'preference': 1, 'url': TEST_URL}, +            {'format_id': 'vid-high', 'ext': 'mp4', 'preference': 2, 'url': TEST_URL},          ]          info_dict = _make_result(formats) @@ -228,9 +231,9 @@ class TestFormatSelection(unittest.TestCase):      def test_format_selection_video(self):          formats = [ -            {'format_id': 'dash-video-low', 'ext': 'mp4', 'preference': 1, 'acodec': 'none', 'url': '_'}, -            {'format_id': 'dash-video-high', 'ext': 'mp4', 'preference': 2, 'acodec': 'none', 'url': '_'}, -            {'format_id': 'vid', 'ext': 'mp4', 'preference': 3, 'url': '_'}, +            {'format_id': 'dash-video-low', 'ext': 'mp4', 'preference': 1, 'acodec': 'none', 'url': TEST_URL}, +            {'format_id': 'dash-video-high', 'ext': 'mp4', 'preference': 2, 'acodec': 'none', 'url': TEST_URL}, +            {'format_id': 'vid', 'ext': 'mp4', 'preference': 3, 'url': TEST_URL},          ]          info_dict = _make_result(formats) @@ -337,6 +340,8 @@ class TestFormatSelection(unittest.TestCase):          downloaded = ydl.downloaded_info_dicts[0]          self.assertEqual(downloaded['format_id'], 'G') + +class TestYoutubeDL(unittest.TestCase):      def test_subtitles(self):          def s_formats(lang, autocaption=False):              return [{ @@ -459,6 +464,73 @@ class TestFormatSelection(unittest.TestCase):          self.assertTrue(os.path.exists(audiofile), '%s doesn\'t exist' % audiofile)          os.unlink(audiofile) +    def test_match_filter(self): +        class FilterYDL(YDL): +            def __init__(self, *args, **kwargs): +                super(FilterYDL, self).__init__(*args, **kwargs) +                self.params['simulate'] = True + +            def process_info(self, info_dict): +                super(YDL, self).process_info(info_dict) + +            def _match_entry(self, info_dict, incomplete): +                res = super(FilterYDL, self)._match_entry(info_dict, incomplete) +                if res is None: +                    self.downloaded_info_dicts.append(info_dict) +                return res + +        first = { +            'id': '1', +            'url': TEST_URL, +            'title': 'one', +            'extractor': 'TEST', +            'duration': 30, +            'filesize': 10 * 1024, +        } +        second = { +            'id': '2', +            'url': TEST_URL, +            'title': 'two', +            'extractor': 'TEST', +            'duration': 10, +            'description': 'foo', +            'filesize': 5 * 1024, +        } +        videos = [first, second] + +        def get_videos(filter_=None): +            ydl = FilterYDL({'match_filter': filter_}) +            for v in videos: +                ydl.process_ie_result(v, download=True) +            return [v['id'] for v in ydl.downloaded_info_dicts] + +        res = get_videos() +        self.assertEqual(res, ['1', '2']) + +        def f(v): +            if v['id'] == '1': +                return None +            else: +                return 'Video id is not 1' +        res = get_videos(f) +        self.assertEqual(res, ['1']) + +        f = match_filter_func('duration < 30') +        res = get_videos(f) +        self.assertEqual(res, ['2']) + +        f = match_filter_func('description = foo') +        res = get_videos(f) +        self.assertEqual(res, ['2']) + +        f = match_filter_func('description =? foo') +        res = get_videos(f) +        self.assertEqual(res, ['1', '2']) + +        f = match_filter_func('filesize > 5KiB') +        res = get_videos(f) +        self.assertEqual(res, ['1']) +  if __name__ == '__main__':      unittest.main() diff --git a/test/test_aes.py b/test/test_aes.py new file mode 100644 index 000000000..4dc7de7b5 --- /dev/null +++ b/test/test_aes.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python + +from __future__ import unicode_literals + +# Allow direct execution +import os +import sys +import unittest +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + +from youtube_dl.aes import aes_decrypt, aes_encrypt, aes_cbc_decrypt, aes_decrypt_text +from youtube_dl.utils import bytes_to_intlist, intlist_to_bytes +import base64 + +# the encrypted data can be generate with 'devscripts/generate_aes_testdata.py' + + +class TestAES(unittest.TestCase): +    def setUp(self): +        self.key = self.iv = [0x20, 0x15] + 14 * [0] +        self.secret_msg = b'Secret message goes here' + +    def test_encrypt(self): +        msg = b'message' +        key = list(range(16)) +        encrypted = aes_encrypt(bytes_to_intlist(msg), key) +        decrypted = intlist_to_bytes(aes_decrypt(encrypted, key)) +        self.assertEqual(decrypted, msg) + +    def test_cbc_decrypt(self): +        data = bytes_to_intlist( +            b"\x97\x92+\xe5\x0b\xc3\x18\x91ky9m&\xb3\xb5@\xe6'\xc2\x96.\xc8u\x88\xab9-[\x9e|\xf1\xcd" +        ) +        decrypted = intlist_to_bytes(aes_cbc_decrypt(data, self.key, self.iv)) +        self.assertEqual(decrypted.rstrip(b'\x08'), self.secret_msg) + +    def test_decrypt_text(self): +        password = intlist_to_bytes(self.key).decode('utf-8') +        encrypted = base64.b64encode( +            intlist_to_bytes(self.iv[:8]) + +            b'\x17\x15\x93\xab\x8d\x80V\xcdV\xe0\t\xcdo\xc2\xa5\xd8ksM\r\xe27N\xae' +        ) +        decrypted = (aes_decrypt_text(encrypted, password, 16)) +        self.assertEqual(decrypted, self.secret_msg) + +        password = intlist_to_bytes(self.key).decode('utf-8') +        encrypted = base64.b64encode( +            intlist_to_bytes(self.iv[:8]) + +            b'\x0b\xe6\xa4\xd9z\x0e\xb8\xb9\xd0\xd4i_\x85\x1d\x99\x98_\xe5\x80\xe7.\xbf\xa5\x83' +        ) +        decrypted = (aes_decrypt_text(encrypted, password, 32)) +        self.assertEqual(decrypted, self.secret_msg) + +if __name__ == '__main__': +    unittest.main() diff --git a/test/test_all_urls.py b/test/test_all_urls.py index e66264b4b..a9db42b30 100644 --- a/test/test_all_urls.py +++ b/test/test_all_urls.py @@ -59,7 +59,7 @@ class TestAllURLsMatching(unittest.TestCase):          self.assertMatch('www.youtube.com/NASAgovVideo/videos', ['youtube:user'])      def test_youtube_feeds(self): -        self.assertMatch('https://www.youtube.com/feed/watch_later', ['youtube:watch_later']) +        self.assertMatch('https://www.youtube.com/feed/watch_later', ['youtube:watchlater'])          self.assertMatch('https://www.youtube.com/feed/subscriptions', ['youtube:subscriptions'])          self.assertMatch('https://www.youtube.com/feed/recommended', ['youtube:recommended'])          self.assertMatch('https://www.youtube.com/my_favorites', ['youtube:favorites']) @@ -104,11 +104,11 @@ class TestAllURLsMatching(unittest.TestCase):          self.assertMatch(':tds', ['ComedyCentralShows'])      def test_vimeo_matching(self): -        self.assertMatch('http://vimeo.com/channels/tributes', ['vimeo:channel']) -        self.assertMatch('http://vimeo.com/channels/31259', ['vimeo:channel']) -        self.assertMatch('http://vimeo.com/channels/31259/53576664', ['vimeo']) -        self.assertMatch('http://vimeo.com/user7108434', ['vimeo:user']) -        self.assertMatch('http://vimeo.com/user7108434/videos', ['vimeo:user']) +        self.assertMatch('https://vimeo.com/channels/tributes', ['vimeo:channel']) +        self.assertMatch('https://vimeo.com/channels/31259', ['vimeo:channel']) +        self.assertMatch('https://vimeo.com/channels/31259/53576664', ['vimeo']) +        self.assertMatch('https://vimeo.com/user7108434', ['vimeo:user']) +        self.assertMatch('https://vimeo.com/user7108434/videos', ['vimeo:user'])          self.assertMatch('https://vimeo.com/user21297594/review/75524534/3c257a1b5d', ['vimeo:review'])      # https://github.com/rg3/youtube-dl/issues/1930 diff --git a/test/test_execution.py b/test/test_execution.py index 60df187de..f31e51558 100644 --- a/test/test_execution.py +++ b/test/test_execution.py @@ -1,4 +1,6 @@  #!/usr/bin/env python +# coding: utf-8 +  from __future__ import unicode_literals  import unittest @@ -27,5 +29,12 @@ class TestExecution(unittest.TestCase):      def test_main_exec(self):          subprocess.check_call([sys.executable, 'youtube_dl/__main__.py', '--version'], cwd=rootDir, stdout=_DEV_NULL) +    def test_cmdline_umlauts(self): +        p = subprocess.Popen( +            [sys.executable, 'youtube_dl/__main__.py', 'ä', '--version'], +            cwd=rootDir, stdout=_DEV_NULL, stderr=subprocess.PIPE) +        _, stderr = p.communicate() +        self.assertFalse(stderr) +  if __name__ == '__main__':      unittest.main() diff --git a/test/test_http.py b/test/test_http.py index bd4d46fef..f2e305b6f 100644 --- a/test/test_http.py +++ b/test/test_http.py @@ -8,7 +8,7 @@ import unittest  sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))  from youtube_dl import YoutubeDL -from youtube_dl.compat import compat_http_server +from youtube_dl.compat import compat_http_server, compat_urllib_request  import ssl  import threading @@ -68,5 +68,52 @@ class TestHTTP(unittest.TestCase):          r = ydl.extract_info('https://localhost:%d/video.html' % self.port)          self.assertEqual(r['url'], 'https://localhost:%d/vid.mp4' % self.port) + +def _build_proxy_handler(name): +    class HTTPTestRequestHandler(compat_http_server.BaseHTTPRequestHandler): +        proxy_name = name + +        def log_message(self, format, *args): +            pass + +        def do_GET(self): +            self.send_response(200) +            self.send_header('Content-Type', 'text/plain; charset=utf-8') +            self.end_headers() +            self.wfile.write('{self.proxy_name}: {self.path}'.format(self=self).encode('utf-8')) +    return HTTPTestRequestHandler + + +class TestProxy(unittest.TestCase): +    def setUp(self): +        self.proxy = compat_http_server.HTTPServer( +            ('localhost', 0), _build_proxy_handler('normal')) +        self.port = self.proxy.socket.getsockname()[1] +        self.proxy_thread = threading.Thread(target=self.proxy.serve_forever) +        self.proxy_thread.daemon = True +        self.proxy_thread.start() + +        self.cn_proxy = compat_http_server.HTTPServer( +            ('localhost', 0), _build_proxy_handler('cn')) +        self.cn_port = self.cn_proxy.socket.getsockname()[1] +        self.cn_proxy_thread = threading.Thread(target=self.cn_proxy.serve_forever) +        self.cn_proxy_thread.daemon = True +        self.cn_proxy_thread.start() + +    def test_proxy(self): +        cn_proxy = 'localhost:{0}'.format(self.cn_port) +        ydl = YoutubeDL({ +            'proxy': 'localhost:{0}'.format(self.port), +            'cn_verification_proxy': cn_proxy, +        }) +        url = 'http://foo.com/bar' +        response = ydl.urlopen(url).read().decode('utf-8') +        self.assertEqual(response, 'normal: {0}'.format(url)) + +        req = compat_urllib_request.Request(url) +        req.add_header('Ytdl-request-proxy', cn_proxy) +        response = ydl.urlopen(req).read().decode('utf-8') +        self.assertEqual(response, 'cn: {0}'.format(url)) +  if __name__ == '__main__':      unittest.main() diff --git a/test/test_netrc.py b/test/test_netrc.py new file mode 100644 index 000000000..7cf3a6a2e --- /dev/null +++ b/test/test_netrc.py @@ -0,0 +1,26 @@ +# coding: utf-8 +from __future__ import unicode_literals + +import os +import sys +import unittest +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + + +from youtube_dl.extractor import ( +    gen_extractors, +) + + +class TestNetRc(unittest.TestCase): +    def test_netrc_present(self): +        for ie in gen_extractors(): +            if not hasattr(ie, '_login'): +                continue +            self.assertTrue( +                hasattr(ie, '_NETRC_MACHINE'), +                'Extractor %s supports login, but is missing a _NETRC_MACHINE property' % ie.IE_NAME) + + +if __name__ == '__main__': +    unittest.main() diff --git a/test/test_postprocessors.py b/test/test_postprocessors.py new file mode 100644 index 000000000..addb69d6f --- /dev/null +++ b/test/test_postprocessors.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python + +from __future__ import unicode_literals + +# Allow direct execution +import os +import sys +import unittest +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + +from youtube_dl.postprocessor import MetadataFromTitlePP + + +class TestMetadataFromTitle(unittest.TestCase): +    def test_format_to_regex(self): +        pp = MetadataFromTitlePP(None, '%(title)s - %(artist)s') +        self.assertEqual(pp._titleregex, '(?P<title>.+)\ \-\ (?P<artist>.+)') diff --git a/test/test_subtitles.py b/test/test_subtitles.py index 3f2d8a2ba..891ee620b 100644 --- a/test/test_subtitles.py +++ b/test/test_subtitles.py @@ -26,6 +26,7 @@ from youtube_dl.extractor import (      VikiIE,      ThePlatformIE,      RTVEALaCartaIE, +    FunnyOrDieIE,  ) @@ -320,5 +321,17 @@ class TestRtveSubtitles(BaseTestSubtitles):          self.assertEqual(md5(subtitles['es']), '69e70cae2d40574fb7316f31d6eb7fca') +class TestFunnyOrDieSubtitles(BaseTestSubtitles): +    url = 'http://www.funnyordie.com/videos/224829ff6d/judd-apatow-will-direct-your-vine' +    IE = FunnyOrDieIE + +    def test_allsubtitles(self): +        self.DL.params['writesubtitles'] = True +        self.DL.params['allsubtitles'] = True +        subtitles = self.getSubtitles() +        self.assertEqual(set(subtitles.keys()), set(['en'])) +        self.assertEqual(md5(subtitles['en']), 'c5593c193eacd353596c11c2d4f9ecc4') + +  if __name__ == '__main__':      unittest.main() diff --git a/test/test_unicode_literals.py b/test/test_unicode_literals.py index 7f816698e..6c1b7ec91 100644 --- a/test/test_unicode_literals.py +++ b/test/test_unicode_literals.py @@ -17,13 +17,22 @@ IGNORED_FILES = [      'buildserver.py',  ] +IGNORED_DIRS = [ +    '.git', +    '.tox', +]  from test.helper import assertRegexpMatches  class TestUnicodeLiterals(unittest.TestCase):      def test_all_files(self): -        for dirpath, _, filenames in os.walk(rootDir): +        for dirpath, dirnames, filenames in os.walk(rootDir): +            for ignore_dir in IGNORED_DIRS: +                if ignore_dir in dirnames: +                    # If we remove the directory from dirnames os.walk won't +                    # recurse into it +                    dirnames.remove(ignore_dir)              for basename in filenames:                  if not basename.endswith('.py'):                      continue diff --git a/test/test_utils.py b/test/test_utils.py index 3fba8ae11..abaf1ab73 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -24,6 +24,7 @@ from youtube_dl.utils import (      encodeFilename,      escape_rfc3986,      escape_url, +    ExtractorError,      find_xpath_attr,      fix_xml_ampersands,      InAdvancePagedList, @@ -38,6 +39,8 @@ from youtube_dl.utils import (      parse_iso8601,      read_batch_urls,      sanitize_filename, +    sanitize_path, +    sanitize_url_path_consecutive_slashes,      shell_quote,      smuggle_url,      str_to_int, @@ -52,6 +55,7 @@ from youtube_dl.utils import (      urlencode_postdata,      version_tuple,      xpath_with_ns, +    xpath_text,      render_table,      match_str,  ) @@ -85,8 +89,11 @@ class TestUtil(unittest.TestCase):          self.assertEqual(              sanitize_filename('New World record at 0:12:34'),              'New World record at 0_12_34') +          self.assertEqual(sanitize_filename('--gasdgf'), '_-gasdgf')          self.assertEqual(sanitize_filename('--gasdgf', is_id=True), '--gasdgf') +        self.assertEqual(sanitize_filename('.gasdgf'), 'gasdgf') +        self.assertEqual(sanitize_filename('.gasdgf', is_id=True), '.gasdgf')          forbidden = '"\0\\/'          for fc in forbidden: @@ -128,6 +135,62 @@ class TestUtil(unittest.TestCase):          self.assertEqual(sanitize_filename('_BD_eEpuzXw', is_id=True), '_BD_eEpuzXw')          self.assertEqual(sanitize_filename('N0Y__7-UOdI', is_id=True), 'N0Y__7-UOdI') +    def test_sanitize_path(self): +        if sys.platform != 'win32': +            return + +        self.assertEqual(sanitize_path('abc'), 'abc') +        self.assertEqual(sanitize_path('abc/def'), 'abc\\def') +        self.assertEqual(sanitize_path('abc\\def'), 'abc\\def') +        self.assertEqual(sanitize_path('abc|def'), 'abc#def') +        self.assertEqual(sanitize_path('<>:"|?*'), '#######') +        self.assertEqual(sanitize_path('C:/abc/def'), 'C:\\abc\\def') +        self.assertEqual(sanitize_path('C?:/abc/def'), 'C##\\abc\\def') + +        self.assertEqual(sanitize_path('\\\\?\\UNC\\ComputerName\\abc'), '\\\\?\\UNC\\ComputerName\\abc') +        self.assertEqual(sanitize_path('\\\\?\\UNC/ComputerName/abc'), '\\\\?\\UNC\\ComputerName\\abc') + +        self.assertEqual(sanitize_path('\\\\?\\C:\\abc'), '\\\\?\\C:\\abc') +        self.assertEqual(sanitize_path('\\\\?\\C:/abc'), '\\\\?\\C:\\abc') +        self.assertEqual(sanitize_path('\\\\?\\C:\\ab?c\\de:f'), '\\\\?\\C:\\ab#c\\de#f') +        self.assertEqual(sanitize_path('\\\\?\\C:\\abc'), '\\\\?\\C:\\abc') + +        self.assertEqual( +            sanitize_path('youtube/%(uploader)s/%(autonumber)s-%(title)s-%(upload_date)s.%(ext)s'), +            'youtube\\%(uploader)s\\%(autonumber)s-%(title)s-%(upload_date)s.%(ext)s') + +        self.assertEqual( +            sanitize_path('youtube/TheWreckingYard ./00001-Not bad, Especially for Free! (1987 Yamaha 700)-20141116.mp4.part'), +            'youtube\\TheWreckingYard #\\00001-Not bad, Especially for Free! (1987 Yamaha 700)-20141116.mp4.part') +        self.assertEqual(sanitize_path('abc/def...'), 'abc\\def..#') +        self.assertEqual(sanitize_path('abc.../def'), 'abc..#\\def') +        self.assertEqual(sanitize_path('abc.../def...'), 'abc..#\\def..#') + +        self.assertEqual(sanitize_path('../abc'), '..\\abc') +        self.assertEqual(sanitize_path('../../abc'), '..\\..\\abc') +        self.assertEqual(sanitize_path('./abc'), 'abc') +        self.assertEqual(sanitize_path('./../abc'), '..\\abc') + +    def test_sanitize_url_path_consecutive_slashes(self): +        self.assertEqual( +            sanitize_url_path_consecutive_slashes('http://hostname/foo//bar/filename.html'), +            'http://hostname/foo/bar/filename.html') +        self.assertEqual( +            sanitize_url_path_consecutive_slashes('http://hostname//foo/bar/filename.html'), +            'http://hostname/foo/bar/filename.html') +        self.assertEqual( +            sanitize_url_path_consecutive_slashes('http://hostname//'), +            'http://hostname/') +        self.assertEqual( +            sanitize_url_path_consecutive_slashes('http://hostname/foo/bar/filename.html'), +            'http://hostname/foo/bar/filename.html') +        self.assertEqual( +            sanitize_url_path_consecutive_slashes('http://hostname/'), +            'http://hostname/') +        self.assertEqual( +            sanitize_url_path_consecutive_slashes('http://hostname/abc//'), +            'http://hostname/abc/') +      def test_ordered_set(self):          self.assertEqual(orderedSet([1, 1, 2, 3, 4, 4, 5, 6, 7, 3, 5]), [1, 2, 3, 4, 5, 6, 7])          self.assertEqual(orderedSet([]), []) @@ -137,6 +200,8 @@ class TestUtil(unittest.TestCase):      def test_unescape_html(self):          self.assertEqual(unescapeHTML('%20;'), '%20;') +        self.assertEqual(unescapeHTML('/'), '/') +        self.assertEqual(unescapeHTML('/'), '/')          self.assertEqual(              unescapeHTML('é'), 'é') @@ -189,6 +254,17 @@ class TestUtil(unittest.TestCase):          self.assertEqual(find('media:song/media:author').text, 'The Author')          self.assertEqual(find('media:song/url').text, 'http://server.com/download.mp3') +    def test_xpath_text(self): +        testxml = '''<root> +            <div> +                <p>Foo</p> +            </div> +        </root>''' +        doc = xml.etree.ElementTree.fromstring(testxml) +        self.assertEqual(xpath_text(doc, 'div/p'), 'Foo') +        self.assertTrue(xpath_text(doc, 'div/bar') is None) +        self.assertRaises(ExtractorError, xpath_text, doc, 'div/bar', fatal=True) +      def test_smuggle_url(self):          data = {"ö": "ö", "abc": [3]}          url = 'https://foo.bar/baz?x=y#a' | 
