Mercurial > hg
changeset 40687:dd028bca9221
tests: make test-check-module-imports more robust
It failed for me without this in this way:
tests/test-commandserver.t:19: relative import of stdlib module
tests/test-lfs-serve.t:108: relative import of stdlib module
tests/test-lfs-serve.t:255: relative import of stdlib module
tests/test-lfs-serve.t:362: relative import of stdlib module
tests/test-lfs-serve.t:406: relative import of stdlib module
tests/test-lock.py:9: imports not lexically sorted: silenttestrunner < unittest, True, True
tests/test-lrucachedict.py:5: imports not lexically sorted: silenttestrunner < unittest, True, True
tests/test-match.py:5: imports not lexically sorted: silenttestrunner < unittest, True, True
tests/test-remotefilelog-datapack.py:15: imports not lexically sorted: silenttestrunner < unittest, True, True
tests/test-remotefilelog-histpack.py:14: imports not lexically sorted: silenttestrunner < unittest, True, True
tests/test-simplekeyvaluefile.py:4: imports not lexically sorted: silenttestrunner < unittest, True, True
tests/test-sshserver.py:6: imports not lexically sorted: silenttestrunner < unittest, True, True
This is because every module is considered a stdlib module, because
the stdlib_prefixes is /usr, and my repo is in /usr/local/home, which
means that sys.path contains a couple of
/usr/local/home/../hg/.. entries that count as "in the stdlib".
Fix this by preventing any path in sys.path that's inside the mercurial
source from being considered "in the stdlib".
Differential Revision: https://phab.mercurial-scm.org/D5294
author | Valentin Gatien-Baron <vgatien-baron@janestreet.com> |
---|---|
date | Wed, 21 Nov 2018 13:08:23 -0500 |
parents | 9b8d1ad851f8 |
children | 0d8425311f2f |
files | contrib/import-checker.py |
diffstat | 1 files changed, 5 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/contrib/import-checker.py Sat Oct 27 21:13:23 2018 +0800 +++ b/contrib/import-checker.py Wed Nov 21 13:08:23 2018 -0500 @@ -260,10 +260,12 @@ break else: stdlib_prefixes.add(dirname) + sourceroot = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) for libpath in sys.path: - # We want to walk everything in sys.path that starts with - # something in stdlib_prefixes. - if not any(libpath.startswith(p) for p in stdlib_prefixes): + # We want to walk everything in sys.path that starts with something in + # stdlib_prefixes, but not directories from the hg sources. + if (os.path.abspath(libpath).startswith(sourceroot) + or not any(libpath.startswith(p) for p in stdlib_prefixes)): continue for top, dirs, files in os.walk(libpath): for i, d in reversed(list(enumerate(dirs))):