summaryrefslogtreecommitdiff
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
parent10a1ef8fe6b190a7c5f863f40197ac96725d3f3f (diff)
downloadnose-e2a4c72927ccb1c13f76ba71ca90423e557a9830.tar.gz
Restored lib-first sorting to loadTestFromDir -- needs tests.
-rw-r--r--TODO11
-rw-r--r--nose/loader.py4
-rw-r--r--nose/util.py21
-rw-r--r--unit_tests/test_loader.py6
4 files changed, 34 insertions, 8 deletions
diff --git a/TODO b/TODO
index 4450e01..f45101a 100644
--- a/TODO
+++ b/TODO
@@ -9,6 +9,8 @@ DOCUMENTATION
sanity check all docstrings
generate new plugin api docs, highlighting new and changed methods
+ generate new docs for all wiki'd docs, flat html, interlinked, for 0.10 doc dir
+ generate pydoctor(?) or pudge(?) api docs for 0.10 doc dir
FEATURES
@@ -16,7 +18,8 @@ add --plugins option displays loadable plugins, with version (if
applicable), score, description for each. options for each also if
verbosity >= 2
-** make sure lib-first collection is still working (dir contents sorted test-last)
+** make sure lib-first collection is still working (dir contents sorted test-last)-- needs a functional test, too difficult to introspect in unit test
+
rename Failure and split into subclasses for Import and other, and make
it optionally include the name of the file being considered so that
@@ -28,7 +31,7 @@ FAILED (todo=10)
or
OK (skipped=2)
-** this can only be done in nose test runner
+NOTE this can only be done in nose test runner
* loader
- support module.callable in addition to module:callable names
@@ -66,9 +69,7 @@ TESTS NEEDED
testid
-- needs tests with doctests
** -- doctests from non module files
- ** doctest
- ** -- needs tests from non-module files
-
+
coverage/doctest -- need tests for coverage/doctest interaction
diff --git a/nose/loader.py b/nose/loader.py
index 66962e0..050a251 100644
--- a/nose/loader.py
+++ b/nose/loader.py
@@ -10,7 +10,7 @@ from nose.config import Config
from nose.importer import Importer, add_path, remove_path
from nose.selector import defaultSelector, TestAddress
from nose.util import cmp_lineno, getpackage, isclass, isgenerator, ispackage, \
- resolve_name
+ match_last, resolve_name
from suite import ContextSuiteFactory, ContextList, LazySuite
log = logging.getLogger(__name__)
@@ -75,7 +75,7 @@ class TestLoader(unittest.TestLoader):
paths_added = add_path(path)
entries = os.listdir(path)
- entries.sort()
+ entries.sort(lambda a, b: match_last(a, b, self.config.testMatch))
for entry in entries:
if entry.startswith('.') or entry.startswith('_'):
continue
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)
diff --git a/unit_tests/test_loader.py b/unit_tests/test_loader.py
index de690ad..2d951e9 100644
--- a/unit_tests/test_loader.py
+++ b/unit_tests/test_loader.py
@@ -128,12 +128,16 @@ def mock_listdir(path):
return ['.', '..', 'subpackage', '__init__.py']
elif path.endswith('/subpackage'):
return ['.', '..', '__init__.py']
+ elif path.endswith('/sort'):
+ return ['.', '..', 'lib', 'src', 'test', 'test_module.py', 'a_test']
return ['.', '..', 'test_module.py', 'module.py']
def mock_isdir(path):
print "is dir '%s'?" % path
- if path in ('/a/dir/path', '/package', '/package/subpackage'):
+ if path in ('/a/dir/path', '/package', '/package/subpackage',
+ '/sort/lib', '/sort/src', '/sort/a_test', '/sort/test',
+ '/sort'):
return True
return False