[PATCH 2 of 2] tests: add pyflakes checking for unused imports

timeless timeless at gmail.com
Sun May 1 08:26:52 CDT 2011


# HG changeset patch
# User timeless <timeless at mozdev.org>
# Date 1304256150 -7200
# Node ID bb7ce463faddaabbb1e5e7af3d4da5e8bc263ea9
# Parent  a33e77032fcdedd4dadc0c2aa8bbbe47be711e61
tests: add pyflakes checking for unused imports

diff --git a/tests/filterpyflakes.py b/tests/filterpyflakes.py
new file mode 100755
--- /dev/null
+++ b/tests/filterpyflakes.py
@@ -0,0 +1,12 @@
+#!/usr/bin/env python
+
+# Filter output by pyflakes to control which warnings we check
+
+import sys, re
+
+for line in sys.stdin:
+    # We whitelist tests
+    if not re.search("imported but unused", line):
+        continue
+    sys.stdout.write(line)
+print
diff --git a/tests/hghave b/tests/hghave
--- a/tests/hghave
+++ b/tests/hghave
@@ -172,6 +172,11 @@ def has_unix_permissions():
     finally:
         os.rmdir(d)
 
+def has_pyflakes():
+    return matchoutput('echo "import re" 2>&1 | pyflakes',
+                       r"<stdin>:1: 're' imported but unused",
+                       True)
+
 def has_pygments():
     try:
         import pygments
@@ -210,6 +215,7 @@ checks = {
     "mtn": (has_mtn, "monotone client (> 0.31)"),
     "outer-repo": (has_outer_repo, "outer repo"),
     "p4": (has_p4, "Perforce server and client"),
+    "pyflakes": (has_pyflakes, "Pyflakes python linter"),
     "pygments": (has_pygments, "Pygments source highlighting library"),
     "ssl": (has_ssl, "python >= 2.6 ssl module and python OpenSSL"),
     "svn": (has_svn, "subversion client and admin tools"),
diff --git a/tests/test-check-pyflakes.t b/tests/test-check-pyflakes.t
new file mode 100644
--- /dev/null
+++ b/tests/test-check-pyflakes.t
@@ -0,0 +1,11 @@
+  $ "$TESTDIR/hghave" pyflakes || exit 80
+  $ cd $(dirname $TESTDIR)
+  $ pyflakes mercurial hgext 2>&1 | sort | $TESTDIR/filterpyflakes.py
+  mercurial/commands.py:*: 'base85' imported but unused (glob)
+  mercurial/commands.py:*: 'bdiff' imported but unused (glob)
+  mercurial/commands.py:*: 'mpatch' imported but unused (glob)
+  mercurial/commands.py:*: 'osutil' imported but unused (glob)
+  mercurial/hgweb/server.py:*: 'activeCount' imported but unused (glob)
+  mercurial/revlog.py:*: 'short' imported but unused (glob)
+  
+


More information about the Mercurial-devel mailing list