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