]> jfr.im git - yt-dlp.git/blame - test/test_execution.py
[cleanup] Misc cleanup and refactor (#2173)
[yt-dlp.git] / test / test_execution.py
CommitLineData
cc52de43 1#!/usr/bin/env python3
19a03940 2import contextlib
e575b682
PH
3import os
4import subprocess
f8271158 5import sys
6import unittest
7
ff02a228
S
8sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
9
7a5c1cfe 10from yt_dlp.utils import encodeArgument
e575b682
PH
11
12rootDir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
13
a0f59cdc 14
e575b682
PH
15try:
16 _DEV_NULL = subprocess.DEVNULL
17except AttributeError:
18 _DEV_NULL = open(os.devnull, 'wb')
19
a0f59cdc 20
e575b682
PH
21class TestExecution(unittest.TestCase):
22 def test_import(self):
7a5c1cfe 23 subprocess.check_call([sys.executable, '-c', 'import yt_dlp'], cwd=rootDir)
e575b682
PH
24
25 def test_module_exec(self):
19a03940 26 subprocess.check_call([sys.executable, '-m', 'yt_dlp', '--ignore-config', '--version'], cwd=rootDir, stdout=_DEV_NULL)
e575b682
PH
27
28 def test_main_exec(self):
19a03940 29 subprocess.check_call([sys.executable, 'yt_dlp/__main__.py', '--ignore-config', '--version'], cwd=rootDir, stdout=_DEV_NULL)
e575b682 30
f5e2efbb
PH
31 def test_cmdline_umlauts(self):
32 p = subprocess.Popen(
19a03940 33 [sys.executable, 'yt_dlp/__main__.py', '--ignore-config', encodeArgument('ä'), '--version'],
f5e2efbb
PH
34 cwd=rootDir, stdout=_DEV_NULL, stderr=subprocess.PIPE)
35 _, stderr = p.communicate()
36 self.assertFalse(stderr)
37
1bdae7d3 38 def test_lazy_extractors(self):
39 try:
40 subprocess.check_call([sys.executable, 'devscripts/make_lazy_extractors.py', 'yt_dlp/extractor/lazy_extractors.py'], cwd=rootDir, stdout=_DEV_NULL)
41 subprocess.check_call([sys.executable, 'test/test_all_urls.py'], cwd=rootDir, stdout=_DEV_NULL)
42 finally:
19a03940 43 with contextlib.suppress(OSError):
1bdae7d3 44 os.remove('yt_dlp/extractor/lazy_extractors.py')
1bdae7d3 45
582be358 46
e575b682
PH
47if __name__ == '__main__':
48 unittest.main()