tests: ignore "undefined name 'memoryview'" pyflakes error on earlier Python
authorFUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Fri, 09 May 2014 08:44:53 +0900
changeset 21271 4adc090fa2fb
parent 21270 8fd982139740
child 21272 4aeb7a6029ba
tests: ignore "undefined name 'memoryview'" pyflakes error on earlier Python Before this patch, "test-check-pyflakes.t" shows unexpected "undefined name 'memoryview'" error for "mercurial/util.py" on Python 2.6.x or earlier, because they don't define symbol 'memoryview'. This patch introduces excluding patterns into "filterpyflakes.py" to ignore "undefined name 'memoryview'" pyflakes error on Python 2.6.x or earlier
tests/filterpyflakes.py
tests/test-check-pyflakes.t
--- a/tests/filterpyflakes.py	Fri May 09 08:44:53 2014 +0900
+++ b/tests/filterpyflakes.py	Fri May 09 08:44:53 2014 +0900
@@ -29,13 +29,16 @@
 for line in sys.stdin:
     # We whitelist tests (see more messages in pyflakes.messages)
     pats = [
-            r"imported but unused",
-            r"local variable '.*' is assigned to but never used",
-            r"unable to detect undefined names",
-            r"undefined name '.*'",
+            (r"imported but unused", None),
+            (r"local variable '.*' is assigned to but never used", None),
+            (r"unable to detect undefined names", None),
            ]
-    for msgtype, pat in enumerate(pats):
-        if re.search(pat, line):
+    if sys.version_info >= (2, 7):
+        pats.append((r"undefined name '.*'", None))
+    else:
+        pats.append((r"undefined name '.*'", r"undefined name 'memoryview'"))
+    for msgtype, (pat, excl) in enumerate(pats):
+        if re.search(pat, line) and (not excl or not re.search(excl, line)):
             break # pattern matches
     else:
         continue # no pattern matched, next line
@@ -50,3 +53,7 @@
 for msgtype, line in sorted(lines, key=makekey):
     sys.stdout.write(line)
 print
+
+# self test of "undefined name" detection for other than 'memoryview'
+if False:
+    print undefinedname
--- a/tests/test-check-pyflakes.t	Fri May 09 08:44:53 2014 +0900
+++ b/tests/test-check-pyflakes.t	Fri May 09 08:44:53 2014 +0900
@@ -17,5 +17,6 @@
   tests/hghave.py:*: 'pygments' imported but unused (glob)
   tests/hghave.py:*: 'ssl' imported but unused (glob)
   contrib/win32/hgwebdir_wsgi.py:93: 'from isapi.install import *' used; unable to detect undefined names (glob)
+  tests/filterpyflakes.py:59: undefined name 'undefinedname'
   
 #endif