You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.4 KiB

  1. #!/usr/bin/env python
  2. # coding: utf-8
  3. from __future__ import unicode_literals
  4. # Allow direct execution
  5. import os
  6. import sys
  7. import unittest
  8. sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  9. from youtube_dl.utils import get_filesystem_encoding
  10. from youtube_dl.compat import (
  11. compat_getenv,
  12. compat_expanduser,
  13. )
  14. class TestCompat(unittest.TestCase):
  15. def test_compat_getenv(self):
  16. test_str = 'тест'
  17. os.environ['YOUTUBE-DL-TEST'] = (
  18. test_str if sys.version_info >= (3, 0)
  19. else test_str.encode(get_filesystem_encoding()))
  20. self.assertEqual(compat_getenv('YOUTUBE-DL-TEST'), test_str)
  21. def test_compat_expanduser(self):
  22. old_home = os.environ.get('HOME')
  23. test_str = 'C:\Documents and Settings\тест\Application Data'
  24. os.environ['HOME'] = (
  25. test_str if sys.version_info >= (3, 0)
  26. else test_str.encode(get_filesystem_encoding()))
  27. self.assertEqual(compat_expanduser('~'), test_str)
  28. os.environ['HOME'] = old_home
  29. def test_all_present(self):
  30. import youtube_dl.compat
  31. all_names = youtube_dl.compat.__all__
  32. present_names = set(filter(
  33. lambda c: '_' in c and not c.startswith('_'),
  34. dir(youtube_dl.compat))) - set(['unicode_literals'])
  35. self.assertEqual(all_names, sorted(present_names))
  36. if __name__ == '__main__':
  37. unittest.main()