]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/env python3 | |
2 | ||
3 | # Allow direct execution | |
4 | import os | |
5 | import sys | |
6 | import unittest | |
7 | ||
8 | sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
9 | ||
10 | ||
11 | import contextlib | |
12 | import subprocess | |
13 | ||
14 | from yt_dlp.utils import Popen | |
15 | ||
16 | rootDir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
17 | LAZY_EXTRACTORS = 'yt_dlp/extractor/lazy_extractors.py' | |
18 | ||
19 | ||
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() | |
27 | ||
28 | def test_main_exec(self): | |
29 | self.run_yt_dlp() | |
30 | ||
31 | def test_import(self): | |
32 | self.run_yt_dlp(exe=(sys.executable, '-c', 'import yt_dlp')) | |
33 | ||
34 | def test_module_exec(self): | |
35 | self.run_yt_dlp(exe=(sys.executable, '-m', 'yt_dlp')) | |
36 | ||
37 | def test_cmdline_umlauts(self): | |
38 | _, stderr = self.run_yt_dlp(opts=('รค', '--version')) | |
39 | self.assertFalse(stderr) | |
40 | ||
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)) | |
46 | ||
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) | |
52 | ||
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) | |
57 | ||
58 | ||
59 | if __name__ == '__main__': | |
60 | unittest.main() |