Merge lp:~asc/fluidity/testharnesscwd2 into lp:fluidity

Proposed by Adam Candy
Status: Work in progress
Proposed branch: lp:~asc/fluidity/testharnesscwd2
Merge into: lp:fluidity
Diff against target: 53 lines (+13/-9)
1 file modified
tools/testharness.py (+13/-9)
To merge this branch: bzr merge lp:~asc/fluidity/testharnesscwd2
Reviewer Review Type Date Requested Status
Adam Candy Needs Fixing
Review via email: mp+74069@code.launchpad.net

Description of the change

Added an option to testharness.py to search for test XMLs in folders of the current working directory. This is useful if you use one version of the script in multiple branches.

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

Hi Adam,

a) I'm a bit confused about what the use case of this can be. Can you tell the story of why you wanted this feature?

b) Couldn't this feature be much more simply implemented with a one-line change like

=== modified file 'tools/testharness.py'
--- tools/testharness.py 2011-08-05 11:19:06 +0000
+++ tools/testharness.py 2011-09-05 14:53:28 +0000
@@ -50,7 +50,7 @@
         for directory in testpaths:
           if os.path.exists(os.path.join(rootdir, directory)):
             dirnames.append(directory)
- testdirs = [ os.path.join( rootdir, x ) for x in dirnames ]
+ testdirs = [ os.path.join( rootdir, x ) for x in dirnames ] + [os.getcwd()]
         for directory in testdirs:
           subdirs = [ os.path.join(directory, x) for x in os.listdir(directory)]
           for subdir in subdirs:

? I don't really know why you didn't take this approach -- like I said, I don't know why you want it.

Revision history for this message
Adam Candy (asc) wrote :

Hi Patrick,

Thanks for the feedback. This simple fix was avoided because it could interfere with current usage. Adding the current working directory to the list of testdirs could result in additional tests being picked up unexpectedly, hence the additional structure was included to avoid changing the default behaviour.

Revision history for this message
Adam Candy (asc) wrote :

The motivation for the change is to:

 1. Use the script from a $PATH location,
 2. on a given test folder (which might be standalone),
 3. from an arbitrary location (already possible before the above, but more complicated in combination with 1 and 2).

Point 1 was because I have several modifications to the testharness.py and just wanted to use one instance of the script for multiple branches (e.g. place it in ~/bin) and point 2 because I have some tests in a standalone folder that I have been testing using multiple branches.

Of course there is an issue with 2, in that tests can have dependencies within the Fluidity source (in the mesh generation, for example). This could work if it was possible to provide the root Fluidity folder (for the binary and other test dependencies) together with the location of the test folder (the default being ../ and ../{examples,tests,longtests} respectively).

As it stands the changes need further thought, so I'll pull the merge request for now. It is possible to use with the limitations that the script itself, binary and associated tools must all be located in the Fluidity source tree, together with the folder of tests.

Revision history for this message
Adam Candy (asc) :
review: Needs Fixing

Unmerged revisions

3569. By Adam Candy

Added an option to testharness.py to search for test XMLs in folders of the current working directory. This is useful if you use one version of the script in multiple branches.

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-08-05 11:19:06 +0000
3+++ tools/testharness.py 2011-09-05 10:31:28 +0000
4@@ -15,7 +15,7 @@
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+ def __init__(self, length="any", parallel=False, exclude_tags=None, tags=None, file="", cwd=False, verbose=True, justtest=False,
10 valgrind=False):
11 self.tests = []
12 self.verbose = verbose
13@@ -44,13 +44,16 @@
14 # step 1. form a list of all the xml files to be considered.
15
16 xml_files = []
17- rootdir = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), os.pardir))
18- dirnames = []
19- testpaths = ["examples", "tests", "longtests"]
20- for directory in testpaths:
21- if os.path.exists(os.path.join(rootdir, directory)):
22- dirnames.append(directory)
23- testdirs = [ os.path.join( rootdir, x ) for x in dirnames ]
24+ if cwd:
25+ testdirs = [ os.getcwd() ]
26+ else:
27+ rootdir = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), os.pardir))
28+ dirnames = []
29+ testpaths = ["examples", "tests", "longtests"]
30+ for directory in testpaths:
31+ if os.path.exists(os.path.join(rootdir, directory)):
32+ dirnames.append(directory)
33+ testdirs = [ os.path.join( rootdir, x ) for x in dirnames ]
34 for directory in testdirs:
35 subdirs = [ os.path.join(directory, x) for x in os.listdir(directory)]
36 for subdir in subdirs:
37@@ -328,6 +331,7 @@
38 parser.add_option("-n", "--threads", dest="thread_count", type="int",
39 help="number of tests to run at the same time", default=1)
40 parser.add_option("-v", "--valgrind", action="store_true", dest="valgrind")
41+ parser.add_option("-d", "--cwd", action="store_true", dest="cwd", help="look for test XMLs in folders of current working directory", default = False)
42 parser.add_option("-c", "--clean", action="store_true", dest="clean", default = False)
43 parser.add_option("--just-test", action="store_true", dest="justtest")
44 parser.add_option("--just-list", action="store_true", dest="justlist")
45@@ -364,7 +368,7 @@
46 else:
47 tags = options.tags
48
49- testharness = TestHarness(length=options.length, parallel=para, exclude_tags=exclude_tags, tags=tags, file=options.file, verbose=True,
50+ testharness = TestHarness(length=options.length, parallel=para, exclude_tags=exclude_tags, tags=tags, file=options.file, cwd=options.cwd, verbose=True,
51 justtest=options.justtest, valgrind=options.valgrind)
52
53 if options.justlist: