[PATCH 1 of 6] test-pyflake: improve sorting algorithm

timeless timeless at gmail.com
Sun May 1 14:16:33 CDT 2011


# HG changeset patch
# User timeless <timeless at mozdev.org>
# Date 1304268987 -7200
# Node ID fd848660e6e7530efaada4860638b99b9467240a
# Parent  0bbf8e52bf9e2731d198103e6961621949536242
test-pyflake: improve sorting algorithm

diff --git a/tests/filterpyflakes.py b/tests/filterpyflakes.py
--- a/tests/filterpyflakes.py
+++ b/tests/filterpyflakes.py
@@ -4,9 +4,24 @@
 
 import sys, re
 
+def makekey(message):
+    # "path/file:line: message"
+    match = re.search(r"(line \d+)", message)
+    line = ''
+    if match:
+        line = match.group(0)
+        message = re.sub(r"(line \d+)", '', message)
+    return re.sub(r"([^:]*):([^:]+):([^']*)('[^']*')(.*)$",
+                  r'\3:\5:\4:\1:\2:' + line,
+                  message)
+
+lines = []
 for line in sys.stdin:
     # We whitelist tests
     if not re.search("imported but unused", line):
         continue
+    lines.append(line)
+
+for line in sorted(lines, key = makekey):
     sys.stdout.write(line)
 print
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
@@ -1,11 +1,11 @@
   $ "$TESTDIR/hghave" pyflakes || exit 80
   $ cd $(dirname $TESTDIR)
-  $ pyflakes mercurial hgext 2>&1 | sort | $TESTDIR/filterpyflakes.py
+  $ pyflakes mercurial hgext 2>&1 | $TESTDIR/filterpyflakes.py
+  mercurial/hgweb/server.py:*: 'activeCount' imported but unused (glob)
   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