diff options
Diffstat (limited to 'test')
29 files changed, 165 insertions, 96 deletions
diff --git a/test/helper.py b/test/helper.py index e62aab11e..f45818b0f 100644 --- a/test/helper.py +++ b/test/helper.py @@ -10,13 +10,13 @@ import types import ssl import sys -import youtube_dl.extractor -from youtube_dl import YoutubeDL -from youtube_dl.compat import ( +import youtube_dlc.extractor +from youtube_dlc import YoutubeDL +from youtube_dlc.compat import ( compat_os_name, compat_str, ) -from youtube_dl.utils import ( +from youtube_dlc.utils import ( preferredencoding, write_string, ) @@ -90,7 +90,7 @@ class FakeYDL(YoutubeDL): def gettestcases(include_onlymatching=False): - for ie in youtube_dl.extractor.gen_extractors(): + for ie in youtube_dlc.extractor.gen_extractors(): for tc in ie.get_testcases(include_onlymatching): yield tc diff --git a/test/test_InfoExtractor.py b/test/test_InfoExtractor.py index 71f6608fe..bdd01e41a 100644 --- a/test/test_InfoExtractor.py +++ b/test/test_InfoExtractor.py @@ -10,10 +10,10 @@ import unittest sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from test.helper import FakeYDL, expect_dict, expect_value, http_server_port -from youtube_dl.compat import compat_etree_fromstring, compat_http_server -from youtube_dl.extractor.common import InfoExtractor -from youtube_dl.extractor import YoutubeIE, get_info_extractor -from youtube_dl.utils import encode_data_uri, strip_jsonp, ExtractorError, RegexNotFoundError +from youtube_dlc.compat import compat_etree_fromstring, compat_http_server +from youtube_dlc.extractor.common import InfoExtractor +from youtube_dlc.extractor import YoutubeIE, get_info_extractor +from youtube_dlc.utils import encode_data_uri, strip_jsonp, ExtractorError, RegexNotFoundError import threading diff --git a/test/test_YoutubeDL.py b/test/test_YoutubeDL.py index ce9666171..6d02c2a54 100644 --- a/test/test_YoutubeDL.py +++ b/test/test_YoutubeDL.py @@ -12,12 +12,12 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import copy from test.helper import FakeYDL, assertRegexpMatches -from youtube_dl import YoutubeDL -from youtube_dl.compat import compat_str, compat_urllib_error -from youtube_dl.extractor import YoutubeIE -from youtube_dl.extractor.common import InfoExtractor -from youtube_dl.postprocessor.common import PostProcessor -from youtube_dl.utils import ExtractorError, match_filter_func +from youtube_dlc import YoutubeDL +from youtube_dlc.compat import compat_str, compat_urllib_error +from youtube_dlc.extractor import YoutubeIE +from youtube_dlc.extractor.common import InfoExtractor +from youtube_dlc.postprocessor.common import PostProcessor +from youtube_dlc.utils import ExtractorError, match_filter_func TEST_URL = 'http://localhost/sample.mp4' @@ -816,11 +816,15 @@ class TestYoutubeDL(unittest.TestCase): 'webpage_url': 'http://example.com', } - def get_ids(params): + def get_downloaded_info_dicts(params): ydl = YDL(params) - # make a copy because the dictionary can be modified - ydl.process_ie_result(playlist.copy()) - return [int(v['id']) for v in ydl.downloaded_info_dicts] + # make a deep copy because the dictionary and nested entries + # can be modified + ydl.process_ie_result(copy.deepcopy(playlist)) + return ydl.downloaded_info_dicts + + def get_ids(params): + return [int(v['id']) for v in get_downloaded_info_dicts(params)] result = get_ids({}) self.assertEqual(result, [1, 2, 3, 4]) @@ -852,6 +856,22 @@ class TestYoutubeDL(unittest.TestCase): result = get_ids({'playlist_items': '2-4,3-4,3'}) self.assertEqual(result, [2, 3, 4]) + # Tests for https://github.com/ytdl-org/youtube-dl/issues/10591 + # @{ + result = get_downloaded_info_dicts({'playlist_items': '2-4,3-4,3'}) + self.assertEqual(result[0]['playlist_index'], 2) + self.assertEqual(result[1]['playlist_index'], 3) + + result = get_downloaded_info_dicts({'playlist_items': '2-4,3-4,3'}) + self.assertEqual(result[0]['playlist_index'], 2) + self.assertEqual(result[1]['playlist_index'], 3) + self.assertEqual(result[2]['playlist_index'], 4) + + result = get_downloaded_info_dicts({'playlist_items': '4,2'}) + self.assertEqual(result[0]['playlist_index'], 4) + self.assertEqual(result[1]['playlist_index'], 2) + # @} + def test_urlopen_no_file_protocol(self): # see https://github.com/ytdl-org/youtube-dl/issues/8227 ydl = YDL() diff --git a/test/test_YoutubeDLCookieJar.py b/test/test_YoutubeDLCookieJar.py index f959798de..615d8a9d8 100644 --- a/test/test_YoutubeDLCookieJar.py +++ b/test/test_YoutubeDLCookieJar.py @@ -10,7 +10,7 @@ import tempfile import unittest sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) -from youtube_dl.utils import YoutubeDLCookieJar +from youtube_dlc.utils import YoutubeDLCookieJar class TestYoutubeDLCookieJar(unittest.TestCase): @@ -39,6 +39,13 @@ class TestYoutubeDLCookieJar(unittest.TestCase): assert_cookie_has_value('HTTPONLY_COOKIE') assert_cookie_has_value('JS_ACCESSIBLE_COOKIE') + def test_malformed_cookies(self): + cookiejar = YoutubeDLCookieJar('./test/testdata/cookies/malformed_cookies.txt') + cookiejar.load(ignore_discard=True, ignore_expires=True) + # Cookies should be empty since all malformed cookie file entries + # will be ignored + self.assertFalse(cookiejar._cookies) + if __name__ == '__main__': unittest.main() diff --git a/test/test_aes.py b/test/test_aes.py index cc89fb6ab..ef1e1b189 100644 --- a/test/test_aes.py +++ b/test/test_aes.py @@ -8,8 +8,8 @@ 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_cbc_encrypt, aes_decrypt_text -from youtube_dl.utils import bytes_to_intlist, intlist_to_bytes +from youtube_dlc.aes import aes_decrypt, aes_encrypt, aes_cbc_decrypt, aes_cbc_encrypt, aes_decrypt_text +from youtube_dlc.utils import bytes_to_intlist, intlist_to_bytes import base64 # the encrypted data can be generate with 'devscripts/generate_aes_testdata.py' diff --git a/test/test_age_restriction.py b/test/test_age_restriction.py index 6f5513faa..b73bdd767 100644 --- a/test/test_age_restriction.py +++ b/test/test_age_restriction.py @@ -10,7 +10,7 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from test.helper import try_rm -from youtube_dl import YoutubeDL +from youtube_dlc import YoutubeDL def _download_restricted(url, filename, age): diff --git a/test/test_all_urls.py b/test/test_all_urls.py index 465ce0050..7b6664cac 100644 --- a/test/test_all_urls.py +++ b/test/test_all_urls.py @@ -12,7 +12,7 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from test.helper import gettestcases -from youtube_dl.extractor import ( +from youtube_dlc.extractor import ( FacebookIE, gen_extractors, YoutubeIE, @@ -70,7 +70,7 @@ class TestAllURLsMatching(unittest.TestCase): def test_youtube_search_matching(self): self.assertMatch('http://www.youtube.com/results?search_query=making+mustard', ['youtube:search_url']) - self.assertMatch('https://www.youtube.com/results?baz=bar&search_query=youtube-dl+test+video&filters=video&lclk=video', ['youtube:search_url']) + self.assertMatch('https://www.youtube.com/results?baz=bar&search_query=youtube-dlc+test+video&filters=video&lclk=video', ['youtube:search_url']) def test_youtube_extract(self): assertExtractId = lambda url, id: self.assertEqual(YoutubeIE.extract_id(url), id) @@ -123,12 +123,6 @@ class TestAllURLsMatching(unittest.TestCase): self.assertMatch('http://video.pbs.org/viralplayer/2365173446/', ['pbs']) self.assertMatch('http://video.pbs.org/widget/partnerplayer/980042464/', ['pbs']) - def test_yahoo_https(self): - # https://github.com/ytdl-org/youtube-dl/issues/2701 - self.assertMatch( - 'https://screen.yahoo.com/smartwatches-latest-wearable-gadgets-163745379-cbs.html', - ['Yahoo']) - def test_no_duplicated_ie_names(self): name_accu = collections.defaultdict(list) for ie in self.ies: diff --git a/test/test_cache.py b/test/test_cache.py index a16160142..1167519d1 100644 --- a/test/test_cache.py +++ b/test/test_cache.py @@ -13,7 +13,7 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from test.helper import FakeYDL -from youtube_dl.cache import Cache +from youtube_dlc.cache import Cache def _is_empty(d): diff --git a/test/test_compat.py b/test/test_compat.py index 86ff389fd..8c49a001e 100644 --- a/test/test_compat.py +++ b/test/test_compat.py @@ -10,7 +10,7 @@ import unittest sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) -from youtube_dl.compat import ( +from youtube_dlc.compat import ( compat_getenv, compat_setenv, compat_etree_Element, @@ -28,11 +28,11 @@ from youtube_dl.compat import ( class TestCompat(unittest.TestCase): def test_compat_getenv(self): test_str = 'тест' - compat_setenv('YOUTUBE_DL_COMPAT_GETENV', test_str) - self.assertEqual(compat_getenv('YOUTUBE_DL_COMPAT_GETENV'), test_str) + compat_setenv('youtube_dlc_COMPAT_GETENV', test_str) + self.assertEqual(compat_getenv('youtube_dlc_COMPAT_GETENV'), test_str) def test_compat_setenv(self): - test_var = 'YOUTUBE_DL_COMPAT_SETENV' + test_var = 'youtube_dlc_COMPAT_SETENV' test_str = 'тест' compat_setenv(test_var, test_str) compat_getenv(test_var) @@ -46,11 +46,11 @@ class TestCompat(unittest.TestCase): compat_setenv('HOME', old_home or '') def test_all_present(self): - import youtube_dl.compat - all_names = youtube_dl.compat.__all__ + import youtube_dlc.compat + all_names = youtube_dlc.compat.__all__ present_names = set(filter( lambda c: '_' in c and not c.startswith('_'), - dir(youtube_dl.compat))) - set(['unicode_literals']) + dir(youtube_dlc.compat))) - set(['unicode_literals']) self.assertEqual(all_names, sorted(present_names)) def test_compat_urllib_parse_unquote(self): diff --git a/test/test_download.py b/test/test_download.py index ebe820dfc..bcd3b4041 100644 --- a/test/test_download.py +++ b/test/test_download.py @@ -24,24 +24,24 @@ import io import json import socket -import youtube_dl.YoutubeDL -from youtube_dl.compat import ( +import youtube_dlc.YoutubeDL +from youtube_dlc.compat import ( compat_http_client, compat_urllib_error, compat_HTTPError, ) -from youtube_dl.utils import ( +from youtube_dlc.utils import ( DownloadError, ExtractorError, format_bytes, UnavailableVideoError, ) -from youtube_dl.extractor import get_info_extractor +from youtube_dlc.extractor import get_info_extractor RETRIES = 3 -class YoutubeDL(youtube_dl.YoutubeDL): +class YoutubeDL(youtube_dlc.YoutubeDL): def __init__(self, *args, **kwargs): self.to_stderr = self.to_screen self.processed_info_dicts = [] @@ -92,7 +92,7 @@ class TestDownload(unittest.TestCase): def generator(test_case, tname): def test_template(self): - ie = youtube_dl.extractor.get_info_extractor(test_case['name'])() + ie = youtube_dlc.extractor.get_info_extractor(test_case['name'])() other_ies = [get_info_extractor(ie_key)() for ie_key in test_case.get('add_ie', [])] is_playlist = any(k.startswith('playlist') for k in test_case) test_cases = test_case.get( diff --git a/test/test_downloader_http.py b/test/test_downloader_http.py index 750472281..c8e28bd3a 100644 --- a/test/test_downloader_http.py +++ b/test/test_downloader_http.py @@ -10,10 +10,10 @@ import unittest sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from test.helper import http_server_port, try_rm -from youtube_dl import YoutubeDL -from youtube_dl.compat import compat_http_server -from youtube_dl.downloader.http import HttpFD -from youtube_dl.utils import encodeFilename +from youtube_dlc import YoutubeDL +from youtube_dlc.compat import compat_http_server +from youtube_dlc.downloader.http import HttpFD +from youtube_dlc.utils import encodeFilename import threading TEST_DIR = os.path.dirname(os.path.abspath(__file__)) diff --git a/test/test_execution.py b/test/test_execution.py index 11661bb68..b18e63d73 100644 --- a/test/test_execution.py +++ b/test/test_execution.py @@ -10,7 +10,7 @@ import os import subprocess sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) -from youtube_dl.utils import encodeArgument +from youtube_dlc.utils import encodeArgument rootDir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -23,18 +23,18 @@ except AttributeError: class TestExecution(unittest.TestCase): def test_import(self): - subprocess.check_call([sys.executable, '-c', 'import youtube_dl'], cwd=rootDir) + subprocess.check_call([sys.executable, '-c', 'import youtube_dlc'], cwd=rootDir) def test_module_exec(self): if sys.version_info >= (2, 7): # Python 2.6 doesn't support package execution - subprocess.check_call([sys.executable, '-m', 'youtube_dl', '--version'], cwd=rootDir, stdout=_DEV_NULL) + subprocess.check_call([sys.executable, '-m', 'youtube_dlc', '--version'], cwd=rootDir, stdout=_DEV_NULL) def test_main_exec(self): - subprocess.check_call([sys.executable, 'youtube_dl/__main__.py', '--version'], cwd=rootDir, stdout=_DEV_NULL) + subprocess.check_call([sys.executable, 'youtube_dlc/__main__.py', '--version'], cwd=rootDir, stdout=_DEV_NULL) def test_cmdline_umlauts(self): p = subprocess.Popen( - [sys.executable, 'youtube_dl/__main__.py', encodeArgument('ä'), '--version'], + [sys.executable, 'youtube_dlc/__main__.py', encodeArgument('ä'), '--version'], cwd=rootDir, stdout=_DEV_NULL, stderr=subprocess.PIPE) _, stderr = p.communicate() self.assertFalse(stderr) diff --git a/test/test_http.py b/test/test_http.py index 3ee0a5dda..55c3c6183 100644 --- a/test/test_http.py +++ b/test/test_http.py @@ -9,8 +9,8 @@ import unittest sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from test.helper import http_server_port -from youtube_dl import YoutubeDL -from youtube_dl.compat import compat_http_server, compat_urllib_request +from youtube_dlc import YoutubeDL +from youtube_dlc.compat import compat_http_server, compat_urllib_request import ssl import threading diff --git a/test/test_iqiyi_sdk_interpreter.py b/test/test_iqiyi_sdk_interpreter.py index 789059dbe..303609baa 100644 --- a/test/test_iqiyi_sdk_interpreter.py +++ b/test/test_iqiyi_sdk_interpreter.py @@ -9,7 +9,7 @@ import unittest sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from test.helper import FakeYDL -from youtube_dl.extractor import IqiyiIE +from youtube_dlc.extractor import IqiyiIE class IqiyiIEWithCredentials(IqiyiIE): diff --git a/test/test_jsinterp.py b/test/test_jsinterp.py index c24b8ca74..97fc8d5aa 100644 --- a/test/test_jsinterp.py +++ b/test/test_jsinterp.py @@ -8,7 +8,7 @@ import sys import unittest sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) -from youtube_dl.jsinterp import JSInterpreter +from youtube_dlc.jsinterp import JSInterpreter class TestJSInterpreter(unittest.TestCase): diff --git a/test/test_netrc.py b/test/test_netrc.py index 7cf3a6a2e..566ba37a6 100644 --- a/test/test_netrc.py +++ b/test/test_netrc.py @@ -7,7 +7,7 @@ import unittest sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) -from youtube_dl.extractor import ( +from youtube_dlc.extractor import ( gen_extractors, ) diff --git a/test/test_options.py b/test/test_options.py index 3a25a6ba3..dce253373 100644 --- a/test/test_options.py +++ b/test/test_options.py @@ -8,7 +8,7 @@ import sys import unittest sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) -from youtube_dl.options import _hide_login_info +from youtube_dlc.options import _hide_login_info class TestOptions(unittest.TestCase): diff --git a/test/test_postprocessors.py b/test/test_postprocessors.py index 4209d1d9a..6f538a3da 100644 --- a/test/test_postprocessors.py +++ b/test/test_postprocessors.py @@ -8,7 +8,7 @@ import sys import unittest sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) -from youtube_dl.postprocessor import MetadataFromTitlePP +from youtube_dlc.postprocessor import MetadataFromTitlePP class TestMetadataFromTitle(unittest.TestCase): diff --git a/test/test_socks.py b/test/test_socks.py index 1e68eb0da..be52e2343 100644 --- a/test/test_socks.py +++ b/test/test_socks.py @@ -15,7 +15,7 @@ from test.helper import ( FakeYDL, get_params, ) -from youtube_dl.compat import ( +from youtube_dlc.compat import ( compat_str, compat_urllib_request, ) diff --git a/test/test_subtitles.py b/test/test_subtitles.py index 7d57a628e..3ca03fb6f 100644 --- a/test/test_subtitles.py +++ b/test/test_subtitles.py @@ -10,7 +10,7 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from test.helper import FakeYDL, md5 -from youtube_dl.extractor import ( +from youtube_dlc.extractor import ( YoutubeIE, DailymotionIE, TEDIE, @@ -26,7 +26,6 @@ from youtube_dl.extractor import ( ThePlatformIE, ThePlatformFeedIE, RTVEALaCartaIE, - FunnyOrDieIE, DemocracynowIE, ) @@ -322,18 +321,6 @@ 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') - - class TestDemocracynowSubtitles(BaseTestSubtitles): url = 'http://www.democracynow.org/shows/2015/7/3' IE = DemocracynowIE diff --git a/test/test_swfinterp.py b/test/test_swfinterp.py index 9f18055e6..1a8b353e8 100644 --- a/test/test_swfinterp.py +++ b/test/test_swfinterp.py @@ -14,7 +14,7 @@ import json import re import subprocess -from youtube_dl.swfinterp import SWFInterpreter +from youtube_dlc.swfinterp import SWFInterpreter TEST_DIR = os.path.join( diff --git a/test/test_update.py b/test/test_update.py index d9c71511d..1b144c43c 100644 --- a/test/test_update.py +++ b/test/test_update.py @@ -10,7 +10,7 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import json -from youtube_dl.update import rsa_verify +from youtube_dlc.update import rsa_verify class TestUpdate(unittest.TestCase): diff --git a/test/test_utils.py b/test/test_utils.py index 659c6ece5..5914d4fd6 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -15,10 +15,11 @@ import io import json import xml.etree.ElementTree -from youtube_dl.utils import ( +from youtube_dlc.utils import ( age_restricted, args_to_str, encode_base_n, + caesar, clean_html, date_from_str, DateRange, @@ -69,11 +70,13 @@ from youtube_dl.utils import ( remove_start, remove_end, remove_quotes, + rot47, shell_quote, smuggle_url, str_to_int, strip_jsonp, strip_or_none, + subtitles_filename, timeconvert, unescapeHTML, unified_strdate, @@ -102,7 +105,7 @@ from youtube_dl.utils import ( cli_bool_option, parse_codecs, ) -from youtube_dl.compat import ( +from youtube_dlc.compat import ( compat_chr, compat_etree_fromstring, compat_getenv, @@ -237,12 +240,12 @@ class TestUtil(unittest.TestCase): def env(var): return '%{0}%'.format(var) if sys.platform == 'win32' else '${0}'.format(var) - compat_setenv('YOUTUBE_DL_EXPATH_PATH', 'expanded') - self.assertEqual(expand_path(env('YOUTUBE_DL_EXPATH_PATH')), 'expanded') + compat_setenv('youtube_dlc_EXPATH_PATH', 'expanded') + self.assertEqual(expand_path(env('youtube_dlc_EXPATH_PATH')), 'expanded') self.assertEqual(expand_path(env('HOME')), compat_getenv('HOME')) self.assertEqual(expand_path('~'), compat_getenv('HOME')) self.assertEqual( - expand_path('~/%s' % env('YOUTUBE_DL_EXPATH_PATH')), + expand_path('~/%s' % env('youtube_dlc_EXPATH_PATH')), '%s/expanded' % compat_getenv('HOME')) def test_prepend_extension(self): @@ -261,6 +264,11 @@ class TestUtil(unittest.TestCase): self.assertEqual(replace_extension('.abc', 'temp'), '.abc.temp') self.assertEqual(replace_extension('.abc.ext', 'temp'), '.abc.temp') + def test_subtitles_filename(self): + self.assertEqual(subtitles_filename('abc.ext', 'en', 'vtt'), 'abc.en.vtt') + self.assertEqual(subtitles_filename('abc.ext', 'en', 'vtt', 'ext'), 'abc.en.vtt') + self.assertEqual(subtitles_filename('abc.unexpected_ext', 'en', 'vtt', 'ext'), 'abc.unexpected_ext.en.vtt') + def test_remove_start(self): self.assertEqual(remove_start(None, 'A - '), None) self.assertEqual(remove_start('A - B', 'A - '), 'B') @@ -334,6 +342,8 @@ class TestUtil(unittest.TestCase): self.assertEqual(unified_strdate('July 15th, 2013'), '20130715') self.assertEqual(unified_strdate('September 1st, 2013'), '20130901') self.assertEqual(unified_strdate('Sep 2nd, 2013'), '20130902') + self.assertEqual(unified_strdate('November 3rd, 2019'), '20191103') + self.assertEqual(unified_strdate('October 23rd, 2005'), '20051023') def test_unified_timestamps(self): self.assertEqual(unified_timestamp('December 21, 2010'), 1292889600) @@ -489,6 +499,12 @@ class TestUtil(unittest.TestCase): def test_str_to_int(self): self.assertEqual(str_to_int('123,456'), 123456) self.assertEqual(str_to_int('123.456'), 123456) + self.assertEqual(str_to_int(523), 523) + # Python 3 has no long + if sys.version_info < (3, 0): + eval('self.assertEqual(str_to_int(123456L), 123456)') + self.assertEqual(str_to_int('noninteger'), None) + self.assertEqual(str_to_int([]), None) def test_url_basename(self): self.assertEqual(url_basename('http://foo.de/'), '') @@ -1361,6 +1377,20 @@ Line 1 self.assertRaises(ValueError, encode_base_n, 0, 70) self.assertRaises(ValueError, encode_base_n, 0, 60, custom_table) + def test_caesar(self): + self.assertEqual(caesar('ace', 'abcdef', 2), 'cea') + self.assertEqual(caesar('cea', 'abcdef', -2), 'ace') + self.assertEqual(caesar('ace', 'abcdef', -2), 'eac') + self.assertEqual(caesar('eac', 'abcdef', 2), 'ace') + self.assertEqual(caesar('ace', 'abcdef', 0), 'ace') + self.assertEqual(caesar('xyz', 'abcdef', 2), 'xyz') + self.assertEqual(caesar('abc', 'acegik', 2), 'ebg') + self.assertEqual(caesar('ebg', 'acegik', -2), 'abc') + + def test_rot47(self): + self.assertEqual(rot47('youtube-dlc'), r'J@FEF36\5=4') + self.assertEqual(rot47('YOUTUBE-DLC'), r'*~&%&qt\s{r') + def test_urshift(self): self.assertEqual(urshift(3, 1), 1) self.assertEqual(urshift(-3, 1), 2147483646) diff --git a/test/test_verbose_output.py b/test/test_verbose_output.py index c1465fe8c..462f25e03 100644 --- a/test/test_verbose_output.py +++ b/test/test_verbose_output.py @@ -17,7 +17,7 @@ class TestVerboseOutput(unittest.TestCase): def test_private_info_arg(self): outp = subprocess.Popen( [ - sys.executable, 'youtube_dl/__main__.py', '-v', + sys.executable, 'youtube_dlc/__main__.py', '-v', '--username', 'johnsmith@gmail.com', '--password', 'secret', ], cwd=rootDir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) @@ -30,7 +30,7 @@ class TestVerboseOutput(unittest.TestCase): def test_private_info_shortarg(self): outp = subprocess.Popen( [ - sys.executable, 'youtube_dl/__main__.py', '-v', + sys.executable, 'youtube_dlc/__main__.py', '-v', '-u', 'johnsmith@gmail.com', '-p', 'secret', ], cwd=rootDir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) @@ -43,7 +43,7 @@ class TestVerboseOutput(unittest.TestCase): def test_private_info_eq(self): outp = subprocess.Popen( [ - sys.executable, 'youtube_dl/__main__.py', '-v', + sys.executable, 'youtube_dlc/__main__.py', '-v', '--username=johnsmith@gmail.com', '--password=secret', ], cwd=rootDir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) @@ -56,7 +56,7 @@ class TestVerboseOutput(unittest.TestCase): def test_private_info_shortarg_eq(self): outp = subprocess.Popen( [ - sys.executable, 'youtube_dl/__main__.py', '-v', + sys.executable, 'youtube_dlc/__main__.py', '-v', '-u=johnsmith@gmail.com', '-p=secret', ], cwd=rootDir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) diff --git a/test/test_write_annotations.py b/test/test_write_annotations.py index 41abdfe3b..d98c96c15 100644 --- a/test/test_write_annotations.py +++ b/test/test_write_annotations.py @@ -15,11 +15,11 @@ import io import xml.etree.ElementTree -import youtube_dl.YoutubeDL -import youtube_dl.extractor +import youtube_dlc.YoutubeDL +import youtube_dlc.extractor -class YoutubeDL(youtube_dl.YoutubeDL): +class YoutubeDL(youtube_dlc.YoutubeDL): def __init__(self, *args, **kwargs): super(YoutubeDL, self).__init__(*args, **kwargs) self.to_stderr = self.to_screen @@ -45,7 +45,7 @@ class TestAnnotations(unittest.TestCase): def test_info_json(self): expected = list(EXPECTED_ANNOTATIONS) # Two annotations could have the same text. - ie = youtube_dl.extractor.YoutubeIE() + ie = youtube_dlc.extractor.YoutubeIE() ydl = YoutubeDL(params) ydl.add_info_extractor(ie) ydl.download([TEST_ID]) diff --git a/test/test_youtube_chapters.py b/test/test_youtube_chapters.py index 324ca8525..4529d2e84 100644 --- a/test/test_youtube_chapters.py +++ b/test/test_youtube_chapters.py @@ -9,7 +9,7 @@ import unittest sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from test.helper import expect_value -from youtube_dl.extractor import YoutubeIE +from youtube_dlc.extractor import YoutubeIE class TestYoutubeChapters(unittest.TestCase): @@ -267,7 +267,7 @@ class TestYoutubeChapters(unittest.TestCase): for description, duration, expected_chapters in self._TEST_CASES: ie = YoutubeIE() expect_value( - self, ie._extract_chapters(description, duration), + self, ie._extract_chapters_from_description(description, duration), expected_chapters, None) diff --git a/test/test_youtube_lists.py b/test/test_youtube_lists.py index c4f0abbea..a693963ef 100644 --- a/test/test_youtube_lists.py +++ b/test/test_youtube_lists.py @@ -10,7 +10,7 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from test.helper import FakeYDL -from youtube_dl.extractor import ( +from youtube_dlc.extractor import ( YoutubePlaylistIE, YoutubeIE, ) diff --git a/test/test_youtube_signature.py b/test/test_youtube_signature.py index f0c370eee..a54b36198 100644 --- a/test/test_youtube_signature.py +++ b/test/test_youtube_signature.py @@ -13,8 +13,8 @@ import re import string from test.helper import FakeYDL -from youtube_dl.extractor import YoutubeIE -from youtube_dl.compat import compat_str, compat_urlretrieve +from youtube_dlc.extractor import YoutubeIE +from youtube_dlc.compat import compat_str, compat_urlretrieve _TESTS = [ ( @@ -74,6 +74,28 @@ _TESTS = [ ] +class TestPlayerInfo(unittest.TestCase): + def test_youtube_extract_player_info(self): + PLAYER_URLS = ( + ('https://www.youtube.com/s/player/64dddad9/player_ias.vflset/en_US/base.js', '64dddad9'), + # obsolete + ('https://www.youtube.com/yts/jsbin/player_ias-vfle4-e03/en_US/base.js', 'vfle4-e03'), + ('https://www.youtube.com/yts/jsbin/player_ias-vfl49f_g4/en_US/base.js', 'vfl49f_g4'), + ('https://www.youtube.com/yts/jsbin/player_ias-vflCPQUIL/en_US/base.js', 'vflCPQUIL'), + ('https://www.youtube.com/yts/jsbin/player-vflzQZbt7/en_US/base.js', 'vflzQZbt7'), + ('https://www.youtube.com/yts/jsbin/player-en_US-vflaxXRn1/base.js', 'vflaxXRn1'), + ('https://s.ytimg.com/yts/jsbin/html5player-en_US-vflXGBaUN.js', 'vflXGBaUN'), + ('https://s.ytimg.com/yts/jsbin/html5player-en_US-vflKjOTVq/html5player.js', 'vflKjOTVq'), + ('http://s.ytimg.com/yt/swfbin/watch_as3-vflrEm9Nq.swf', 'vflrEm9Nq'), + ('https://s.ytimg.com/yts/swfbin/player-vflenCdZL/watch_as3.swf', 'vflenCdZL'), + ) + for player_url, expected_player_id in PLAYER_URLS: + expected_player_type = player_url.split('.')[-1] + player_type, player_id = YoutubeIE._extract_player_info(player_url) + self.assertEqual(player_type, expected_player_type) + self.assertEqual(player_id, expected_player_id) + + class TestSignature(unittest.TestCase): def setUp(self): TEST_DIR = os.path.dirname(os.path.abspath(__file__)) diff --git a/test/testdata/cookies/malformed_cookies.txt b/test/testdata/cookies/malformed_cookies.txt new file mode 100644 index 000000000..17bc40354 --- /dev/null +++ b/test/testdata/cookies/malformed_cookies.txt @@ -0,0 +1,9 @@ +# Netscape HTTP Cookie File +# http://curl.haxx.se/rfc/cookie_spec.html +# This is a generated file! Do not edit. + +# Cookie file entry with invalid number of fields - 6 instead of 7 +www.foobar.foobar FALSE / FALSE 0 COOKIE + +# Cookie file entry with invalid expires at +www.foobar.foobar FALSE / FALSE 1.7976931348623157e+308 COOKIE VALUE |