]> Raphaƫl G. Git Repositories - youtubedl/blob - test/test_unicode_literals.py
Annotate changelog with bugs closed.
[youtubedl] / 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 IGNORED_FILES = [
11 'setup.py', # http://bugs.python.org/issue13943
12 ]
13
14
15 class TestUnicodeLiterals(unittest.TestCase):
16 def test_all_files(self):
17 print('Skipping this test (not yet fully implemented)')
18 return
19
20 for dirpath, _, filenames in os.walk(rootDir):
21 for basename in filenames:
22 if not basename.endswith('.py'):
23 continue
24 if basename in IGNORED_FILES:
25 continue
26
27 fn = os.path.join(dirpath, basename)
28 with io.open(fn, encoding='utf-8') as inf:
29 code = inf.read()
30
31 if "'" not in code and '"' not in code:
32 continue
33 imps = 'from __future__ import unicode_literals'
34 self.assertTrue(
35 imps in code,
36 ' %s missing in %s' % (imps, fn))
37
38 m = re.search(r'(?<=\s)u[\'"](?!\)|,|$)', code)
39 if m is not None:
40 self.assertTrue(
41 m is None,
42 'u present in %s, around %s' % (
43 fn, code[m.start() - 10:m.end() + 10]))
44
45
46 if __name__ == '__main__':
47 unittest.main()