Patchwork [1,of,3] py3: fix module imports in tests, as flagged by test-check-module-imports.t

login
register
mail settings
Submitter Matt Harbison
Date Oct. 18, 2018, 10:14 p.m.
Message ID <b8adc6cf0c130b1bc418.1539900897@mharbison-pc.attotech.com>
Download mbox | patch
Permalink /patch/36159/
State Accepted
Headers show

Comments

Matt Harbison - Oct. 18, 2018, 10:14 p.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1539833623 14400
#      Wed Oct 17 23:33:43 2018 -0400
# Node ID b8adc6cf0c130b1bc4183df9b4b3363ae94aa3f1
# Parent  13885aa723e6d83cd9a873cf861ef92377a2dfde
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:
Yuya Nishihara - Oct. 19, 2018, 12:39 p.m.
On Thu, 18 Oct 2018 18:14:57 -0400, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1539833623 14400
> #      Wed Oct 17 23:33:43 2018 -0400
> # Node ID b8adc6cf0c130b1bc4183df9b4b3363ae94aa3f1
> # Parent  13885aa723e6d83cd9a873cf861ef92377a2dfde
> py3: fix module imports in tests, as flagged by test-check-module-imports.t

Looks good for slipping into the rc. Queued, thanks.

Patch

diff --git a/tests/test-basic.t b/tests/test-basic.t
--- a/tests/test-basic.t
+++ b/tests/test-basic.t
@@ -61,8 +61,8 @@  This command is ancient:
 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
diff --git a/tests/test-blackbox.t b/tests/test-blackbox.t
--- a/tests/test-blackbox.t
+++ b/tests/test-blackbox.t
@@ -351,7 +351,8 @@  when using chg, blackbox.log should get 
   $ 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
diff --git a/tests/test-bundle2-exchange.t b/tests/test-bundle2-exchange.t
--- a/tests/test-bundle2-exchange.t
+++ b/tests/test-bundle2-exchange.t
@@ -934,7 +934,7 @@  Test lazily acquiring the lock during un
 
   $ 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")
diff --git a/tests/test-clone.t b/tests/test-clone.t
--- a/tests/test-clone.t
+++ b/tests/test-clone.t
@@ -558,8 +558,8 @@  Issue2267: Error in 1.6 hg.py: TypeError
 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 @@  iterable in addbranchrevs()
   $ 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",])
diff --git a/tests/test-commit-multiple.t b/tests/test-commit-multiple.t
--- a/tests/test-commit-multiple.t
+++ b/tests/test-commit-multiple.t
@@ -80,8 +80,8 @@  transplant bug fixes onto release branch
 
 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 @@  now test that we fixed the bug for all s
   >                    % (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()
diff --git a/tests/test-devel-warnings.t b/tests/test-devel-warnings.t
--- a/tests/test-devel-warnings.t
+++ b/tests/test-devel-warnings.t
@@ -342,7 +342,7 @@  Test warning on config option access and
   $ 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)
diff --git a/tests/test-encoding.t b/tests/test-encoding.t
--- a/tests/test-encoding.t
+++ b/tests/test-encoding.t
@@ -278,9 +278,10 @@  Test roundtrip encoding/decoding of utf8
 
 #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
diff --git a/tests/test-extension.t b/tests/test-extension.t
--- a/tests/test-extension.t
+++ b/tests/test-extension.t
@@ -1266,7 +1266,8 @@  Broken disabled extension and command:
   > "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`
diff --git a/tests/test-import.t b/tests/test-import.t
--- a/tests/test-import.t
+++ b/tests/test-import.t
@@ -285,7 +285,8 @@  override commit message
   $ 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 @@  subject: duplicate detection, removal of
 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 @@  Importing some extra header
 ===========================
 
   $ 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:
diff --git a/tests/test-install.t b/tests/test-install.t
--- a/tests/test-install.t
+++ b/tests/test-install.t
@@ -153,7 +153,9 @@  not found (this is intentionally using b
   $ . "$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
diff --git a/tests/test-issue5979.t b/tests/test-issue5979.t
--- a/tests/test-issue5979.t
+++ b/tests/test-issue5979.t
@@ -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
diff --git a/tests/test-journal.t b/tests/test-journal.t
--- a/tests/test-journal.t
+++ b/tests/test-journal.t
@@ -3,7 +3,7 @@  Tests for the journal extension; records
   $ 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'
diff --git a/tests/test-pager-legacy.t b/tests/test-pager-legacy.t
--- a/tests/test-pager-legacy.t
+++ b/tests/test-pager-legacy.t
@@ -244,7 +244,7 @@  pager is globally set to off using a fla
 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)
diff --git a/tests/test-parseindex.t b/tests/test-parseindex.t
--- a/tests/test-parseindex.t
+++ b/tests/test-parseindex.t
@@ -27,8 +27,7 @@  We approximate that by reducing the read
   
   $ 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 @@  We approximate that by reducing the read
   > 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:
diff --git a/tests/test-pending.t b/tests/test-pending.t
--- a/tests/test-pending.t
+++ b/tests/test-pending.t
@@ -41,8 +41,8 @@  utility to run the test - start a push i
 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
diff --git a/tests/test-profile.t b/tests/test-profile.t
--- a/tests/test-profile.t
+++ b/tests/test-profile.t
@@ -66,7 +66,7 @@  Install an extension that can sleep and 
 
   $ 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')
diff --git a/tests/test-purge.t b/tests/test-purge.t
--- a/tests/test-purge.t
+++ b/tests/test-purge.t
@@ -50,7 +50,8 @@  delete an untracked file
   $ 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