test_execution.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/env python3
  2. # Allow direct execution
  3. import os
  4. import sys
  5. import unittest
  6. sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  7. import contextlib
  8. import subprocess
  9. from yt_dlp.utils import encodeArgument
  10. rootDir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  11. try:
  12. _DEV_NULL = subprocess.DEVNULL
  13. except AttributeError:
  14. _DEV_NULL = open(os.devnull, 'wb')
  15. class TestExecution(unittest.TestCase):
  16. def test_import(self):
  17. subprocess.check_call([sys.executable, '-c', 'import yt_dlp'], cwd=rootDir)
  18. def test_module_exec(self):
  19. subprocess.check_call([sys.executable, '-m', 'yt_dlp', '--ignore-config', '--version'], cwd=rootDir, stdout=_DEV_NULL)
  20. def test_main_exec(self):
  21. subprocess.check_call([sys.executable, 'yt_dlp/__main__.py', '--ignore-config', '--version'], cwd=rootDir, stdout=_DEV_NULL)
  22. def test_cmdline_umlauts(self):
  23. p = subprocess.Popen(
  24. [sys.executable, 'yt_dlp/__main__.py', '--ignore-config', encodeArgument('ä'), '--version'],
  25. cwd=rootDir, stdout=_DEV_NULL, stderr=subprocess.PIPE)
  26. _, stderr = p.communicate()
  27. self.assertFalse(stderr)
  28. def test_lazy_extractors(self):
  29. try:
  30. subprocess.check_call([sys.executable, 'devscripts/make_lazy_extractors.py', 'yt_dlp/extractor/lazy_extractors.py'], cwd=rootDir, stdout=_DEV_NULL)
  31. subprocess.check_call([sys.executable, 'test/test_all_urls.py'], cwd=rootDir, stdout=_DEV_NULL)
  32. finally:
  33. with contextlib.suppress(OSError):
  34. os.remove('yt_dlp/extractor/lazy_extractors.py')
  35. if __name__ == '__main__':
  36. unittest.main()