##// END OF EJS Templates
tests: ignore "undefined name 'memoryview'" pyflakes error on earlier Python...
FUJIWARA Katsunori -
r21271:4adc090f default
parent child Browse files
Show More
@@ -1,52 +1,59 b''
1 1 #!/usr/bin/env python
2 2
3 3 # Filter output by pyflakes to control which warnings we check
4 4
5 5 import sys, re, os
6 6
7 7 def makekey(typeandline):
8 8 """
9 9 for sorting lines by: msgtype, path/to/file, lineno, message
10 10
11 11 typeandline is a sequence of a message type and the entire message line
12 12 the message line format is path/to/file:line: message
13 13
14 14 >>> makekey((3, 'example.py:36: any message'))
15 15 (3, 'example.py', 36, ' any message')
16 16 >>> makekey((7, 'path/to/file.py:68: dummy message'))
17 17 (7, 'path/to/file.py', 68, ' dummy message')
18 18 >>> makekey((2, 'fn:88: m')) > makekey((2, 'fn:9: m'))
19 19 True
20 20 """
21 21
22 22 msgtype, line = typeandline
23 23 fname, line, message = line.split(":", 2)
24 24 # line as int for ordering 9 before 88
25 25 return msgtype, fname, int(line), message
26 26
27 27
28 28 lines = []
29 29 for line in sys.stdin:
30 30 # We whitelist tests (see more messages in pyflakes.messages)
31 31 pats = [
32 r"imported but unused",
33 r"local variable '.*' is assigned to but never used",
34 r"unable to detect undefined names",
35 r"undefined name '.*'",
32 (r"imported but unused", None),
33 (r"local variable '.*' is assigned to but never used", None),
34 (r"unable to detect undefined names", None),
36 35 ]
37 for msgtype, pat in enumerate(pats):
38 if re.search(pat, line):
36 if sys.version_info >= (2, 7):
37 pats.append((r"undefined name '.*'", None))
38 else:
39 pats.append((r"undefined name '.*'", r"undefined name 'memoryview'"))
40 for msgtype, (pat, excl) in enumerate(pats):
41 if re.search(pat, line) and (not excl or not re.search(excl, line)):
39 42 break # pattern matches
40 43 else:
41 44 continue # no pattern matched, next line
42 45 fn = line.split(':', 1)[0]
43 46 f = open(os.path.join(os.path.dirname(os.path.dirname(__file__)), fn))
44 47 data = f.read()
45 48 f.close()
46 49 if 'no-' 'check-code' in data:
47 50 continue
48 51 lines.append((msgtype, line))
49 52
50 53 for msgtype, line in sorted(lines, key=makekey):
51 54 sys.stdout.write(line)
52 55 print
56
57 # self test of "undefined name" detection for other than 'memoryview'
58 if False:
59 print undefinedname
@@ -1,21 +1,22 b''
1 1 #if test-repo pyflakes
2 2
3 3 $ cd "`dirname "$TESTDIR"`"
4 4
5 5 run pyflakes on all tracked files ending in .py or without a file ending
6 6 (skipping binary file random-seed)
7 7
8 8 $ hg locate 'set:**.py or grep("^!#.*python")' 2>/dev/null \
9 9 > | xargs pyflakes 2>/dev/null | "$TESTDIR/filterpyflakes.py"
10 10 contrib/win32/hgwebdir_wsgi.py:*: 'win32traceutil' imported but unused (glob)
11 11 setup.py:*: 'sha' imported but unused (glob)
12 12 setup.py:*: 'zlib' imported but unused (glob)
13 13 setup.py:*: 'bz2' imported but unused (glob)
14 14 setup.py:*: 'py2exe' imported but unused (glob)
15 15 tests/hghave.py:*: '_lsprof' imported but unused (glob)
16 16 tests/hghave.py:*: 'publish_cmdline' imported but unused (glob)
17 17 tests/hghave.py:*: 'pygments' imported but unused (glob)
18 18 tests/hghave.py:*: 'ssl' imported but unused (glob)
19 19 contrib/win32/hgwebdir_wsgi.py:93: 'from isapi.install import *' used; unable to detect undefined names (glob)
20 tests/filterpyflakes.py:59: undefined name 'undefinedname'
20 21
21 22 #endif
General Comments 0
You need to be logged in to leave comments. Login now