test_execution.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/env python
  2. # coding: utf-8
  3. from __future__ import unicode_literals
  4. import unittest
  5. import sys
  6. import os
  7. import subprocess
  8. sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  9. from youtube_dl.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 youtube_dl'], cwd=rootDir)
  18. def test_module_exec(self):
  19. if sys.version_info >= (2, 7): # Python 2.6 doesn't support package execution
  20. subprocess.check_call([sys.executable, '-m', 'youtube_dl', '--version'], cwd=rootDir, stdout=_DEV_NULL)
  21. def test_main_exec(self):
  22. subprocess.check_call([sys.executable, 'youtube_dl/__main__.py', '--version'], cwd=rootDir, stdout=_DEV_NULL)
  23. def test_cmdline_umlauts(self):
  24. p = subprocess.Popen(
  25. [sys.executable, 'youtube_dl/__main__.py', encodeArgument('ä'), '--version'],
  26. cwd=rootDir, stdout=_DEV_NULL, stderr=subprocess.PIPE)
  27. _, stderr = p.communicate()
  28. self.assertFalse(stderr)
  29. def test_lazy_extractors(self):
  30. try:
  31. subprocess.check_call([sys.executable, 'devscripts/make_lazy_extractors.py', 'youtube_dl/extractor/lazy_extractors.py'], cwd=rootDir, stdout=_DEV_NULL)
  32. subprocess.check_call([sys.executable, 'test/test_all_urls.py'], cwd=rootDir, stdout=_DEV_NULL)
  33. finally:
  34. try:
  35. os.remove('youtube_dl/extractor/lazy_extractors.py')
  36. except (IOError, OSError):
  37. pass
  38. if __name__ == '__main__':
  39. unittest.main()