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.

44 lines
1.3 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. test_str = 'C:\Documents and Settings\тест\Application Data'
  23. os.environ['HOME'] = (
  24. test_str if sys.version_info >= (3, 0)
  25. else test_str.encode(get_filesystem_encoding()))
  26. self.assertEqual(compat_expanduser('~'), test_str)
  27. def test_all_present(self):
  28. import youtube_dl.compat
  29. all_names = youtube_dl.compat.__all__
  30. present_names = set(filter(
  31. lambda c: '_' in c and not c.startswith('_'),
  32. dir(youtube_dl.compat)))
  33. self.assertEqual(all_names, sorted(present_names))
  34. if __name__ == '__main__':
  35. unittest.main()