]> jfr.im git - yt-dlp.git/blame - test/test_execution.py
[cleanup] Add more ruff rules (#10149)
[yt-dlp.git] / test / test_execution.py
CommitLineData
cc52de43 1#!/usr/bin/env python3
54007a45 2
3# Allow direct execution
e575b682 4import os
f8271158 5import sys
6import unittest
7
ff02a228
S
8sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
9
54007a45 10
11import contextlib
12import subprocess
13
e5458d1d 14from yt_dlp.utils import Popen
e575b682
PH
15
16rootDir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
e5458d1d 17LAZY_EXTRACTORS = 'yt_dlp/extractor/lazy_extractors.py'
e575b682 18
a0f59cdc 19
e5458d1d 20class TestExecution(unittest.TestCase):
21 def run_yt_dlp(self, exe=(sys.executable, 'yt_dlp/__main__.py'), opts=('--version', )):
22 stdout, stderr, returncode = Popen.run(
23 [*exe, '--ignore-config', *opts], cwd=rootDir, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
24 print(stderr, file=sys.stderr)
25 self.assertEqual(returncode, 0)
26 return stdout.strip(), stderr.strip()
e575b682 27
e5458d1d 28 def test_main_exec(self):
29 self.run_yt_dlp()
a0f59cdc 30
e575b682 31 def test_import(self):
e5458d1d 32 self.run_yt_dlp(exe=(sys.executable, '-c', 'import yt_dlp'))
e575b682
PH
33
34 def test_module_exec(self):
e5458d1d 35 self.run_yt_dlp(exe=(sys.executable, '-m', 'yt_dlp'))
e575b682 36
f5e2efbb 37 def test_cmdline_umlauts(self):
e5458d1d 38 _, stderr = self.run_yt_dlp(opts=('ä', '--version'))
f5e2efbb
PH
39 self.assertFalse(stderr)
40
1bdae7d3 41 def test_lazy_extractors(self):
42 try:
e5458d1d 43 subprocess.check_call([sys.executable, 'devscripts/make_lazy_extractors.py', LAZY_EXTRACTORS],
44 cwd=rootDir, stdout=subprocess.DEVNULL)
45 self.assertTrue(os.path.exists(LAZY_EXTRACTORS))
46
47 _, stderr = self.run_yt_dlp(opts=('-s', 'test:'))
47ab66db 48 # `MIN_RECOMMENDED` emits a deprecated feature warning for deprecated Python versions
61bdf15f
SS
49 if stderr and stderr.startswith('Deprecated Feature: Support for Python'):
50 stderr = ''
e5458d1d 51 self.assertFalse(stderr)
52
53 subprocess.check_call([sys.executable, 'test/test_all_urls.py'], cwd=rootDir, stdout=subprocess.DEVNULL)
1bdae7d3 54 finally:
19a03940 55 with contextlib.suppress(OSError):
e5458d1d 56 os.remove(LAZY_EXTRACTORS)
1bdae7d3 57
582be358 58
e575b682
PH
59if __name__ == '__main__':
60 unittest.main()