2013-01-05 18:00:59 -05:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
import nose
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import glob
|
|
|
|
from collections import OrderedDict
|
|
|
|
|
|
|
|
class JimOrderPlugin(nose.plugins.Plugin):
|
|
|
|
"""When searching for tests and encountering a directory that
|
|
|
|
contains a 'test.order' file, run tests listed in that file, in the
|
|
|
|
order that they're listed. Globs are OK in that file and duplicates
|
|
|
|
are removed."""
|
|
|
|
name = 'jimorder'
|
|
|
|
score = 10000
|
|
|
|
|
|
|
|
def prepareTestLoader(self, loader):
|
|
|
|
def wrap(func):
|
|
|
|
def wrapper(name, *args, **kwargs):
|
|
|
|
addr = nose.selector.TestAddress(
|
|
|
|
name, workingDir=loader.workingDir)
|
|
|
|
try:
|
|
|
|
order = os.path.join(addr.filename, "test.order")
|
|
|
|
except:
|
|
|
|
order = None
|
|
|
|
if order and os.path.exists(order):
|
|
|
|
files = []
|
|
|
|
for line in open(order):
|
2013-01-06 19:25:07 -05:00
|
|
|
line = line.split('#')[0].strip()
|
2013-01-05 18:00:59 -05:00
|
|
|
if not line:
|
|
|
|
continue
|
|
|
|
fn = os.path.join(addr.filename, line.strip())
|
|
|
|
files.extend(sorted(glob.glob(fn)) or [fn])
|
|
|
|
files = list(OrderedDict.fromkeys(files))
|
|
|
|
tests = [ wrapper(fn, *args, **kwargs) for fn in files ]
|
|
|
|
return loader.suiteClass(tests)
|
|
|
|
return func(name, *args, **kwargs)
|
|
|
|
return wrapper
|
|
|
|
loader.loadTestsFromName = wrap(loader.loadTestsFromName)
|
|
|
|
return loader
|
|
|
|
|
|
|
|
# Use setup.cfg for most of the test configuration. Adding
|
|
|
|
# --with-jimorder here means that a normal "nosetests" run will
|
|
|
|
# still work, it just won't support test.order.
|
|
|
|
nose.main(addplugins = [ JimOrderPlugin() ],
|
|
|
|
argv = sys.argv + ["--with-jimorder"])
|