##// END OF EJS Templates
filterpyflakes: move self-test into test file...
Augie Fackler -
r33367:6029939f default
parent child Browse files
Show More
@@ -1,41 +1,37 b''
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2
2
3 # Filter output by pyflakes to control which warnings we check
3 # Filter output by pyflakes to control which warnings we check
4
4
5 from __future__ import absolute_import, print_function
5 from __future__ import absolute_import, print_function
6
6
7 import re
7 import re
8 import sys
8 import sys
9
9
10 lines = []
10 lines = []
11 for line in sys.stdin:
11 for line in sys.stdin:
12 # We blacklist tests that are too noisy for us
12 # We blacklist tests that are too noisy for us
13 pats = [
13 pats = [
14 r"undefined name 'WindowsError'",
14 r"undefined name 'WindowsError'",
15 r"redefinition of unused '[^']+' from line",
15 r"redefinition of unused '[^']+' from line",
16 # for cffi, allow re-exports from pure.*
16 # for cffi, allow re-exports from pure.*
17 r"cffi/[^:]*:.*\bimport \*' used",
17 r"cffi/[^:]*:.*\bimport \*' used",
18 r"cffi/[^:]*:.*\*' imported but unused",
18 r"cffi/[^:]*:.*\*' imported but unused",
19 ]
19 ]
20
20
21 keep = True
21 keep = True
22 for pat in pats:
22 for pat in pats:
23 if re.search(pat, line):
23 if re.search(pat, line):
24 keep = False
24 keep = False
25 break # pattern matches
25 break # pattern matches
26 if keep:
26 if keep:
27 fn = line.split(':', 1)[0]
27 fn = line.split(':', 1)[0]
28 f = open(fn)
28 f = open(fn)
29 data = f.read()
29 data = f.read()
30 f.close()
30 f.close()
31 if 'no-' 'check-code' in data:
31 if 'no-' 'check-code' in data:
32 continue
32 continue
33 lines.append(line)
33 lines.append(line)
34
34
35 for line in lines:
35 for line in lines:
36 sys.stdout.write(line)
36 sys.stdout.write(line)
37 print()
37 print()
38
39 # self test of "undefined name" detection
40 if False:
41 print(undefinedname)
@@ -1,15 +1,21 b''
1 #require test-repo pyflakes hg10
1 #require test-repo pyflakes hg10
2
2
3 $ . "$TESTDIR/helpers-testrepo.sh"
3 $ . "$TESTDIR/helpers-testrepo.sh"
4 $ cd "`dirname "$TESTDIR"`"
4 $ cd "`dirname "$TESTDIR"`"
5
5
6 run pyflakes on all tracked files ending in .py or without a file ending
6 run pyflakes on all tracked files ending in .py or without a file ending
7 (skipping binary file random-seed)
7 (skipping binary file random-seed)
8
8
9 $ cat > test.py <<EOF
10 > print(undefinedname)
11 > EOF
12 $ pyflakes test.py 2>/dev/null | "$TESTDIR/filterpyflakes.py"
13 test.py:1: undefined name 'undefinedname'
14
15
9 $ testrepohg locate 'set:**.py or grep("^#!.*python")' \
16 $ testrepohg locate 'set:**.py or grep("^#!.*python")' \
10 > -X hgext/fsmonitor/pywatchman \
17 > -X hgext/fsmonitor/pywatchman \
11 > -X mercurial/pycompat.py -X contrib/python-zstandard \
18 > -X mercurial/pycompat.py -X contrib/python-zstandard \
12 > 2>/dev/null \
19 > 2>/dev/null \
13 > | xargs pyflakes 2>/dev/null | "$TESTDIR/filterpyflakes.py"
20 > | xargs pyflakes 2>/dev/null | "$TESTDIR/filterpyflakes.py"
14 tests/filterpyflakes.py:41: undefined name 'undefinedname'
15
21
General Comments 0
You need to be logged in to leave comments. Login now