[ie/neteasemusic] Fix extractors (#8181)
[yt-dlp3.git] / test / test_execution.py
blobfb2f6e2e9ce4fc8d508bcb291c01417d2f16b7de
1 #!/usr/bin/env python3
3 # Allow direct execution
4 import os
5 import sys
6 import unittest
8 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
11 import contextlib
12 import subprocess
14 from yt_dlp.utils import Popen
16 rootDir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
17 LAZY_EXTRACTORS = 'yt_dlp/extractor/lazy_extractors.py'
20 class 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()
28 def test_main_exec(self):
29 self.run_yt_dlp()
31 def test_import(self):
32 self.run_yt_dlp(exe=(sys.executable, '-c', 'import yt_dlp'))
34 def test_module_exec(self):
35 self.run_yt_dlp(exe=(sys.executable, '-m', 'yt_dlp'))
37 def test_cmdline_umlauts(self):
38 _, stderr = self.run_yt_dlp(opts=('รค', '--version'))
39 self.assertFalse(stderr)
41 def test_lazy_extractors(self):
42 try:
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))
47 _, stderr = self.run_yt_dlp(opts=('-s', 'test:'))
48 # `MIN_RECOMMENDED` emits a deprecated feature warning for deprecated python versions
49 if stderr and stderr.startswith('Deprecated Feature: Support for Python'):
50 stderr = ''
51 self.assertFalse(stderr)
53 subprocess.check_call([sys.executable, 'test/test_all_urls.py'], cwd=rootDir, stdout=subprocess.DEVNULL)
54 finally:
55 with contextlib.suppress(OSError):
56 os.remove(LAZY_EXTRACTORS)
59 if __name__ == '__main__':
60 unittest.main()