test_execution.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 hypervideo_dl.utils import Popen
  10. rootDir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  11. LAZY_EXTRACTORS = 'hypervideo_dl/extractor/lazy_extractors.py'
  12. class TestExecution(unittest.TestCase):
  13. def run_hypervideo_dl(self, exe=(sys.executable, 'hypervideo_dl/__main__.py'), opts=('--version', )):
  14. stdout, stderr, returncode = Popen.run(
  15. [*exe, '--ignore-config', *opts], cwd=rootDir, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  16. print(stderr, file=sys.stderr)
  17. self.assertEqual(returncode, 0)
  18. return stdout.strip(), stderr.strip()
  19. def test_main_exec(self):
  20. self.run_hypervideo_dl()
  21. def test_import(self):
  22. self.run_hypervideo_dl(exe=(sys.executable, '-c', 'import hypervideo_dl'))
  23. def test_module_exec(self):
  24. self.run_hypervideo_dl(exe=(sys.executable, '-m', 'hypervideo_dl'))
  25. def test_cmdline_umlauts(self):
  26. _, stderr = self.run_hypervideo_dl(opts=('ä', '--version'))
  27. self.assertFalse(stderr)
  28. def test_lazy_extractors(self):
  29. try:
  30. subprocess.check_call([sys.executable, 'devscripts/make_lazy_extractors.py', LAZY_EXTRACTORS],
  31. cwd=rootDir, stdout=subprocess.DEVNULL)
  32. self.assertTrue(os.path.exists(LAZY_EXTRACTORS))
  33. _, stderr = self.run_hypervideo_dl(opts=('-s', 'test:'))
  34. self.assertFalse(stderr)
  35. subprocess.check_call([sys.executable, 'test/test_all_urls.py'], cwd=rootDir, stdout=subprocess.DEVNULL)
  36. finally:
  37. with contextlib.suppress(OSError):
  38. os.remove(LAZY_EXTRACTORS)
  39. if __name__ == '__main__':
  40. unittest.main()