Mercurial > hg-stable
changeset 28836:3f45488d70df
test-commandserver: handle cStringIO.StringIO/io.StringIO divergence
author | timeless <timeless@mozdev.org> |
---|---|
date | Wed, 06 Apr 2016 20:34:34 +0000 |
parents | 68a946e83188 |
children | d54a7410307f |
files | contrib/hgclient.py tests/test-commandserver.t |
diffstat | 2 files changed, 20 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/contrib/hgclient.py Wed Apr 06 20:31:31 2016 +0000 +++ b/contrib/hgclient.py Wed Apr 06 20:34:34 2016 +0000 @@ -1,7 +1,6 @@ # A minimal client for Mercurial's command server from __future__ import absolute_import, print_function -import cStringIO import os import signal import socket @@ -10,6 +9,13 @@ import sys import time +try: + import cStringIO as io + stringio = io.StringIO +except ImportError: + import io + stringio = io.StringIO + def connectpipe(path=None): cmdline = ['hg', 'serve', '--cmdserver', 'pipe'] if path: @@ -83,7 +89,7 @@ writeblock(server, '\0'.join(args)) if not input: - input = cStringIO.StringIO() + input = stringio() while True: ch, data = readchannel(server)
--- a/tests/test-commandserver.t Wed Apr 06 20:31:31 2016 +0000 +++ b/tests/test-commandserver.t Wed Apr 06 20:34:34 2016 +0000 @@ -102,8 +102,7 @@ ... print 'server exit code =', server.wait() server exit code = 1 - >>> import cStringIO - >>> from hgclient import readchannel, runcommand, check + >>> from hgclient import readchannel, runcommand, check, stringio >>> @check ... def serverinput(server): ... readchannel(server) @@ -123,7 +122,7 @@ ... +1 ... """ ... - ... runcommand(server, ['import', '-'], input=cStringIO.StringIO(patch)) + ... runcommand(server, ['import', '-'], input=stringio(patch)) ... runcommand(server, ['log']) *** runcommand import - applying patch from stdin @@ -211,15 +210,14 @@ > print 'now try to read something: %r' % sys.stdin.read() > EOF - >>> import cStringIO - >>> from hgclient import readchannel, runcommand, check + >>> from hgclient import readchannel, runcommand, check, stringio >>> @check ... def hookoutput(server): ... readchannel(server) ... runcommand(server, ['--config', ... 'hooks.pre-identify=python:hook.hook', ... 'id'], - ... input=cStringIO.StringIO('some input')) + ... input=stringio('some input')) *** runcommand --config hooks.pre-identify=python:hook.hook id hook talking now try to read something: 'some input' @@ -587,17 +585,16 @@ > dbgui = dbgui.py > EOF - >>> import cStringIO - >>> from hgclient import readchannel, runcommand, check + >>> from hgclient import readchannel, runcommand, check, stringio >>> @check ... def getpass(server): ... readchannel(server) ... runcommand(server, ['debuggetpass', '--config', ... 'ui.interactive=True'], - ... input=cStringIO.StringIO('1234\n')) + ... input=stringio('1234\n')) ... runcommand(server, ['debugprompt', '--config', ... 'ui.interactive=True'], - ... input=cStringIO.StringIO('5678\n')) + ... input=stringio('5678\n')) ... runcommand(server, ['debugreadstdin']) ... runcommand(server, ['debugwritestdout']) *** runcommand debuggetpass --config ui.interactive=True @@ -611,14 +608,13 @@ run commandserver in commandserver, which is silly but should work: - >>> import cStringIO - >>> from hgclient import readchannel, runcommand, check + >>> from hgclient import readchannel, runcommand, check, stringio >>> @check ... def nested(server): ... print '%c, %r' % readchannel(server) ... class nestedserver(object): - ... stdin = cStringIO.StringIO('getencoding\n') - ... stdout = cStringIO.StringIO() + ... stdin = stringio('getencoding\n') + ... stdout = stringio() ... runcommand(server, ['serve', '--cmdserver', 'pipe'], ... output=nestedserver.stdout, input=nestedserver.stdin) ... nestedserver.stdout.seek(0) @@ -674,8 +670,7 @@ #if unix-socket unix-permissions - >>> import cStringIO - >>> from hgclient import unixserver, readchannel, runcommand, check + >>> from hgclient import unixserver, readchannel, runcommand, check, stringio >>> server = unixserver('.hg/server.sock', '.hg/server.log') >>> def hellomessage(conn): ... ch, data = readchannel(conn) @@ -704,7 +699,7 @@ ... 1 ... +2 ... """ - ... runcommand(conn, ['import', '-'], input=cStringIO.StringIO(patch)) + ... runcommand(conn, ['import', '-'], input=stringio(patch)) ... runcommand(conn, ['log', '-rtip', '-q']) >>> check(serverinput, server.connect) *** runcommand import -