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