[Request] [+ ] D8571: test: make test-doctest.py not assume it's run from a mercurial repo

jcristau (Julien Cristau) phabricator at mercurial-scm.org
Tue May 19 19:28:33 UTC 2020


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

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)



To: jcristau, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mercurial-scm.org/pipermail/mercurial-patches/attachments/20200519/ec1d56fd/attachment-0001.html>


More information about the Mercurial-patches mailing list