[ci skip] Fix typos
[scons.git] / src / test_pychecker.py
blobfdc8d2018e66f562fd9d98143488a307703570cb
1 #!/usr/bin/env python
3 # __COPYRIGHT__
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
25 """
26 Use pychecker to catch various Python coding errors.
27 """
29 import os
30 import os.path
31 import sys
33 import TestSCons
35 test = TestSCons.TestSCons()
37 test.skip_test('Not ready for clean pychecker output; skipping test.\n')
39 try:
40 import pychecker
41 except ImportError:
42 pychecker = test.where_is('pychecker')
43 if not pychecker:
44 test.skip_test("Could not find 'pychecker'; skipping test(s).\n")
45 program = pychecker
46 default_arguments = []
47 else:
48 pychecker = os.path.join(os.path.split(pychecker.__file__)[0], 'checker.py')
49 program = sys.executable
50 default_arguments = [pychecker]
52 try:
53 cwd = os.environ['SCONS_CWD']
54 except KeyError:
55 src_engine = os.environ['SCONS_LIB_DIR']
56 else:
57 src_engine = os.path.join(cwd, 'build', 'scons-src', 'src', 'engine')
58 if not os.path.exists(src_engine):
59 src_engine = os.path.join(cwd, 'src', 'engine')
61 src_engine_ = os.path.join(src_engine, '')
63 MANIFEST = os.path.join(src_engine, 'MANIFEST.in')
64 with open(MANIFEST) as f:
65 files = f.read().split()
67 files = [f for f in files if f[-3:] == '.py']
69 ignore = [
70 'SCons/compat/__init__.py',
71 'SCons/compat/_scons_UserString.py',
72 'SCons/compat/_scons_hashlib.py',
73 'SCons/compat/_scons_sets.py',
74 'SCons/compat/_scons_subprocess.py',
75 'SCons/compat/builtins.py',
78 u = {}
79 for file in files:
80 u[file] = 1
81 for file in ignore:
82 try:
83 del u[file]
84 except KeyError:
85 pass
86 files = sorted(u.keys())
88 mismatches = []
90 default_arguments.extend([
91 '--quiet',
92 '--limit=1000',
93 # Suppress warnings about unused arguments to functions and methods.
94 # We have too many wrapper functions that intentionally only use some
95 # of their arguments.
96 '--no-argsused',
99 if sys.platform == 'win32':
100 default_arguments.extend([
101 '--blacklist', '"pywintypes,pywintypes.error"',
104 per_file_arguments = {
105 #'SCons/__init__.py' : [
106 # '--varlist',
107 # '"__revision__,__version__,__build__,__buildsys__,__date__,__developer__"',
111 pywintypes_warning = "warning: couldn't find real module for class pywintypes.error (module name: pywintypes)\n"
113 os.environ['PYTHONPATH'] = src_engine
115 for file in files:
117 args = (default_arguments +
118 per_file_arguments.get(file, []) +
119 [os.path.join(src_engine, file)])
121 test.run(program=program, arguments=args, status=None, stderr=None)
123 stdout = test.stdout()
124 stdout = stdout.replace(src_engine_, '')
126 stderr = test.stderr()
127 stderr = stderr.replace(src_engine_, '')
128 stderr = stderr.replace(pywintypes_warning, '')
130 if test.status or stdout or stderr:
131 mismatches.append('\n')
132 mismatches.append(' '.join([program] + args) + '\n')
134 mismatches.append('STDOUT =====================================\n')
135 mismatches.append(stdout)
137 if stderr:
138 mismatches.append('STDERR =====================================\n')
139 mismatches.append(stderr)
141 if mismatches:
142 print(''.join(mismatches[1:]))
143 test.fail_test()
145 test.pass_test()
147 # Local Variables:
148 # tab-width:4
149 # indent-tabs-mode:nil
150 # End:
151 # vim: set expandtab tabstop=4 shiftwidth=4: