test_execution.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. rootDir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  9. sys.path.insert(0, rootDir)
  10. from youtube_dl.compat import compat_register_utf8, compat_subprocess_get_DEVNULL
  11. from youtube_dl.utils import encodeArgument
  12. compat_register_utf8()
  13. _DEV_NULL = compat_subprocess_get_DEVNULL()
  14. class TestExecution(unittest.TestCase):
  15. def setUp(self):
  16. self.module = 'youtube_dl'
  17. if sys.version_info < (2, 7):
  18. self.module += '.__main__'
  19. def test_import(self):
  20. subprocess.check_call([sys.executable, '-c', 'import youtube_dl'], cwd=rootDir)
  21. def test_module_exec(self):
  22. subprocess.check_call([sys.executable, '-m', self.module, '--version'], cwd=rootDir, stdout=_DEV_NULL)
  23. def test_main_exec(self):
  24. subprocess.check_call([sys.executable, os.path.normpath('youtube_dl/__main__.py'), '--version'], cwd=rootDir, stdout=_DEV_NULL)
  25. def test_cmdline_umlauts(self):
  26. os.environ['PYTHONIOENCODING'] = 'utf-8'
  27. p = subprocess.Popen(
  28. [sys.executable, '-m', self.module, encodeArgument('ä'), '--version'],
  29. cwd=rootDir, stdout=_DEV_NULL, stderr=subprocess.PIPE)
  30. _, stderr = p.communicate()
  31. self.assertFalse(stderr)
  32. def test_lazy_extractors(self):
  33. lazy_extractors = os.path.normpath('youtube_dl/extractor/lazy_extractors.py')
  34. try:
  35. subprocess.check_call([sys.executable, os.path.normpath('devscripts/make_lazy_extractors.py'), lazy_extractors], cwd=rootDir, stdout=_DEV_NULL)
  36. subprocess.check_call([sys.executable, os.path.normpath('test/test_all_urls.py')], cwd=rootDir, stdout=_DEV_NULL)
  37. finally:
  38. for x in ('', 'c') if sys.version_info[0] < 3 else ('',):
  39. try:
  40. os.remove(lazy_extractors + x)
  41. except OSError:
  42. pass
  43. if __name__ == '__main__':
  44. unittest.main()