[PATCH 2 of 2] tests: ignore "undefined name 'memoryview'" pyflakes error on earlier Python

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Thu May 8 23:47:53 UTC 2014


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1399592693 -32400
#      Fri May 09 08:44:53 2014 +0900
# Node ID e4efded5bd814a0e76af91aaa161aaeb8db29832
# Parent  48f9d5939b8ea2c5ee21facae4efe24a572df65c
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

diff --git a/tests/filterpyflakes.py b/tests/filterpyflakes.py
--- a/tests/filterpyflakes.py
+++ b/tests/filterpyflakes.py
@@ -29,13 +29,16 @@ lines = []
 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 line in sys.stdin:
 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
diff --git a/tests/test-check-pyflakes.t b/tests/test-check-pyflakes.t
--- a/tests/test-check-pyflakes.t
+++ b/tests/test-check-pyflakes.t
@@ -17,5 +17,6 @@ run pyflakes on all tracked files ending
   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



More information about the Mercurial-devel mailing list