Patchwork D7133: run-tests: make code coverage work on Python 3

login
register
mail settings
Submitter phabricator
Date Oct. 18, 2019, 3:40 a.m.
Message ID <differential-rev-PHID-DREV-37khhjdgvzfmzajlx4aa-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/42469/
State Superseded
Headers show

Comments

phabricator - Oct. 18, 2019, 3:40 a.m.
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This code path was obviously not tested on Python 3 because it
  blew up in several places due to str/bytes mismatch.
  
  For internal code, we normalize paths to bytes.
  
  For code calling into `coverage`, we normalize paths to str,
  which is what `coverage` seems to expect.
  
  After this, `run-tests.py -H` works on Python 3!

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D7133

AFFECTED FILES
  tests/run-tests.py

CHANGE DETAILS




To: indygreg, #hg-reviewers
Cc: mercurial-devel
Yuya Nishihara - Oct. 18, 2019, 12:37 p.m.
Fixed some `os.environb` and queued, thanks.
phabricator - Oct. 18, 2019, 12:40 p.m.
yuja added a comment.


  Fixed some `os.environb` and queued, thanks.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7133/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7133

To: indygreg, #hg-reviewers
Cc: yuja, mercurial-devel

Patch

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -3518,21 +3518,23 @@ 
                 print('WARNING: cannot fix hg.bat reference to python.exe')
 
         if self.options.anycoverage:
-            custom = os.path.join(osenvironb[b'RUNTESTDIR'], 'sitecustomize.py')
-            target = os.path.join(self._pythondir, 'sitecustomize.py')
+            custom = os.path.join(
+                osenvironb[b'RUNTESTDIR'], b'sitecustomize.py'
+            )
+            target = os.path.join(self._pythondir, b'sitecustomize.py')
             vlog('# Installing coverage trigger to %s' % target)
             shutil.copyfile(custom, target)
-            rc = os.path.join(self._testdir, '.coveragerc')
+            rc = os.path.join(self._testdir, b'.coveragerc')
             vlog('# Installing coverage rc to %s' % rc)
-            os.environ['COVERAGE_PROCESS_START'] = rc
-            covdir = os.path.join(self._installdir, '..', 'coverage')
+            os.environb[b'COVERAGE_PROCESS_START'] = rc
+            covdir = os.path.join(self._installdir, b'..', b'coverage')
             try:
                 os.mkdir(covdir)
             except OSError as e:
                 if e.errno != errno.EEXIST:
                     raise
 
-            os.environ['COVERAGE_DIR'] = covdir
+            os.environb[b'COVERAGE_DIR'] = covdir
 
     def _checkhglib(self, verb):
         """Ensure that the 'mercurial' package imported by python is
@@ -3606,22 +3608,25 @@ 
         # chdir is the easiest way to get short, relative paths in the
         # output.
         os.chdir(self._hgroot)
-        covdir = os.path.join(self._installdir, '..', 'coverage')
+        covdir = os.path.join(_strpath(self._installdir), '..', 'coverage')
         cov = coverage(data_file=os.path.join(covdir, 'cov'))
 
         # Map install directory paths back to source directory.
-        cov.config.paths['srcdir'] = ['.', self._pythondir]
+        cov.config.paths['srcdir'] = ['.', _strpath(self._pythondir)]
 
         cov.combine()
 
-        omit = [os.path.join(x, '*') for x in [self._bindir, self._testdir]]
+        omit = [
+            _strpath(os.path.join(x, b'*'))
+            for x in [self._bindir, self._testdir]
+        ]
         cov.report(ignore_errors=True, omit=omit)
 
         if self.options.htmlcov:
-            htmldir = os.path.join(self._outputdir, 'htmlcov')
+            htmldir = os.path.join(_strpath(self._outputdir), 'htmlcov')
             cov.html_report(directory=htmldir, omit=omit)
         if self.options.annotate:
-            adir = os.path.join(self._outputdir, 'annotated')
+            adir = os.path.join(_strpath(self._outputdir), 'annotated')
             if not os.path.isdir(adir):
                 os.mkdir(adir)
             cov.annotate(directory=adir, omit=omit)