Mercurial > hg-stable
changeset 40369:ef6cab7930b3
py3: fix module imports in tests, as flagged by test-check-module-imports.t
I have no idea why these aren't flagged with python2. I excluded
test-highlight.t for now to make this easier to review- the changed code is
committed to a repo, which has cascading changes on the rest of the test.
There's a mix of bytes and str in the imports dict of contrib/import-checker.py
that crashed it half way through listing out these errors. I couldn't figure
out how to fix that properly, so I was lazy and applied this on py3, to find the
rest of the errors:
diff --git a/contrib/import-checker.py b/contrib/import-checker.py
--- a/contrib/import-checker.py
+++ b/contrib/import-checker.py
@@ -626,7 +626,12 @@ def find_cycles(imports):
top.foo -> top.qux -> top.foo
"""
cycles = set()
- for mod in sorted(imports.keys()):
+ def sort(v):
+ if isinstance(v, bytes):
+ return v.decode('ascii')
+ return v
+
+ for mod in sorted(imports.keys(), key=sort):
try:
checkmod(mod, imports)
except CircularImport as e:
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Wed, 17 Oct 2018 23:33:43 -0400 |
parents | fad6068249d9 |
children | 3b84ef904aea |
files | tests/test-basic.t tests/test-blackbox.t tests/test-bundle2-exchange.t tests/test-clone.t tests/test-commit-multiple.t tests/test-devel-warnings.t tests/test-encoding.t tests/test-extension.t tests/test-import.t tests/test-install.t tests/test-issue5979.t tests/test-journal.t tests/test-pager-legacy.t tests/test-parseindex.t tests/test-pending.t tests/test-profile.t tests/test-purge.t |
diffstat | 17 files changed, 39 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/tests/test-basic.t Thu Oct 18 21:55:47 2018 -0400 +++ b/tests/test-basic.t Wed Oct 17 23:33:43 2018 -0400 @@ -61,8 +61,8 @@ Verify that updating to revision 0 via commands.update() works properly $ cat <<EOF > update_to_rev0.py - > from mercurial import ui, hg, commands - > myui = ui.ui.load() + > from mercurial import commands, hg, ui as uimod + > myui = uimod.ui.load() > repo = hg.repository(myui, path=b'.') > commands.update(myui, repo, rev=b"0") > EOF
--- a/tests/test-blackbox.t Thu Oct 18 21:55:47 2018 -0400 +++ b/tests/test-blackbox.t Wed Oct 17 23:33:43 2018 -0400 @@ -351,7 +351,8 @@ $ chg noop $ cat > showsize.py << 'EOF' - > import os, sys + > import os + > import sys > limit = 500 > for p in sys.argv[1:]: > size = os.stat(p).st_size
--- a/tests/test-bundle2-exchange.t Thu Oct 18 21:55:47 2018 -0400 +++ b/tests/test-bundle2-exchange.t Wed Oct 17 23:33:43 2018 -0400 @@ -934,7 +934,7 @@ $ cat >> $TESTTMP/locktester.py <<EOF > import os - > from mercurial import extensions, bundle2, error + > from mercurial import bundle2, error, extensions > def checklock(orig, repo, *args, **kwargs): > if repo.svfs.lexists(b"lock"): > raise error.Abort(b"Lock should not be taken")
--- a/tests/test-clone.t Thu Oct 18 21:55:47 2018 -0400 +++ b/tests/test-clone.t Wed Oct 17 23:33:43 2018 -0400 @@ -558,8 +558,8 @@ iterable in addbranchrevs() $ cat <<EOF > simpleclone.py - > from mercurial import ui, hg - > myui = ui.ui.load() + > from mercurial import hg, ui as uimod + > myui = uimod.ui.load() > repo = hg.repository(myui, b'a') > hg.clone(myui, {}, repo, dest=b"ua") > EOF @@ -571,8 +571,8 @@ $ rm -r ua $ cat <<EOF > branchclone.py - > from mercurial import ui, hg, extensions - > myui = ui.ui.load() + > from mercurial import extensions, hg, ui as uimod + > myui = uimod.ui.load() > extensions.loadall(myui) > repo = hg.repository(myui, b'a') > hg.clone(myui, {}, repo, dest=b"ua", branch=[b"stable",])
--- a/tests/test-commit-multiple.t Thu Oct 18 21:55:47 2018 -0400 +++ b/tests/test-commit-multiple.t Wed Oct 17 23:33:43 2018 -0400 @@ -80,8 +80,8 @@ now test that we fixed the bug for all scripts/extensions $ cat > $TESTTMP/committwice.py <<__EOF__ - > from mercurial import ui, hg, match, node - > from time import sleep + > import time + > from mercurial import hg, match, node, ui as uimod > > def replacebyte(fn, b): > f = open(fn, "rb+") @@ -94,12 +94,12 @@ > % (rev, b', '.join(b"'%s'" % f > for f in repo[rev].files()))) > - > repo = hg.repository(ui.ui.load(), b'.') + > repo = hg.repository(uimod.ui.load(), b'.') > assert len(repo) == 6, \ > "initial: len(repo): %d, expected: 6" % len(repo) > > replacebyte(b"bugfix", b"u") - > sleep(2) + > time.sleep(2) > try: > repo.ui.status(b"PRE: len(repo): %d\n" % len(repo)) > wlock = repo.wlock()
--- a/tests/test-devel-warnings.t Thu Oct 18 21:55:47 2018 -0400 +++ b/tests/test-devel-warnings.t Wed Oct 17 23:33:43 2018 -0400 @@ -342,7 +342,7 @@ $ cat << EOF > ${TESTTMP}/buggyconfig.py > """A small extension that tests our developer warnings for config""" > - > from mercurial import registrar, configitems + > from mercurial import configitems, registrar > > cmdtable = {} > command = registrar.command(cmdtable)
--- a/tests/test-encoding.t Thu Oct 18 21:55:47 2018 -0400 +++ b/tests/test-encoding.t Wed Oct 17 23:33:43 2018 -0400 @@ -278,9 +278,10 @@ #if hypothesis - >>> from hypothesishelpers import * + >>> import hypothesishelpers >>> from mercurial import encoding - >>> roundtrips(st.binary(), encoding.fromutf8b, encoding.toutf8b) + >>> hypothesishelpers.roundtrips(hypothesishelpers.st.binary(), + ... encoding.fromutf8b, encoding.toutf8b) Round trip OK #endif
--- a/tests/test-extension.t Thu Oct 18 21:55:47 2018 -0400 +++ b/tests/test-extension.t Wed Oct 17 23:33:43 2018 -0400 @@ -1266,7 +1266,8 @@ > "broken extension' > NO_CHECK_EOF $ cat > path.py <<EOF - > import os, sys + > import os + > import sys > sys.path.insert(0, os.environ['HGEXTPATH']) > EOF $ HGEXTPATH=`pwd`
--- a/tests/test-import.t Thu Oct 18 21:55:47 2018 -0400 +++ b/tests/test-import.t Wed Oct 17 23:33:43 2018 -0400 @@ -285,7 +285,8 @@ $ rm -r b $ cat > mkmsg.py <<EOF - > import email.message, sys + > import email.message + > import sys > msg = email.message.Message() > patch = open(sys.argv[1], 'rb').read() > msg.set_payload(b'email commit message\n' + patch) @@ -383,7 +384,8 @@ The '---' tests the gitsendmail handling without proper mail headers $ cat > mkmsg2.py <<EOF - > import email.message, sys + > import email.message + > import sys > msg = email.message.Message() > patch = open(sys.argv[1], 'rb').read() > msg.set_payload(b'email patch\n\nnext line\n---\n' + patch) @@ -1871,8 +1873,8 @@ =========================== $ cat > $TESTTMP/parseextra.py <<EOF + > import mercurial.cmdutil > import mercurial.patch - > import mercurial.cmdutil > > def processfoo(repo, data, extra, opts): > if b'foo' in data:
--- a/tests/test-install.t Thu Oct 18 21:55:47 2018 -0400 +++ b/tests/test-install.t Wed Oct 17 23:33:43 2018 -0400 @@ -153,7 +153,9 @@ $ . "$TESTDIR/helpers-testrepo.sh" $ cat >> wixxml.py << EOF - > import os, subprocess, sys + > import os + > import subprocess + > import sys > import xml.etree.ElementTree as ET > > # MSYS mangles the path if it expands $TESTDIR
--- a/tests/test-issue5979.t Thu Oct 18 21:55:47 2018 -0400 +++ b/tests/test-issue5979.t Wed Oct 17 23:33:43 2018 -0400 @@ -22,9 +22,9 @@ o c0 - >>> from mercurial.ui import ui - >>> from mercurial.hg import repository - >>> repo = repository(ui()) + >>> from mercurial import hg + >>> from mercurial import ui as uimod + >>> repo = hg.repository(uimod.ui()) >>> for anc in repo.changelog.ancestors([4], inclusive=True): ... print(anc) 4
--- a/tests/test-journal.t Thu Oct 18 21:55:47 2018 -0400 +++ b/tests/test-journal.t Wed Oct 17 23:33:43 2018 -0400 @@ -3,7 +3,7 @@ $ cat >> testmocks.py << EOF > # mock out procutil.getuser() and util.makedate() to supply testable values > import os - > from mercurial import util, pycompat + > from mercurial import pycompat, util > from mercurial.utils import dateutil, procutil > def mockgetuser(): > return b'foobar'
--- a/tests/test-pager-legacy.t Thu Oct 18 21:55:47 2018 -0400 +++ b/tests/test-pager-legacy.t Wed Oct 17 23:33:43 2018 -0400 @@ -244,7 +244,7 @@ Pager should not override the exit code of other commands $ cat >> $TESTTMP/fortytwo.py <<'EOF' - > from mercurial import registrar, commands + > from mercurial import commands, registrar > cmdtable = {} > command = registrar.command(cmdtable) > @command(b'fortytwo', [], b'fortytwo', norepo=True)
--- a/tests/test-parseindex.t Thu Oct 18 21:55:47 2018 -0400 +++ b/tests/test-parseindex.t Wed Oct 17 23:33:43 2018 -0400 @@ -27,8 +27,7 @@ $ cat >> test.py << EOF > from __future__ import print_function - > from mercurial import changelog, vfs - > from mercurial.node import * + > from mercurial import changelog, node, vfs > > class singlebyteread(object): > def __init__(self, real): @@ -59,7 +58,7 @@ > cl = changelog.changelog(opener('.hg/store')) > print(len(cl), 'revisions:') > for r in cl: - > print(short(cl.node(r))) + > print(node.short(cl.node(r))) > EOF $ "$PYTHON" test.py 2 revisions:
--- a/tests/test-pending.t Thu Oct 18 21:55:47 2018 -0400 +++ b/tests/test-pending.t Wed Oct 17 23:33:43 2018 -0400 @@ -41,8 +41,8 @@ python hook $ cat <<EOF > reject.py - > import os, time - > from mercurial import ui, localrepo + > import os + > import time > def rejecthook(ui, repo, hooktype, node, **opts): > ui.write(b'hook %s\\n' % repo[b'tip'].hex()) > # create the notify file so caller knows we're running
--- a/tests/test-profile.t Thu Oct 18 21:55:47 2018 -0400 +++ b/tests/test-profile.t Wed Oct 17 23:33:43 2018 -0400 @@ -66,7 +66,7 @@ $ cat >> sleepext.py << EOF > import time - > from mercurial import registrar, commands + > from mercurial import registrar > cmdtable = {} > command = registrar.command(cmdtable) > @command(b'sleep', [], b'hg sleep')
--- a/tests/test-purge.t Thu Oct 18 21:55:47 2018 -0400 +++ b/tests/test-purge.t Wed Oct 17 23:33:43 2018 -0400 @@ -50,7 +50,8 @@ $ touch untracked_file $ touch untracked_file_readonly $ "$PYTHON" <<EOF - > import os, stat + > import os + > import stat > f= 'untracked_file_readonly' > os.chmod(f, stat.S_IMODE(os.stat(f).st_mode) & ~stat.S_IWRITE) > EOF