aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rwxr-xr-xtest/gentests.py18
-rw-r--r--test/test_download.py42
-rw-r--r--test/test_execution.py26
-rw-r--r--test/test_import.py13
-rw-r--r--test/test_utils.py7
-rw-r--r--test/test_youtube_playlist_ids.py22
-rw-r--r--test/tests.json14
7 files changed, 89 insertions, 53 deletions
diff --git a/test/gentests.py b/test/gentests.py
index c3cca5156..9352d6d94 100755
--- a/test/gentests.py
+++ b/test/gentests.py
@@ -34,31 +34,19 @@ import youtube_dl.InfoExtractors
def _file_md5(fn):
with open(fn, 'rb') as f:
return hashlib.md5(f.read()).hexdigest()
-
-def md5_for_file(filename, block_size=2**20):
- with open(filename) as f:
- md5 = hashlib.md5()
- while True:
- data = f.read(block_size)
- if not data:
- break
- md5.update(data)
- return md5.hexdigest()
-_file_md5 = md5_for_file
-
-
try:
_skip_unless = unittest.skipUnless
except AttributeError: # Python 2.6
def _skip_unless(cond, reason='No reason given'):
def resfunc(f):
- def wfunc(*args, **kwargs):
+ # Start the function name with test to appease nosetests-2.6
+ def test_wfunc(*args, **kwargs):
if cond:
return f(*args, **kwargs)
else:
print('Skipped test')
return
- return wfunc
+ return test_wfunc
return resfunc
_skip = lambda *args, **kwargs: _skip_unless(False, *args, **kwargs)
diff --git a/test/test_download.py b/test/test_download.py
index b7cb6cebb..6926dd04e 100644
--- a/test/test_download.py
+++ b/test/test_download.py
@@ -20,31 +20,19 @@ import youtube_dl.InfoExtractors
def _file_md5(fn):
with open(fn, 'rb') as f:
return hashlib.md5(f.read()).hexdigest()
-
-def md5_for_file(filename, block_size=2**20):
- with open(filename) as f:
- md5 = hashlib.md5()
- while True:
- data = f.read(block_size)
- if not data:
- break
- md5.update(data)
- return md5.hexdigest()
-_file_md5 = md5_for_file
-
-
try:
_skip_unless = unittest.skipUnless
except AttributeError: # Python 2.6
def _skip_unless(cond, reason='No reason given'):
def resfunc(f):
- def wfunc(*args, **kwargs):
+ # Start the function name with test to appease nosetests-2.6
+ def test_wfunc(*args, **kwargs):
if cond:
return f(*args, **kwargs)
else:
print('Skipped test')
return
- return wfunc
+ return test_wfunc
return resfunc
_skip = lambda *args, **kwargs: _skip_unless(False, *args, **kwargs)
@@ -79,7 +67,7 @@ class DownloadTest(unittest.TestCase):
@_skip_unless(youtube_dl.InfoExtractors.MetacafeIE._WORKING, "IE marked as not _WORKING")
def test_Metacafe(self):
- filename = 'aUehQsCQtM.flv'
+ filename = '_aUehQsCQtM.flv'
fd = FileDownloader(self.parameters)
fd.add_info_extractor(youtube_dl.InfoExtractors.MetacafeIE())
fd.add_info_extractor(youtube_dl.InfoExtractors.YoutubeIE())
@@ -120,7 +108,7 @@ class DownloadTest(unittest.TestCase):
@_skip_unless(youtube_dl.InfoExtractors.SoundcloudIE._WORKING, "IE marked as not _WORKING")
def test_Soundcloud(self):
- filename = 'n6FLbx6ZzMiu.mp3'
+ filename = '62986583.mp3'
fd = FileDownloader(self.parameters)
fd.add_info_extractor(youtube_dl.InfoExtractors.SoundcloudIE())
fd.download(['http://soundcloud.com/ethmusic/lostin-powers-she-so-heavy'])
@@ -159,26 +147,38 @@ class DownloadTest(unittest.TestCase):
md5_for_file = _file_md5(filename)
self.assertEqual(md5_for_file, 'c5c67df477eb0d9b058200351448ba4c')
+ @_skip_unless(youtube_dl.InfoExtractors.YoukuIE._WORKING, "IE marked as not _WORKING")
+ def test_Youku(self):
+ filename = 'XNDgyMDQ2NTQw_part00.flv'
+ fd = FileDownloader(self.parameters)
+ fd.add_info_extractor(youtube_dl.InfoExtractors.YoukuIE())
+ fd.download(['http://v.youku.com/v_show/id_XNDgyMDQ2NTQw.html'])
+ self.assertTrue(os.path.exists(filename))
+ md5_for_file = _file_md5(filename)
+ self.assertEqual(md5_for_file, 'ffe3f2e435663dc2d1eea34faeff5b5b')
+
def tearDown(self):
if os.path.exists('BaW_jenozKc.mp4'):
os.remove('BaW_jenozKc.mp4')
if os.path.exists('x33vw9.mp4'):
os.remove('x33vw9.mp4')
- if os.path.exists('aUehQsCQtM.flv'):
- os.remove('aUehQsCQtM.flv')
+ if os.path.exists('_aUehQsCQtM.flv'):
+ os.remove('_aUehQsCQtM.flv')
if os.path.exists('5779306.m4v'):
os.remove('5779306.m4v')
if os.path.exists('939581.flv'):
os.remove('939581.flv')
# No file specified for Vimeo
- if os.path.exists('n6FLbx6ZzMiu.mp3'):
- os.remove('n6FLbx6ZzMiu.mp3')
+ if os.path.exists('62986583.mp3'):
+ os.remove('62986583.mp3')
if os.path.exists('PracticalUnix_intro-environment.mp4'):
os.remove('PracticalUnix_intro-environment.mp4')
# No file specified for CollegeHumor
if os.path.exists('1135332.flv'):
os.remove('1135332.flv')
+ if os.path.exists('XNDgyMDQ2NTQw_part00.flv'):
+ os.remove('XNDgyMDQ2NTQw_part00.flv')
diff --git a/test/test_execution.py b/test/test_execution.py
new file mode 100644
index 000000000..2b115fb31
--- /dev/null
+++ b/test/test_execution.py
@@ -0,0 +1,26 @@
+import unittest
+
+import sys
+import os
+import subprocess
+
+rootDir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+
+try:
+ _DEV_NULL = subprocess.DEVNULL
+except 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
+ subprocess.check_call([sys.executable, '-m', 'youtube_dl', '--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)
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/test/test_import.py b/test/test_import.py
deleted file mode 100644
index acf95444d..000000000
--- a/test/test_import.py
+++ /dev/null
@@ -1,13 +0,0 @@
-import unittest
-
-import sys
-import os.path
-import subprocess
-
-class TestImport(unittest.TestCase):
- def test_import(self):
- rootDir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
- subprocess.check_call([sys.executable, '-c', 'import youtube_dl'], cwd=rootDir)
-
-if __name__ == '__main__':
- unittest.main()
diff --git a/test/test_utils.py b/test/test_utils.py
index fd8190f51..796ed4ab2 100644
--- a/test/test_utils.py
+++ b/test/test_utils.py
@@ -1,3 +1,5 @@
+#!/usr/bin/env python
+
# Various small unit tests
import sys
@@ -79,6 +81,11 @@ class TestUtil(unittest.TestCase):
self.assertTrue(sanitize_filename('-', restricted=True) != '')
self.assertTrue(sanitize_filename(':', restricted=True) != '')
+ def test_sanitize_ids(self):
+ self.assertEquals(sanitize_filename('_n_cd26wFpw', is_id=True), '_n_cd26wFpw')
+ self.assertEquals(sanitize_filename('_BD_eEpuzXw', is_id=True), '_BD_eEpuzXw')
+ self.assertEquals(sanitize_filename('N0Y__7-UOdI', is_id=True), 'N0Y__7-UOdI')
+
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([]), [])
diff --git a/test/test_youtube_playlist_ids.py b/test/test_youtube_playlist_ids.py
new file mode 100644
index 000000000..b4dcedb45
--- /dev/null
+++ b/test/test_youtube_playlist_ids.py
@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+
+import sys
+import unittest
+
+# Allow direct execution
+import os
+sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+
+from youtube_dl.InfoExtractors import YoutubeIE, YoutubePlaylistIE
+
+class TestYoutubePlaylistMatching(unittest.TestCase):
+ def test_playlist_matching(self):
+ assert YoutubePlaylistIE().suitable(u'ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8')
+ assert YoutubePlaylistIE().suitable(u'PL63F0C78739B09958')
+ assert not YoutubePlaylistIE().suitable(u'PLtS2H6bU1M')
+
+ def test_youtube_matching(self):
+ assert YoutubeIE().suitable(u'PLtS2H6bU1M')
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/test/tests.json b/test/tests.json
index 731c91718..cb29f2053 100644
--- a/test/tests.json
+++ b/test/tests.json
@@ -16,7 +16,7 @@
"size": 5754305,
"addIEs": ["Youtube"],
"url": "http://www.metacafe.com/watch/yt-_aUehQsCQtM/the_electric_company_short_i_pbs_kids_go/",
- "file": "aUehQsCQtM.flv"
+ "file": "_aUehQsCQtM.flv"
},
{
"name": "BlipTV",
@@ -40,7 +40,7 @@
"name": "Soundcloud",
"md5": "c1b9b9ea8bfd620b96b2628664576e1c",
"url": "http://soundcloud.com/ethmusic/lostin-powers-she-so-heavy",
- "file": "n6FLbx6ZzMiu.mp3"
+ "file": "62986583.mp3"
},
{
"name": "StanfordOpenClassroom",
@@ -54,10 +54,16 @@
"url": "http://www.collegehumor.com/video/6830834/mitt-romney-style-gangnam-style-parody",
"file": ""
},
- {
+ {
"name": "XNXX",
"md5": "c5c67df477eb0d9b058200351448ba4c",
"url": "http://video.xnxx.com/video1135332/lida_naked_funny_actress_5_",
"file": "1135332.flv"
+ },
+ {
+ "name": "Youku",
+ "url": "http://v.youku.com/v_show/id_XNDgyMDQ2NTQw.html",
+ "file": "XNDgyMDQ2NTQw_part00.flv",
+ "md5": "ffe3f2e435663dc2d1eea34faeff5b5b"
}
-] \ No newline at end of file
+]