[PATCH] tests: add pyflakes checking for unused imports

timeless timeless at gmail.com
Sun May 1 08:12:31 CDT 2011


# HG changeset patch
# User timeless <timeless at mozdev.org>
# Date 1304254240 -7200
# Node ID 2ad3c270f93065f12cee3ac1cff151d9e15c8b46
# Parent  0386b51dd749f83e3f759a5b799ec364924e3b82
tests: add pyflakes checking for unused imports

diff --git a/hgext/color.py b/hgext/color.py
--- a/hgext/color.py
+++ b/hgext/color.py
@@ -100,7 +100,7 @@ disable color.
 
 '''
 
-import os, sys
+import os
 
 from mercurial import commands, dispatch, extensions, ui as uimod, util
 from mercurial.i18n import _
diff --git a/hgext/convert/darcs.py b/hgext/convert/darcs.py
--- a/hgext/convert/darcs.py
+++ b/hgext/convert/darcs.py
@@ -7,7 +7,7 @@
 
 from common import NoRepo, checktool, commandline, commit, converter_source
 from mercurial.i18n import _
-from mercurial import encoding, util
+from mercurial import util
 import os, shutil, tempfile, re
 
 # The naming drift of ElementTree is fun!
diff --git a/hgext/graphlog.py b/hgext/graphlog.py
--- a/hgext/graphlog.py
+++ b/hgext/graphlog.py
@@ -17,7 +17,7 @@ from mercurial.commands import templateo
 from mercurial.i18n import _
 from mercurial.node import nullrev
 from mercurial import cmdutil, commands, extensions
-from mercurial import hg, scmutil, util, graphmod
+from mercurial import hg, util, graphmod
 
 ASCIIDATA = 'ASC'
 
diff --git a/hgext/progress.py b/hgext/progress.py
--- a/hgext/progress.py
+++ b/hgext/progress.py
@@ -47,7 +47,6 @@ import sys
 import time
 
 from mercurial.i18n import _
-from mercurial import util
 
 def spacejoin(*args):
     return ' '.join(s for s in args if s)
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