3 # Allow direct execution
8 sys
.path
.insert(0, os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))))
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
):
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
):
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'):
51 self
.assertFalse(stderr
)
53 subprocess
.check_call([sys
.executable
, 'test/test_all_urls.py'], cwd
=rootDir
, stdout
=subprocess
.DEVNULL
)
55 with contextlib
.suppress(OSError):
56 os
.remove(LAZY_EXTRACTORS
)
59 if __name__
== '__main__':