Prepare widespread unicode literal use
[youtube-dl] / test / test_unicode_literals.py
1 from __future__ import unicode_literals
2
3 import io
4 import os
5 import re
6 import unittest
7
8 rootDir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
9
10
11 class TestUnicodeLiterals(unittest.TestCase):
12     def test_all_files(self):
13         print('Skipping this test (not yet fully implemtned)')
14         return
15
16         for dirpath, _, filenames in os.walk(rootDir):
17             for basename in filenames:
18                 if not basename.endswith('.py'):
19                     continue
20                 fn = os.path.join(dirpath, basename)
21                 with io.open(fn, encoding='utf-8') as inf:
22                     code = inf.read()
23
24                 if "'" not in code and '"' not in code:
25                     continue
26                 imps = 'from __future__ import unicode_literals'
27                 self.assertTrue(
28                     imps in code,
29                     ' %s  missing in %s' % (imps, fn))
30
31                 m = re.search(r'(?<=\s)u[\'"](?!\)|,|$)', code)
32                 if m is not None:
33                     self.assertTrue(
34                         m is None,
35                         'u present in %s, around %s' % (
36                             fn, code[m.start() - 10:m.end() + 10]))
37
38
39 if __name__ == '__main__':
40     unittest.main()