Patchwork D8571: test: make test-doctest.py not assume it's run from a mercurial repo

login
register
mail settings
Submitter phabricator
Date May 19, 2020, 7:28 p.m.
Message ID <differential-rev-PHID-DREV-7h3ha2yp6jyyyexgbbom-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/46361/
State New
Headers show

Comments

phabricator - May 19, 2020, 7:28 p.m.
jcristau created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This assumption fails when building and running tests from a source
  tarball, e.g.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  tests/test-doctest.py

CHANGE DETAILS




To: jcristau, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/tests/test-doctest.py b/tests/test-doctest.py
--- a/tests/test-doctest.py
+++ b/tests/test-doctest.py
@@ -6,7 +6,6 @@ 
 import doctest
 import os
 import re
-import subprocess
 import sys
 
 ispy3 = sys.version_info[0] >= 3
@@ -70,11 +69,18 @@ 
 
 fileset = 'set:(**.py)'
 
-cwd = os.path.dirname(os.environ["TESTDIR"])
+if ispy3:
+    cwd = os.path.dirname(os.environb[b"TESTDIR"])
+else:
+    cwd = os.path.dirname(os.environ["TESTDIR"])
 
-files = subprocess.check_output(
-    "hg files --print0 \"%s\"" % fileset, shell=True, cwd=cwd,
-).split(b'\0')
+files = []
+for dirpath, dirnames, filenames in os.walk(cwd):
+    dotdirindexes = reversed([i for i, dir in enumerate(dirnames) if dir.startswith(b'.')])
+    for i in dotdirindexes:
+        del dirnames[i]
+    # include all .py files, removing the cwd + dirsep prefix
+    files.extend(os.path.join(dirpath, f)[len(cwd) + 1:] for f in filenames if f.endswith(b'.py'))
 
 if sys.version_info[0] >= 3:
     cwd = os.fsencode(cwd)