Commit 7c21b958 authored by Carlos Garcia Campos's avatar Carlos Garcia Campos Committed by Carlos Garcia Campos

regtest: Allow to run groups of tests individually

Now it's possible to pass more than one argument to run-tests command and
optionally the docs directory. When more than one test is passed and the
docs directory is not provided, the common base path of all passed tests
is used as docs directory. The tests passed can be documents or
directories, using absolute paths or paths relative to the docs
directory.
This also allows us to update the refs for a group of tests.
parent 53be607e
......@@ -172,8 +172,30 @@ class TestRun:
self.run_test(doc)
self._queue.task_done()
def run_tests(self):
docs, total_docs = get_document_paths_from_dir(self._docsdir)
def run_tests(self, tests = []):
if not tests:
docs, total_docs = get_document_paths_from_dir(self._docsdir)
else:
docs = []
total_docs = 0
for test in tests:
if os.path.isdir(test):
test_dir = test
elif os.path.isdir(os.path.join(self._docsdir, test)):
test_dir = os.path.join(self._docsdir, test)
else:
test_dir = None
if test_dir is not None:
dir_docs, dir_n_docs = get_document_paths_from_dir(test_dir, self._docsdir)
docs.extend(dir_docs)
total_docs += dir_n_docs
else:
if test.startswith(self._docsdir):
test = test[len(self._docsdir):].lstrip(os.path.sep)
docs.append(test)
total_docs += 1
backends = self._get_backends()
self._total_tests = total_docs * len(backends)
......
......@@ -18,7 +18,10 @@
import os
def get_document_paths_from_dir(docsdir):
def get_document_paths_from_dir(docsdir, basedir = None):
if basedir is None:
basedir = docsdir
paths = []
n_paths = 0
for root, dirs, files in os.walk(docsdir, False):
......@@ -26,7 +29,7 @@ def get_document_paths_from_dir(docsdir):
if not entry.lower().endswith('.pdf'):
continue
test_path = os.path.join(root[len(docsdir):], entry)
test_path = os.path.join(root[len(basedir):], entry)
paths.append(test_path.lstrip(os.path.sep))
n_paths += 1
paths.sort()
......
......@@ -39,6 +39,9 @@ class RunTests(Command):
parser.add_argument('-o', '--out-dir',
action = 'store', dest = 'out_dir', default = os.path.join(tempfile.gettempdir(), 'out'),
help = 'Directory where test results will be created')
parser.add_argument('--docs-dir',
action = 'store', dest = 'docs_dir',
help = 'Base documents directory')
parser.add_argument('--keep-results',
action = 'store_true', dest = 'keep_results', default = False,
help = 'Do not remove result files for passing tests')
......@@ -48,7 +51,8 @@ class RunTests(Command):
parser.add_argument('--update-refs',
action = 'store_true', dest = 'update_refs', default = False,
help = 'Update references for failed tests')
parser.add_argument('tests')
parser.add_argument('tests', metavar = 'TEST', nargs = '+',
help = 'Tests directory or individual test to run')
def run(self, options):
config = Config()
......@@ -57,17 +61,24 @@ class RunTests(Command):
config.update_refs = options['update_refs']
t = Timer()
doc = options['tests']
if os.path.isdir(doc):
docs_dir = doc
docs = options['tests']
docs_dir = options['docs_dir']
if len(docs) == 1:
if os.path.isdir(docs[0]):
if docs_dir is None:
docs_dir = docs[0]
if docs_dir == docs[0]:
docs = []
else:
if docs_dir is None:
docs_dir = os.path.dirname(docs[0])
else:
docs_dir = os.path.dirname(doc)
if docs_dir is None:
docs_dir = os.path.commonprefix(docs).rpartition(os.path.sep)[0]
tests = TestRun(docs_dir, options['refs_dir'], options['out_dir'])
if doc == docs_dir:
status = tests.run_tests()
else:
status = tests.run_test(os.path.basename(doc))
status = tests.run_tests(docs)
tests.summary()
get_printer().printout_ln("Tests run in %s" % (t.elapsed_str()))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment