]>
Commit | Line | Data |
---|---|---|
6febd1c1 PH |
1 | from __future__ import unicode_literals |
2 | ||
8bdcb436 PH |
3 | # Allow direct execution |
4 | import os | |
5 | import sys | |
6 | import unittest | |
7 | sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
8 | ||
6febd1c1 | 9 | import io |
6febd1c1 | 10 | import re |
6febd1c1 PH |
11 | |
12 | rootDir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
13 | ||
01c62591 PH |
14 | IGNORED_FILES = [ |
15 | 'setup.py', # http://bugs.python.org/issue13943 | |
dcddc10a PH |
16 | 'conf.py', |
17 | 'buildserver.py', | |
01c62591 PH |
18 | ] |
19 | ||
6febd1c1 | 20 | |
da4d4191 | 21 | from test.helper import assertRegexpMatches |
8bdcb436 PH |
22 | |
23 | ||
6febd1c1 PH |
24 | class TestUnicodeLiterals(unittest.TestCase): |
25 | def test_all_files(self): | |
6febd1c1 PH |
26 | for dirpath, _, filenames in os.walk(rootDir): |
27 | for basename in filenames: | |
28 | if not basename.endswith('.py'): | |
29 | continue | |
01c62591 PH |
30 | if basename in IGNORED_FILES: |
31 | continue | |
32 | ||
6febd1c1 PH |
33 | fn = os.path.join(dirpath, basename) |
34 | with io.open(fn, encoding='utf-8') as inf: | |
35 | code = inf.read() | |
36 | ||
37 | if "'" not in code and '"' not in code: | |
38 | continue | |
8bdcb436 PH |
39 | assertRegexpMatches( |
40 | self, | |
dcddc10a | 41 | code, |
8bdcb436 | 42 | r'(?:(?:#.*?|\s*)\n)*from __future__ import (?:[a-z_]+,\s*)*unicode_literals', |
dcddc10a | 43 | 'unicode_literals import missing in %s' % fn) |
6febd1c1 PH |
44 | |
45 | m = re.search(r'(?<=\s)u[\'"](?!\)|,|$)', code) | |
46 | if m is not None: | |
47 | self.assertTrue( | |
48 | m is None, | |
49 | 'u present in %s, around %s' % ( | |
50 | fn, code[m.start() - 10:m.end() + 10])) | |
51 | ||
52 | ||
53 | if __name__ == '__main__': | |
54 | unittest.main() |