~fluidity-core/fluidity/sea-ice-branch

« back to all changes in this revision

Viewing changes to tools/testharness.py

  • Committer: Simon Mouradian
  • Date: 2012-10-19 10:35:59 UTC
  • mfrom: (3520.32.371 fluidity)
  • Revision ID: simon.mouradian06@imperial.ac.uk-20121019103559-y36qa47phc69q8sc
mergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
  import elementtree.ElementTree as etree
19
19
 
20
20
class TestHarness:
21
 
    def __init__(self, length="any", parallel=False, exclude_tags=None, tags=None, file="", verbose=True, justtest=False,
22
 
        valgrind=False):
 
21
    def __init__(self, length="any", parallel=False, exclude_tags=None,
 
22
                 tags=None, file="", from_file=None,
 
23
                 verbose=True, justtest=False,
 
24
                 valgrind=False):
23
25
        self.tests = []
24
26
        self.verbose = verbose
25
27
        self.length = length
71
73
        # step 2. if the user has specified a particular file, let's use that.
72
74
 
73
75
        if file != "":
 
76
          files = [file]
 
77
        elif from_file:
 
78
          try:
 
79
            f = open(from_file, 'r')
 
80
            files = [line[:-1] for line in f.readlines()]
 
81
          except IOError as e:
 
82
            sys.stderr.write("Unable to read tests from file %s: %s" % (from_file, e))
 
83
            sys.exit(1)
 
84
          f.close()
 
85
        else:
 
86
          files = None
 
87
 
 
88
        if files:
74
89
          for (subdir, xml_file) in [os.path.split(x) for x in xml_files]:
75
 
            if xml_file == file:
 
90
            if xml_file in files:
76
91
              testprob = regressiontest.TestProblem(filename=os.path.join(subdir, xml_file),
77
92
                           verbose=self.verbose, replace=self.modify_command_line())
78
 
              self.tests = [(subdir, testprob)]
79
 
              return
80
 
          print "Could not find file %s." % file
81
 
          sys.exit(1)
 
93
              self.tests.append((subdir, testprob))
 
94
              files.remove(xml_file)
 
95
          if files != []:
 
96
            print "Could not find the following specified test files:"
 
97
            for f in files:
 
98
              print f
 
99
            sys.exit(1)
 
100
          return
82
101
 
83
102
        # step 3. form a cut-down list of the xml files matching the correct length and the correct parallelism.
84
103
        working_set = []
328
347
    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")
329
348
    parser.add_option("-t", "--tags", dest="tags", help="run tests with specific tags", default=[], action="append")
330
349
    parser.add_option("-f", "--file", dest="file", help="specific test case to run (by filename)", default="")
 
350
    parser.add_option("--from-file", dest="from_file", default=None,
 
351
                      help="run tests listed in FROM_FILE (one test per line)")
331
352
    parser.add_option("-n", "--threads", dest="thread_count", type="int",
332
353
                      help="number of tests to run at the same time", default=1)
333
354
    parser.add_option("-v", "--valgrind", action="store_true", dest="valgrind")
367
388
    else:
368
389
      tags = options.tags
369
390
 
370
 
    testharness = TestHarness(length=options.length, parallel=para, exclude_tags=exclude_tags, tags=tags, file=options.file, verbose=True,
371
 
        justtest=options.justtest, valgrind=options.valgrind)
 
391
    testharness = TestHarness(length=options.length, parallel=para,
 
392
                              exclude_tags=exclude_tags, tags=tags,
 
393
                              file=options.file, verbose=True,
 
394
                              justtest=options.justtest,
 
395
                              valgrind=options.valgrind,
 
396
                              from_file=options.from_file)
372
397
 
373
398
    if options.justlist:
374
399
      testharness.list()