run-tests: move outputcoverage() into TestRunner
authorGregory Szorc <gregory.szorc@gmail.com>
Sat, 19 Apr 2014 23:49:23 -0700
changeset 21356 f96d7dfd8cb5
parent 21355 d83f4e94512a
child 21357 4c4f64b8df3c
run-tests: move outputcoverage() into TestRunner
tests/run-tests.py
--- a/tests/run-tests.py	Sat Apr 19 23:47:59 2014 -0700
+++ b/tests/run-tests.py	Sat Apr 19 23:49:23 2014 -0700
@@ -386,29 +386,6 @@
     return killmod.killdaemons(pidfile, tryhard=False, remove=True,
                                logfn=vlog)
 
-def outputcoverage(runner):
-
-    vlog('# Producing coverage report')
-    os.chdir(runner.pythondir)
-
-    def covrun(*args):
-        cmd = 'coverage %s' % ' '.join(args)
-        vlog('# Running: %s' % cmd)
-        os.system(cmd)
-
-    covrun('-c')
-    omit = ','.join(os.path.join(x, '*') for x in
-                    [runner.bindir, runner.testdir])
-    covrun('-i', '-r', '"--omit=%s"' % omit) # report
-    if runner.options.htmlcov:
-        htmldir = os.path.join(runner.testdir, 'htmlcov')
-        covrun('-i', '-b', '"--directory=%s"' % htmldir, '"--omit=%s"' % omit)
-    if runner.options.annotate:
-        adir = os.path.join(runner.testdir, 'annotated')
-        if not os.path.isdir(adir):
-            os.mkdir(adir)
-        covrun('-i', '-a', '"--directory=%s"' % adir, '"--omit=%s"' % omit)
-
 class Test(object):
     """Encapsulates a single, runnable test.
 
@@ -1121,7 +1098,7 @@
             runner.outputtimes()
 
         if runner.options.anycoverage:
-            outputcoverage(runner)
+            runner.outputcoverage()
     except KeyboardInterrupt:
         failed = True
         print "\ninterrupted!"
@@ -1301,6 +1278,29 @@
         for test, timetaken in times:
             print cols % (timetaken, test)
 
+    def outputcoverage(self):
+        vlog('# Producing coverage report')
+        os.chdir(self.pythondir)
+
+        def covrun(*args):
+            cmd = 'coverage %s' % ' '.join(args)
+            vlog('# Running: %s' % cmd)
+            os.system(cmd)
+
+        covrun('-c')
+        omit = ','.join(os.path.join(x, '*') for x in
+                        [self.bindir, self.testdir])
+        covrun('-i', '-r', '"--omit=%s"' % omit) # report
+        if self.options.htmlcov:
+            htmldir = os.path.join(self.testdir, 'htmlcov')
+            covrun('-i', '-b', '"--directory=%s"' % htmldir,
+                   '"--omit=%s"' % omit)
+        if self.options.annotate:
+            adir = os.path.join(self.testdir, 'annotated')
+            if not os.path.isdir(adir):
+                os.mkdir(adir)
+            covrun('-i', '-a', '"--directory=%s"' % adir, '"--omit=%s"' % omit)
+
 def main(args, parser=None):
     runner = TestRunner()