]>
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', | |
cdb7547e U |
18 | 'pyinst.py', |
19 | 'pyinst32.py', | |
01c62591 PH |
20 | ] |
21 | ||
4d165248 JMF |
22 | IGNORED_DIRS = [ |
23 | '.git', | |
24 | '.tox', | |
25 | ] | |
6febd1c1 | 26 | |
da4d4191 | 27 | from test.helper import assertRegexpMatches |
8bdcb436 PH |
28 | |
29 | ||
6febd1c1 PH |
30 | class TestUnicodeLiterals(unittest.TestCase): |
31 | def test_all_files(self): | |
4d165248 JMF |
32 | for dirpath, dirnames, filenames in os.walk(rootDir): |
33 | for ignore_dir in IGNORED_DIRS: | |
34 | if ignore_dir in dirnames: | |
35 | # If we remove the directory from dirnames os.walk won't | |
36 | # recurse into it | |
37 | dirnames.remove(ignore_dir) | |
6febd1c1 PH |
38 | for basename in filenames: |
39 | if not basename.endswith('.py'): | |
40 | continue | |
01c62591 PH |
41 | if basename in IGNORED_FILES: |
42 | continue | |
43 | ||
6febd1c1 PH |
44 | fn = os.path.join(dirpath, basename) |
45 | with io.open(fn, encoding='utf-8') as inf: | |
46 | code = inf.read() | |
47 | ||
48 | if "'" not in code and '"' not in code: | |
49 | continue | |
8bdcb436 PH |
50 | assertRegexpMatches( |
51 | self, | |
dcddc10a | 52 | code, |
8bdcb436 | 53 | r'(?:(?:#.*?|\s*)\n)*from __future__ import (?:[a-z_]+,\s*)*unicode_literals', |
dcddc10a | 54 | 'unicode_literals import missing in %s' % fn) |
6febd1c1 PH |
55 | |
56 | m = re.search(r'(?<=\s)u[\'"](?!\)|,|$)', code) | |
57 | if m is not None: | |
58 | self.assertTrue( | |
59 | m is None, | |
60 | 'u present in %s, around %s' % ( | |
61 | fn, code[m.start() - 10:m.end() + 10])) | |
62 | ||
63 | ||
64 | if __name__ == '__main__': | |
65 | unittest.main() |