summaryrefslogtreecommitdiff
path: root/nose/util.py
diff options
context:
space:
mode:
authorJason Pellerin <jpellerin@gmail.com>2007-04-27 21:10:06 +0000
committerJason Pellerin <jpellerin@gmail.com>2007-04-27 21:10:06 +0000
commite2a4c72927ccb1c13f76ba71ca90423e557a9830 (patch)
treee656921b4745b691375cfc5d3dbdc88fb3ecc55e /nose/util.py
parent10a1ef8fe6b190a7c5f863f40197ac96725d3f3f (diff)
downloadnose-e2a4c72927ccb1c13f76ba71ca90423e557a9830.tar.gz
Restored lib-first sorting to loadTestFromDir -- needs tests.
Diffstat (limited to 'nose/util.py')
-rw-r--r--nose/util.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/nose/util.py b/nose/util.py
index adefb99..e601ebd 100644
--- a/nose/util.py
+++ b/nose/util.py
@@ -209,6 +209,7 @@ def getpackage(filename):
mod_parts.reverse()
return '.'.join(mod_parts)
+
def ln(label):
"""Draw a 70-char-wide divider, with label in the middle.
@@ -223,6 +224,7 @@ def ln(label):
out = out + ('-' * pad)
return out
+
def resolve_name(name, module=None):
"""Resolve a dotted name to a module and its parts. This is stolen
wholesale from unittest.TestLoader.loadTestByName.
@@ -382,6 +384,25 @@ def src(filename):
return '.'.join((base, 'py'))
return filename
+
+def match_last(a, b, regex):
+ """Sort compare function that puts items that match a
+ regular expression last.
+
+ >>> from nose.config import Config
+ >>> c = Config()
+ >>> regex = c.testMatch
+ >>> entries = ['.', '..', 'a_test', 'src', 'lib', 'test', 'foo.py']
+ >>> entries.sort(lambda a, b: match_last(a, b, regex))
+ >>> entries
+ ['.', '..', 'foo.py', 'lib', 'src', 'a_test', 'test']
+ """
+ if regex.search(a) and not regex.search(b):
+ return 1
+ elif regex.search(b) and not regex.search(a):
+ return -1
+ return cmp(a, b)
+
def tolist(val):
"""Convert a value that may be a list or a (possibly comma-separated)