]> jfr.im git - yt-dlp.git/blob - test/test_execution.py
[cleanup] Consistent style for file heads
[yt-dlp.git] / test / test_execution.py
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 encodeArgument
15
16 rootDir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
17
18
19 try:
20 _DEV_NULL = subprocess.DEVNULL
21 except AttributeError:
22 _DEV_NULL = open(os.devnull, 'wb')
23
24
25 class TestExecution(unittest.TestCase):
26 def test_import(self):
27 subprocess.check_call([sys.executable, '-c', 'import yt_dlp'], cwd=rootDir)
28
29 def test_module_exec(self):
30 subprocess.check_call([sys.executable, '-m', 'yt_dlp', '--ignore-config', '--version'], cwd=rootDir, stdout=_DEV_NULL)
31
32 def test_main_exec(self):
33 subprocess.check_call([sys.executable, 'yt_dlp/__main__.py', '--ignore-config', '--version'], cwd=rootDir, stdout=_DEV_NULL)
34
35 def test_cmdline_umlauts(self):
36 p = subprocess.Popen(
37 [sys.executable, 'yt_dlp/__main__.py', '--ignore-config', encodeArgument('รค'), '--version'],
38 cwd=rootDir, stdout=_DEV_NULL, stderr=subprocess.PIPE)
39 _, stderr = p.communicate()
40 self.assertFalse(stderr)
41
42 def test_lazy_extractors(self):
43 try:
44 subprocess.check_call([sys.executable, 'devscripts/make_lazy_extractors.py', 'yt_dlp/extractor/lazy_extractors.py'], cwd=rootDir, stdout=_DEV_NULL)
45 subprocess.check_call([sys.executable, 'test/test_all_urls.py'], cwd=rootDir, stdout=_DEV_NULL)
46 finally:
47 with contextlib.suppress(OSError):
48 os.remove('yt_dlp/extractor/lazy_extractors.py')
49
50
51 if __name__ == '__main__':
52 unittest.main()