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