diff options
author | Alex Merkel <mail@alexmerkel.com> | 2020-12-29 16:03:07 +0100 |
---|---|---|
committer | pukkandan <pukkandan@gmail.com> | 2021-01-09 16:00:49 +0530 |
commit | ab8e5e516f38c3eab8947614e2347a2473e5dbbc (patch) | |
tree | 48040b0af24439d51ea923efcaf9f48f4bfca477 /test/test_post_hooks.py | |
parent | 62d80ba17c5d4f06c324991b076597ec8c5a8c33 (diff) | |
download | hypervideo-pre-ab8e5e516f38c3eab8947614e2347a2473e5dbbc.tar.lz hypervideo-pre-ab8e5e516f38c3eab8947614e2347a2473e5dbbc.tar.xz hypervideo-pre-ab8e5e516f38c3eab8947614e2347a2473e5dbbc.zip |
Add post_hooks option to YoutubeDL.py (https://github.com/ytdl-org/youtube-dl/pull/27573)
Authored by: alexmerkel
Diffstat (limited to 'test/test_post_hooks.py')
-rw-r--r-- | test/test_post_hooks.py | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/test/test_post_hooks.py b/test/test_post_hooks.py new file mode 100644 index 000000000..d8d2b36c3 --- /dev/null +++ b/test/test_post_hooks.py @@ -0,0 +1,68 @@ +#!/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() |