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