Merge lp:~wence/fluidity/testharness-tests-from-file into lp:fluidity

Proposed by Lawrence Mitchell
Status: Merged
Merged at revision: 4090
Proposed branch: lp:~wence/fluidity/testharness-tests-from-file
Merge into: lp:fluidity
Diff against target: 77 lines (+34/-9)
1 file modified
tools/testharness.py (+34/-9)
To merge this branch: bzr merge lp:~wence/fluidity/testharness-tests-from-file
Reviewer Review Type Date Requested Status
Patrick Farrell Approve
Review via email: mp+129639@code.launchpad.net

Description of the change

Allow running a set of tests using testharness by specifying a file that lists tests to run. Useful for break/test/debug/maybe-fix cycles.

To post a comment you must log in.
Revision history for this message
Patrick Farrell (pefarrell) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tools/testharness.py'
2--- tools/testharness.py 2011-11-04 13:20:03 +0000
3+++ tools/testharness.py 2012-10-15 10:06:24 +0000
4@@ -18,8 +18,10 @@
5 import elementtree.ElementTree as etree
6
7 class TestHarness:
8- def __init__(self, length="any", parallel=False, exclude_tags=None, tags=None, file="", verbose=True, justtest=False,
9- valgrind=False):
10+ def __init__(self, length="any", parallel=False, exclude_tags=None,
11+ tags=None, file="", from_file=None,
12+ verbose=True, justtest=False,
13+ valgrind=False):
14 self.tests = []
15 self.verbose = verbose
16 self.length = length
17@@ -71,14 +73,31 @@
18 # step 2. if the user has specified a particular file, let's use that.
19
20 if file != "":
21+ files = [file]
22+ elif from_file:
23+ try:
24+ f = open(from_file, 'r')
25+ files = [line[:-1] for line in f.readlines()]
26+ except IOError as e:
27+ sys.stderr.write("Unable to read tests from file %s: %s" % (from_file, e))
28+ sys.exit(1)
29+ f.close()
30+ else:
31+ files = None
32+
33+ if files:
34 for (subdir, xml_file) in [os.path.split(x) for x in xml_files]:
35- if xml_file == file:
36+ if xml_file in files:
37 testprob = regressiontest.TestProblem(filename=os.path.join(subdir, xml_file),
38 verbose=self.verbose, replace=self.modify_command_line())
39- self.tests = [(subdir, testprob)]
40- return
41- print "Could not find file %s." % file
42- sys.exit(1)
43+ self.tests.append((subdir, testprob))
44+ files.remove(xml_file)
45+ if files != []:
46+ print "Could not find the following specified test files:"
47+ for f in files:
48+ print f
49+ sys.exit(1)
50+ return
51
52 # step 3. form a cut-down list of the xml files matching the correct length and the correct parallelism.
53 working_set = []
54@@ -328,6 +347,8 @@
55 parser.add_option("-e", "--exclude-tags", dest="exclude_tags", help="run only tests that do not have specific tags (takes precidence over -t)", default=[], action="append")
56 parser.add_option("-t", "--tags", dest="tags", help="run tests with specific tags", default=[], action="append")
57 parser.add_option("-f", "--file", dest="file", help="specific test case to run (by filename)", default="")
58+ parser.add_option("--from-file", dest="from_file", default=None,
59+ help="run tests listed in FROM_FILE (one test per line)")
60 parser.add_option("-n", "--threads", dest="thread_count", type="int",
61 help="number of tests to run at the same time", default=1)
62 parser.add_option("-v", "--valgrind", action="store_true", dest="valgrind")
63@@ -367,8 +388,12 @@
64 else:
65 tags = options.tags
66
67- testharness = TestHarness(length=options.length, parallel=para, exclude_tags=exclude_tags, tags=tags, file=options.file, verbose=True,
68- justtest=options.justtest, valgrind=options.valgrind)
69+ testharness = TestHarness(length=options.length, parallel=para,
70+ exclude_tags=exclude_tags, tags=tags,
71+ file=options.file, verbose=True,
72+ justtest=options.justtest,
73+ valgrind=options.valgrind,
74+ from_file=options.from_file)
75
76 if options.justlist:
77 testharness.list()