]>
Commit | Line | Data |
---|---|---|
cc52de43 | 1 | #!/usr/bin/env python3 |
54007a45 | 2 | |
3 | # Allow direct execution | |
e575b682 | 4 | import os |
f8271158 | 5 | import sys |
6 | import unittest | |
7 | ||
ff02a228 S |
8 | sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
9 | ||
54007a45 | 10 | |
11 | import contextlib | |
12 | import subprocess | |
13 | ||
e5458d1d | 14 | from yt_dlp.utils import Popen |
e575b682 PH |
15 | |
16 | rootDir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
e5458d1d | 17 | LAZY_EXTRACTORS = 'yt_dlp/extractor/lazy_extractors.py' |
e575b682 | 18 | |
a0f59cdc | 19 | |
e5458d1d | 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() | |
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:')) | |
48 | self.assertFalse(stderr) | |
49 | ||
50 | subprocess.check_call([sys.executable, 'test/test_all_urls.py'], cwd=rootDir, stdout=subprocess.DEVNULL) | |
1bdae7d3 | 51 | finally: |
19a03940 | 52 | with contextlib.suppress(OSError): |
e5458d1d | 53 | os.remove(LAZY_EXTRACTORS) |
1bdae7d3 | 54 | |
582be358 | 55 | |
e575b682 PH |
56 | if __name__ == '__main__': |
57 | unittest.main() |