A feature-rich command-line audio/video downloader
[tests] Modernize
Philipp Hagemeistera0f59cdcb405
diff --git a/test/test_age_restriction.py b/test/test_age_restriction.pyindex 71e80b037a..5be065c437 100644--- a/test/test_age_restriction.py+++ b/test/test_age_restriction.py@@ -1,4 +1,5 @@#!/usr/bin/env python+from __future__ import unicode_literals# Allow direct executionimport os@@ -19,7 +20,7 @@ def _download_restricted(url, filename, age):'age_limit': age,'skip_download': True,'writeinfojson': True,- "outtmpl": "%(id)s.%(ext)s",+ 'outtmpl': '%(id)s.%(ext)s',}ydl = YoutubeDL(params)ydl.add_default_info_extractors()diff --git a/test/test_download.py b/test/test_download.pyindex 87aced97cf..12cfb5cbe4 100644--- a/test/test_download.py+++ b/test/test_download.py@@ -1,5 +1,7 @@#!/usr/bin/env python+from __future__ import unicode_literals+# Allow direct executionimport osimport sys@@ -210,9 +212,9 @@ for n, test_case in enumerate(defs):tname = 'test_' + str(test_case['name'])i = 1while hasattr(TestDownload, tname):- tname = 'test_' + str(test_case['name']) + '_' + str(i)+ tname = 'test_%s_%d' % (test_case['name'], i)i += 1- test_method.__name__ = tname+ test_method.__name__ = str(tname)setattr(TestDownload, test_method.__name__, test_method)del test_methoddiff --git a/test/test_execution.py b/test/test_execution.pyindex 2b115fb31a..60df187de4 100644--- a/test/test_execution.py+++ b/test/test_execution.py@@ -1,3 +1,6 @@+#!/usr/bin/env python+from __future__ import unicode_literals+import unittestimport sys@@ -6,17 +9,19 @@ import subprocessrootDir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))+try:_DEV_NULL = subprocess.DEVNULLexcept AttributeError:_DEV_NULL = open(os.devnull, 'wb')+class TestExecution(unittest.TestCase):def test_import(self):subprocess.check_call([sys.executable, '-c', 'import youtube_dl'], cwd=rootDir)def test_module_exec(self):- if sys.version_info >= (2,7): # Python 2.6 doesn't support package execution+ if sys.version_info >= (2, 7): # Python 2.6 doesn't support package executionsubprocess.check_call([sys.executable, '-m', 'youtube_dl', '--version'], cwd=rootDir, stdout=_DEV_NULL)def test_main_exec(self):diff --git a/test/test_subtitles.py b/test/test_subtitles.pyindex 8f4602e5f6..94e3290db6 100644--- a/test/test_subtitles.py+++ b/test/test_subtitles.py@@ -1,4 +1,5 @@#!/usr/bin/env python+from __future__ import unicode_literals# Allow direct executionimport os@@ -74,7 +75,7 @@ class TestYoutubeSubtitles(BaseTestSubtitles):self.assertEqual(md5(subtitles['en']), '3cb210999d3e021bd6c7f0ea751eab06')def test_youtube_list_subtitles(self):- self.DL.expect_warning(u'Video doesn\'t have automatic captions')+ self.DL.expect_warning('Video doesn\'t have automatic captions')self.DL.params['listsubtitles'] = Trueinfo_dict = self.getInfoDict()self.assertEqual(info_dict, None)@@ -87,7 +88,7 @@ class TestYoutubeSubtitles(BaseTestSubtitles):self.assertTrue(subtitles['it'] is not None)def test_youtube_nosubtitles(self):- self.DL.expect_warning(u'video doesn\'t have subtitles')+ self.DL.expect_warning('video doesn\'t have subtitles')self.url = 'n5BB19UTcdA'self.DL.params['writesubtitles'] = Trueself.DL.params['allsubtitles'] = True@@ -101,7 +102,7 @@ class TestYoutubeSubtitles(BaseTestSubtitles):self.DL.params['subtitleslangs'] = langssubtitles = self.getSubtitles()for lang in langs:- self.assertTrue(subtitles.get(lang) is not None, u'Subtitles for \'%s\' not extracted' % lang)+ self.assertTrue(subtitles.get(lang) is not None, 'Subtitles for \'%s\' not extracted' % lang)class TestDailymotionSubtitles(BaseTestSubtitles):@@ -130,20 +131,20 @@ class TestDailymotionSubtitles(BaseTestSubtitles):self.assertEqual(len(subtitles.keys()), 5)def test_list_subtitles(self):- self.DL.expect_warning(u'Automatic Captions not supported by this server')+ self.DL.expect_warning('Automatic Captions not supported by this server')self.DL.params['listsubtitles'] = Trueinfo_dict = self.getInfoDict()self.assertEqual(info_dict, None)def test_automatic_captions(self):- self.DL.expect_warning(u'Automatic Captions not supported by this server')+ self.DL.expect_warning('Automatic Captions not supported by this server')self.DL.params['writeautomaticsub'] = Trueself.DL.params['subtitleslang'] = ['en']subtitles = self.getSubtitles()self.assertTrue(len(subtitles.keys()) == 0)def test_nosubtitles(self):- self.DL.expect_warning(u'video doesn\'t have subtitles')+ self.DL.expect_warning('video doesn\'t have subtitles')self.url = 'http://www.dailymotion.com/video/x12u166_le-zapping-tele-star-du-08-aout-2013_tv'self.DL.params['writesubtitles'] = Trueself.DL.params['allsubtitles'] = True@@ -156,7 +157,7 @@ class TestDailymotionSubtitles(BaseTestSubtitles):self.DL.params['subtitleslangs'] = langssubtitles = self.getSubtitles()for lang in langs:- self.assertTrue(subtitles.get(lang) is not None, u'Subtitles for \'%s\' not extracted' % lang)+ self.assertTrue(subtitles.get(lang) is not None, 'Subtitles for \'%s\' not extracted' % lang)class TestTedSubtitles(BaseTestSubtitles):@@ -185,13 +186,13 @@ class TestTedSubtitles(BaseTestSubtitles):self.assertTrue(len(subtitles.keys()) >= 28)def test_list_subtitles(self):- self.DL.expect_warning(u'Automatic Captions not supported by this server')+ self.DL.expect_warning('Automatic Captions not supported by this server')self.DL.params['listsubtitles'] = Trueinfo_dict = self.getInfoDict()self.assertEqual(info_dict, None)def test_automatic_captions(self):- self.DL.expect_warning(u'Automatic Captions not supported by this server')+ self.DL.expect_warning('Automatic Captions not supported by this server')self.DL.params['writeautomaticsub'] = Trueself.DL.params['subtitleslang'] = ['en']subtitles = self.getSubtitles()@@ -203,7 +204,7 @@ class TestTedSubtitles(BaseTestSubtitles):self.DL.params['subtitleslangs'] = langssubtitles = self.getSubtitles()for lang in langs:- self.assertTrue(subtitles.get(lang) is not None, u'Subtitles for \'%s\' not extracted' % lang)+ self.assertTrue(subtitles.get(lang) is not None, 'Subtitles for \'%s\' not extracted' % lang)class TestBlipTVSubtitles(BaseTestSubtitles):@@ -211,13 +212,13 @@ class TestBlipTVSubtitles(BaseTestSubtitles):IE = BlipTVIEdef test_list_subtitles(self):- self.DL.expect_warning(u'Automatic Captions not supported by this server')+ self.DL.expect_warning('Automatic Captions not supported by this server')self.DL.params['listsubtitles'] = Trueinfo_dict = self.getInfoDict()self.assertEqual(info_dict, None)def test_allsubtitles(self):- self.DL.expect_warning(u'Automatic Captions not supported by this server')+ self.DL.expect_warning('Automatic Captions not supported by this server')self.DL.params['writesubtitles'] = Trueself.DL.params['allsubtitles'] = Truesubtitles = self.getSubtitles()@@ -251,20 +252,20 @@ class TestVimeoSubtitles(BaseTestSubtitles):self.assertEqual(set(subtitles.keys()), set(['de', 'en', 'es', 'fr']))def test_list_subtitles(self):- self.DL.expect_warning(u'Automatic Captions not supported by this server')+ self.DL.expect_warning('Automatic Captions not supported by this server')self.DL.params['listsubtitles'] = Trueinfo_dict = self.getInfoDict()self.assertEqual(info_dict, None)def test_automatic_captions(self):- self.DL.expect_warning(u'Automatic Captions not supported by this server')+ self.DL.expect_warning('Automatic Captions not supported by this server')self.DL.params['writeautomaticsub'] = Trueself.DL.params['subtitleslang'] = ['en']subtitles = self.getSubtitles()self.assertTrue(len(subtitles.keys()) == 0)def test_nosubtitles(self):- self.DL.expect_warning(u'video doesn\'t have subtitles')+ self.DL.expect_warning('video doesn\'t have subtitles')self.url = 'http://vimeo.com/56015672'self.DL.params['writesubtitles'] = Trueself.DL.params['allsubtitles'] = True@@ -277,7 +278,7 @@ class TestVimeoSubtitles(BaseTestSubtitles):self.DL.params['subtitleslangs'] = langssubtitles = self.getSubtitles()for lang in langs:- self.assertTrue(subtitles.get(lang) is not None, u'Subtitles for \'%s\' not extracted' % lang)+ self.assertTrue(subtitles.get(lang) is not None, 'Subtitles for \'%s\' not extracted' % lang)class TestWallaSubtitles(BaseTestSubtitles):@@ -285,13 +286,13 @@ class TestWallaSubtitles(BaseTestSubtitles):IE = WallaIEdef test_list_subtitles(self):- self.DL.expect_warning(u'Automatic Captions not supported by this server')+ self.DL.expect_warning('Automatic Captions not supported by this server')self.DL.params['listsubtitles'] = Trueinfo_dict = self.getInfoDict()self.assertEqual(info_dict, None)def test_allsubtitles(self):- self.DL.expect_warning(u'Automatic Captions not supported by this server')+ self.DL.expect_warning('Automatic Captions not supported by this server')self.DL.params['writesubtitles'] = Trueself.DL.params['allsubtitles'] = Truesubtitles = self.getSubtitles()@@ -299,7 +300,7 @@ class TestWallaSubtitles(BaseTestSubtitles):self.assertEqual(md5(subtitles['heb']), 'e758c5d7cb982f6bef14f377ec7a3920')def test_nosubtitles(self):- self.DL.expect_warning(u'video doesn\'t have subtitles')+ self.DL.expect_warning('video doesn\'t have subtitles')self.url = 'http://vod.walla.co.il/movie/2642630/one-direction-all-for-one'self.DL.params['writesubtitles'] = Trueself.DL.params['allsubtitles'] = Truediff --git a/test/test_swfinterp.py b/test/test_swfinterp.pyindex 273e0f0743..9f18055e62 100644--- a/test/test_swfinterp.py+++ b/test/test_swfinterp.py@@ -1,4 +1,5 @@#!/usr/bin/env python+from __future__ import unicode_literals# Allow direct executionimport os