comparison tests/run-tests.py @ 24504:7046ecabd9a8

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.
author Gregory Szorc <gregory.szorc@gmail.com>
date Fri, 27 Mar 2015 23:17:19 -0700
parents 7b0a20cd8c95
children 031947baf4d0
comparison
equal deleted inserted replaced
24503:944749de6f3a 24504:7046ecabd9a8
1983 1983
1984 return self._hgpath 1984 return self._hgpath
1985 1985
1986 def _outputcoverage(self): 1986 def _outputcoverage(self):
1987 """Produce code coverage output.""" 1987 """Produce code coverage output."""
1988 from coverage import coverage
1989
1988 vlog('# Producing coverage report') 1990 vlog('# Producing coverage report')
1991 # chdir is the easiest way to get short, relative paths in the
1992 # output.
1989 os.chdir(self._pythondir) 1993 os.chdir(self._pythondir)
1990 1994 covdir = os.path.join(self._installdir, '..')
1991 def covrun(*args): 1995 cov = coverage(data_file=os.path.join(covdir, '.coverage'))
1992 cmd = 'coverage %s' % ' '.join(args) 1996 cov.load()
1993 vlog('# Running: %s' % cmd) 1997
1994 os.system(cmd) 1998 omit = [os.path.join(x, '*') for x in [self._bindir, self._testdir]]
1995 1999 cov.report(ignore_errors=True, omit=omit)
1996 covrun('-c') 2000
1997 omit = ','.join(os.path.join(x, '*') for x in
1998 [self._bindir, self._testdir])
1999 covrun('-i', '-r', '"--omit=%s"' % omit) # report
2000 if self.options.htmlcov: 2001 if self.options.htmlcov:
2001 htmldir = os.path.join(self._testdir, 'htmlcov') 2002 htmldir = os.path.join(self._testdir, 'htmlcov')
2002 covrun('-i', '-b', '"--directory=%s"' % htmldir, 2003 cov.html_report(directory=htmldir, omit=omit)
2003 '"--omit=%s"' % omit)
2004 if self.options.annotate: 2004 if self.options.annotate:
2005 adir = os.path.join(self._testdir, 'annotated') 2005 adir = os.path.join(self._testdir, 'annotated')
2006 if not os.path.isdir(adir): 2006 if not os.path.isdir(adir):
2007 os.mkdir(adir) 2007 os.mkdir(adir)
2008 covrun('-i', '-a', '"--directory=%s"' % adir, '"--omit=%s"' % omit) 2008 cov.annotate(directory=adir, omit=omit)
2009 2009
2010 def _findprogram(self, program): 2010 def _findprogram(self, program):
2011 """Search PATH for a executable program""" 2011 """Search PATH for a executable program"""
2012 for p in os.environ.get('PATH', os.defpath).split(os.pathsep): 2012 for p in os.environ.get('PATH', os.defpath).split(os.pathsep):
2013 name = os.path.join(p, program) 2013 name = os.path.join(p, program)