tests/run-tests.py
changeset 21356 f96d7dfd8cb5
parent 21355 d83f4e94512a
child 21357 4c4f64b8df3c
equal deleted inserted replaced
21355:d83f4e94512a 21356:f96d7dfd8cb5
   384 
   384 
   385 def killdaemons(pidfile):
   385 def killdaemons(pidfile):
   386     return killmod.killdaemons(pidfile, tryhard=False, remove=True,
   386     return killmod.killdaemons(pidfile, tryhard=False, remove=True,
   387                                logfn=vlog)
   387                                logfn=vlog)
   388 
   388 
   389 def outputcoverage(runner):
       
   390 
       
   391     vlog('# Producing coverage report')
       
   392     os.chdir(runner.pythondir)
       
   393 
       
   394     def covrun(*args):
       
   395         cmd = 'coverage %s' % ' '.join(args)
       
   396         vlog('# Running: %s' % cmd)
       
   397         os.system(cmd)
       
   398 
       
   399     covrun('-c')
       
   400     omit = ','.join(os.path.join(x, '*') for x in
       
   401                     [runner.bindir, runner.testdir])
       
   402     covrun('-i', '-r', '"--omit=%s"' % omit) # report
       
   403     if runner.options.htmlcov:
       
   404         htmldir = os.path.join(runner.testdir, 'htmlcov')
       
   405         covrun('-i', '-b', '"--directory=%s"' % htmldir, '"--omit=%s"' % omit)
       
   406     if runner.options.annotate:
       
   407         adir = os.path.join(runner.testdir, 'annotated')
       
   408         if not os.path.isdir(adir):
       
   409             os.mkdir(adir)
       
   410         covrun('-i', '-a', '"--directory=%s"' % adir, '"--omit=%s"' % omit)
       
   411 
       
   412 class Test(object):
   389 class Test(object):
   413     """Encapsulates a single, runnable test.
   390     """Encapsulates a single, runnable test.
   414 
   391 
   415     Test instances can be run multiple times via run(). However, multiple
   392     Test instances can be run multiple times via run(). However, multiple
   416     runs cannot be run concurrently.
   393     runs cannot be run concurrently.
  1119             print 'python hash seed:', os.environ['PYTHONHASHSEED']
  1096             print 'python hash seed:', os.environ['PYTHONHASHSEED']
  1120         if runner.options.time:
  1097         if runner.options.time:
  1121             runner.outputtimes()
  1098             runner.outputtimes()
  1122 
  1099 
  1123         if runner.options.anycoverage:
  1100         if runner.options.anycoverage:
  1124             outputcoverage(runner)
  1101             runner.outputcoverage()
  1125     except KeyboardInterrupt:
  1102     except KeyboardInterrupt:
  1126         failed = True
  1103         failed = True
  1127         print "\ninterrupted!"
  1104         print "\ninterrupted!"
  1128 
  1105 
  1129     if failed:
  1106     if failed:
  1299         cols = '%7.3f   %s'
  1276         cols = '%7.3f   %s'
  1300         print '\n%-7s   %s' % ('Time', 'Test')
  1277         print '\n%-7s   %s' % ('Time', 'Test')
  1301         for test, timetaken in times:
  1278         for test, timetaken in times:
  1302             print cols % (timetaken, test)
  1279             print cols % (timetaken, test)
  1303 
  1280 
       
  1281     def outputcoverage(self):
       
  1282         vlog('# Producing coverage report')
       
  1283         os.chdir(self.pythondir)
       
  1284 
       
  1285         def covrun(*args):
       
  1286             cmd = 'coverage %s' % ' '.join(args)
       
  1287             vlog('# Running: %s' % cmd)
       
  1288             os.system(cmd)
       
  1289 
       
  1290         covrun('-c')
       
  1291         omit = ','.join(os.path.join(x, '*') for x in
       
  1292                         [self.bindir, self.testdir])
       
  1293         covrun('-i', '-r', '"--omit=%s"' % omit) # report
       
  1294         if self.options.htmlcov:
       
  1295             htmldir = os.path.join(self.testdir, 'htmlcov')
       
  1296             covrun('-i', '-b', '"--directory=%s"' % htmldir,
       
  1297                    '"--omit=%s"' % omit)
       
  1298         if self.options.annotate:
       
  1299             adir = os.path.join(self.testdir, 'annotated')
       
  1300             if not os.path.isdir(adir):
       
  1301                 os.mkdir(adir)
       
  1302             covrun('-i', '-a', '"--directory=%s"' % adir, '"--omit=%s"' % omit)
       
  1303 
  1304 def main(args, parser=None):
  1304 def main(args, parser=None):
  1305     runner = TestRunner()
  1305     runner = TestRunner()
  1306 
  1306 
  1307     parser = parser or getparser()
  1307     parser = parser or getparser()
  1308     (options, args) = parseargs(args, parser)
  1308     (options, args) = parseargs(args, parser)