Browse Source

Add a Nosetests plugin that lets me specify a test order within a directory.

tags/nilmdb-0.1
Jim Paris 11 years ago
parent
commit
b7688844fa
3 changed files with 66 additions and 2 deletions
  1. +2
    -2
      Makefile
  2. +46
    -0
      runtests.py
  3. +18
    -0
      tests/test.order

+ 2
- 2
Makefile View File

@@ -9,10 +9,10 @@ lint:
pylint -f parseable nilmdb

test:
nosetests
python runtests.py

profile:
nosetests --with-profile
python runtests.py --with-profile

clean::
find . -name '*pyc' | xargs rm -f


+ 46
- 0
runtests.py View File

@@ -0,0 +1,46 @@
#!/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):
line = line.strip()
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"])

+ 18
- 0
tests/test.order View File

@@ -0,0 +1,18 @@
test_printf.py
test_lrucache.py
test_mustclose.py

test_serializer.py
test_iteratorizer.py

test_timestamper.py
test_layout.py
test_rbtree.py
test_interval.py

test_bulkdata.py
test_nilmdb.py
test_client.py
test_cmdline.py

test_*.py

Loading…
Cancel
Save