From a8bfabf2e6c3242e0f882c6dff4a0b7fdccaefc1 Mon Sep 17 00:00:00 2001 From: Gregory Szorc Date: Fri, 27 Mar 2015 23:17:19 -0700 Subject: [PATCH] run-tests: obtain code coverage via Python API Before, we were invoking the "coverage" program provided by the "coverage" module. This patch changes the code to go through the Python API. This makes the next patch a little bit easier to reason about. A side effect of this patch is that writing code coverage reports will be slightly faster, as we won't have to redundantly load coverage data. --- tests/run-tests.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/run-tests.py b/tests/run-tests.py index 2430427632..3215514b3f 100755 --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -1985,27 +1985,27 @@ class TestRunner(object): def _outputcoverage(self): """Produce code coverage output.""" + from coverage import coverage + vlog('# Producing coverage report') + # chdir is the easiest way to get short, relative paths in the + # output. os.chdir(self._pythondir) + covdir = os.path.join(self._installdir, '..') + cov = coverage(data_file=os.path.join(covdir, '.coverage')) + cov.load() - def covrun(*args): - cmd = 'coverage %s' % ' '.join(args) - vlog('# Running: %s' % cmd) - os.system(cmd) + omit = [os.path.join(x, '*') for x in [self._bindir, self._testdir]] + cov.report(ignore_errors=True, omit=omit) - 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) + cov.html_report(directory=htmldir, omit=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) + cov.annotate(directory=adir, omit=omit) def _findprogram(self, program): """Search PATH for a executable program"""