]>
Commit | Line | Data |
---|---|---|
8c25f81b PH |
1 | #!/usr/bin/env python |
2 | # coding: utf-8 | |
3 | ||
4 | from __future__ import unicode_literals | |
5 | ||
6 | # Allow direct execution | |
7 | import os | |
8 | import sys | |
9 | import unittest | |
10 | sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
11 | ||
12 | ||
13 | from youtube_dl.utils import get_filesystem_encoding | |
14 | from youtube_dl.compat import ( | |
15 | compat_getenv, | |
16 | compat_expanduser, | |
4a632911 | 17 | compat_urllib_parse_unquote, |
8c25f81b PH |
18 | ) |
19 | ||
20 | ||
21 | class TestCompat(unittest.TestCase): | |
22 | def test_compat_getenv(self): | |
23 | test_str = 'тест' | |
24 | os.environ['YOUTUBE-DL-TEST'] = ( | |
25 | test_str if sys.version_info >= (3, 0) | |
26 | else test_str.encode(get_filesystem_encoding())) | |
27 | self.assertEqual(compat_getenv('YOUTUBE-DL-TEST'), test_str) | |
28 | ||
29 | def test_compat_expanduser(self): | |
f56875f2 | 30 | old_home = os.environ.get('HOME') |
8c25f81b PH |
31 | test_str = 'C:\Documents and Settings\тест\Application Data' |
32 | os.environ['HOME'] = ( | |
33 | test_str if sys.version_info >= (3, 0) | |
34 | else test_str.encode(get_filesystem_encoding())) | |
35 | self.assertEqual(compat_expanduser('~'), test_str) | |
f56875f2 | 36 | os.environ['HOME'] = old_home |
8c25f81b PH |
37 | |
38 | def test_all_present(self): | |
39 | import youtube_dl.compat | |
40 | all_names = youtube_dl.compat.__all__ | |
41 | present_names = set(filter( | |
42 | lambda c: '_' in c and not c.startswith('_'), | |
278143df | 43 | dir(youtube_dl.compat))) - set(['unicode_literals']) |
8c25f81b PH |
44 | self.assertEqual(all_names, sorted(present_names)) |
45 | ||
4a632911 | 46 | def test_compat_urllib_parse_unquote(self): |
14309e1d S |
47 | self.assertEqual(compat_urllib_parse_unquote(''), '') |
48 | self.assertEqual(compat_urllib_parse_unquote('%'), '%') | |
49 | self.assertEqual(compat_urllib_parse_unquote('%%'), '%%') | |
50 | self.assertEqual(compat_urllib_parse_unquote('%%%'), '%%%') | |
51 | self.assertEqual(compat_urllib_parse_unquote('%2F'), '/') | |
52 | self.assertEqual(compat_urllib_parse_unquote('%2f'), '/') | |
53 | self.assertEqual(compat_urllib_parse_unquote('%E6%B4%A5%E6%B3%A2'), '津波') | |
14309e1d S |
54 | self.assertEqual( |
55 | compat_urllib_parse_unquote('''<meta property="og:description" content="%E2%96%81%E2%96%82%E2%96%83%E2%96%84%25%E2%96%85%E2%96%86%E2%96%87%E2%96%88" /> | |
56 | %<a href="https://ar.wikipedia.org/wiki/%D8%AA%D8%B3%D9%88%D9%86%D8%A7%D9%85%D9%8A">%a'''), | |
57 | '''<meta property="og:description" content="▁▂▃▄%▅▆▇█" /> | |
58 | %<a href="https://ar.wikipedia.org/wiki/تسونامي">%a''') | |
59 | self.assertEqual( | |
60 | compat_urllib_parse_unquote('''%28%5E%E2%97%A3_%E2%97%A2%5E%29%E3%81%A3%EF%B8%BB%E3%83%87%E2%95%90%E4%B8%80 %E2%87%80 %E2%87%80 %E2%87%80 %E2%87%80 %E2%87%80 %E2%86%B6%I%Break%25Things%'''), | |
61 | '''(^◣_◢^)っ︻デ═一 ⇀ ⇀ ⇀ ⇀ ⇀ ↶%I%Break%Things%''') | |
4a632911 | 62 | |
8c25f81b PH |
63 | if __name__ == '__main__': |
64 | unittest.main() |