mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2025-02-04 17:19:53 +00:00
Add test for post_hooks
This commit is contained in:
parent
f8d189d8bd
commit
e6abe3f933
3
Makefile
3
Makefile
@ -49,7 +49,8 @@ offlinetest: codetest
|
|||||||
--exclude test_subtitles.py \
|
--exclude test_subtitles.py \
|
||||||
--exclude test_write_annotations.py \
|
--exclude test_write_annotations.py \
|
||||||
--exclude test_youtube_lists.py \
|
--exclude test_youtube_lists.py \
|
||||||
--exclude test_youtube_signature.py
|
--exclude test_youtube_signature.py \
|
||||||
|
--exclude test_post_hooks.py
|
||||||
|
|
||||||
tar: youtube-dl.tar.gz
|
tar: youtube-dl.tar.gz
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
@echo off
|
@echo off
|
||||||
|
|
||||||
rem Keep this list in sync with the `offlinetest` target in Makefile
|
rem Keep this list in sync with the `offlinetest` target in Makefile
|
||||||
set DOWNLOAD_TESTS="age_restriction^|download^|iqiyi_sdk_interpreter^|socks^|subtitles^|write_annotations^|youtube_lists^|youtube_signature"
|
set DOWNLOAD_TESTS="age_restriction^|download^|iqiyi_sdk_interpreter^|socks^|subtitles^|write_annotations^|youtube_lists^|youtube_signature^|post_hooks"
|
||||||
|
|
||||||
if "%YTDL_TEST_SET%" == "core" (
|
if "%YTDL_TEST_SET%" == "core" (
|
||||||
set test_set="-I test_("%DOWNLOAD_TESTS%")\.py"
|
set test_set="-I test_("%DOWNLOAD_TESTS%")\.py"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Keep this list in sync with the `offlinetest` target in Makefile
|
# Keep this list in sync with the `offlinetest` target in Makefile
|
||||||
DOWNLOAD_TESTS="age_restriction|download|iqiyi_sdk_interpreter|socks|subtitles|write_annotations|youtube_lists|youtube_signature"
|
DOWNLOAD_TESTS="age_restriction|download|iqiyi_sdk_interpreter|socks|subtitles|write_annotations|youtube_lists|youtube_signature|post_hooks"
|
||||||
|
|
||||||
test_set=""
|
test_set=""
|
||||||
multiprocess_args=""
|
multiprocess_args=""
|
||||||
|
64
test/test_post_hooks.py
Normal file
64
test/test_post_hooks.py
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
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 test.helper import get_params, try_rm
|
||||||
|
import youtube_dl.YoutubeDL
|
||||||
|
from youtube_dl.utils import DownloadError
|
||||||
|
|
||||||
|
class YoutubeDL(youtube_dl.YoutubeDL):
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(YoutubeDL, self).__init__(*args, **kwargs)
|
||||||
|
self.to_stderr = self.to_screen
|
||||||
|
|
||||||
|
TEST_ID = 'gr51aVj-mLg'
|
||||||
|
EXPECTED_NAME = 'gr51aVj-mLg'
|
||||||
|
|
||||||
|
class TestPostHooks(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.stored_name_1 = None
|
||||||
|
self.stored_name_2 = None
|
||||||
|
self.params = get_params({
|
||||||
|
'skip_download': False,
|
||||||
|
'writeinfojson': False,
|
||||||
|
'quiet': True,
|
||||||
|
'verbose': False,
|
||||||
|
'cachedir': False,
|
||||||
|
})
|
||||||
|
self.files = []
|
||||||
|
|
||||||
|
def test_post_hooks(self):
|
||||||
|
self.params['post_hooks'] = [self.hook_one, self.hook_two]
|
||||||
|
ydl = YoutubeDL(self.params)
|
||||||
|
ydl.download([TEST_ID])
|
||||||
|
self.assertEqual(self.stored_name_1, EXPECTED_NAME, 'Not the expected name from hook 1')
|
||||||
|
self.assertEqual(self.stored_name_2, EXPECTED_NAME, 'Not the expected name from hook 2')
|
||||||
|
|
||||||
|
def test_post_hook_exception(self):
|
||||||
|
self.params['post_hooks'] = [self.hook_three]
|
||||||
|
ydl = YoutubeDL(self.params)
|
||||||
|
self.assertRaises(DownloadError, ydl.download, [TEST_ID])
|
||||||
|
|
||||||
|
def hook_one(self,filename):
|
||||||
|
self.stored_name_1, _ = os.path.splitext(os.path.basename(filename))
|
||||||
|
self.files.append(filename)
|
||||||
|
|
||||||
|
def hook_two(self,filename):
|
||||||
|
self.stored_name_2, _ = os.path.splitext(os.path.basename(filename))
|
||||||
|
self.files.append(filename)
|
||||||
|
|
||||||
|
def hook_three(self,filename):
|
||||||
|
self.files.append(filename)
|
||||||
|
raise Exception('Test exception for \'%s\'' % filename)
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
for f in self.files:
|
||||||
|
try_rm(f)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
Loading…
Reference in New Issue
Block a user