1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2024-12-13 17:16:16 +01:00
yt-dlp/test/test_execution.py

58 lines
1.8 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
# Allow direct execution
2012-12-01 15:52:34 +01:00
import os
import sys
import unittest
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import contextlib
import subprocess
from yt_dlp.utils import Popen
2012-12-01 15:52:34 +01:00
rootDir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
LAZY_EXTRACTORS = 'yt_dlp/extractor/lazy_extractors.py'
2012-12-01 15:52:34 +01:00
2014-11-16 15:17:48 +01:00
class TestExecution(unittest.TestCase):
def run_yt_dlp(self, exe=(sys.executable, 'yt_dlp/__main__.py'), opts=('--version', )):
stdout, stderr, returncode = Popen.run(
[*exe, '--ignore-config', *opts], cwd=rootDir, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print(stderr, file=sys.stderr)
self.assertEqual(returncode, 0)
return stdout.strip(), stderr.strip()
2012-12-01 15:52:34 +01:00
def test_main_exec(self):
self.run_yt_dlp()
2014-11-16 15:17:48 +01:00
2012-12-01 15:52:34 +01:00
def test_import(self):
self.run_yt_dlp(exe=(sys.executable, '-c', 'import yt_dlp'))
2012-12-01 15:52:34 +01:00
def test_module_exec(self):
self.run_yt_dlp(exe=(sys.executable, '-m', 'yt_dlp'))
2012-12-01 15:52:34 +01:00
def test_cmdline_umlauts(self):
_, stderr = self.run_yt_dlp(opts=('ä', '--version'))
self.assertFalse(stderr)
def test_lazy_extractors(self):
try:
subprocess.check_call([sys.executable, 'devscripts/make_lazy_extractors.py', LAZY_EXTRACTORS],
cwd=rootDir, stdout=subprocess.DEVNULL)
self.assertTrue(os.path.exists(LAZY_EXTRACTORS))
_, stderr = self.run_yt_dlp(opts=('-s', 'test:'))
self.assertFalse(stderr)
subprocess.check_call([sys.executable, 'test/test_all_urls.py'], cwd=rootDir, stdout=subprocess.DEVNULL)
finally:
with contextlib.suppress(OSError):
os.remove(LAZY_EXTRACTORS)
2012-12-01 15:52:34 +01:00
if __name__ == '__main__':
unittest.main()