changeset 40355:77ab5fbdbbf0

py3: use bprint() helper in test-commandserver.t
author Yuya Nishihara <yuya@tcha.org>
date Tue, 16 Oct 2018 07:38:31 +0200
parents f9f2faf25fc4
children 756e9b1084fd
files tests/test-commandserver.t
diffstat 1 files changed, 28 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/tests/test-commandserver.t	Tue Oct 16 07:35:29 2018 +0200
+++ b/tests/test-commandserver.t	Tue Oct 16 07:38:31 2018 +0200
@@ -13,14 +13,14 @@
   $ hg init repo
   $ cd repo
 
-  >>> from __future__ import absolute_import, print_function
+  >>> from __future__ import absolute_import
   >>> import os
   >>> import sys
-  >>> from hgclient import check, readchannel, runcommand
+  >>> from hgclient import bprint, check, readchannel, runcommand
   >>> @check
   ... def hellomessage(server):
   ...     ch, data = readchannel(server)
-  ...     print(b'%c, %r' % (ch, data))
+  ...     bprint(b'%c, %r' % (ch, data))
   ...     # run an arbitrary command to make sure the next thing the server
   ...     # sends isn't part of the hello message
   ...     runcommand(server, [b'id'])
@@ -93,7 +93,7 @@
   abort: unknown revision 'unknown'!
    [255]
 
-  >>> from hgclient import check, readchannel
+  >>> from hgclient import bprint, check, readchannel
   >>> @check
   ... def inputeof(server):
   ...     readchannel(server)
@@ -102,7 +102,7 @@
   ...     server.stdin.close()
   ... 
   ...     # server exits with 1 if the pipe closed while reading the command
-  ...     print(b'server exit code =', server.wait())
+  ...     bprint(b'server exit code =', b'%d' % server.wait())
   server exit code = 1
 
   >>> from hgclient import check, readchannel, runcommand, stringio
@@ -235,11 +235,11 @@
 #endif
 
   $ cat <<EOF > hook.py
-  > from __future__ import print_function
   > import sys
+  > from hgclient import bprint
   > def hook(**args):
-  >     print(b'hook talking')
-  >     print(b'now try to read something: %r' % sys.stdin.read())
+  >     bprint(b'hook talking')
+  >     bprint(b'now try to read something: %r' % sys.stdin.read())
   > EOF
 
   >>> from hgclient import check, readchannel, runcommand, stringio
@@ -281,7 +281,7 @@
   *** runcommand status
 
   >>> import os
-  >>> from hgclient import check, readchannel, runcommand
+  >>> from hgclient import bprint, check, readchannel, runcommand
   >>> @check
   ... def bookmarks(server):
   ...     readchannel(server)
@@ -302,7 +302,7 @@
   ...     f.close()
   ...     runcommand(server, [b'commit', b'-Amm'])
   ...     runcommand(server, [b'bookmarks'])
-  ...     print(b'')
+  ...     bprint(b'')
   *** runcommand bookmarks
   no bookmarks set
   *** runcommand bookmarks
@@ -346,7 +346,7 @@
   3: public
 
   $ echo a >> a
-  >>> from hgclient import check, readchannel, runcommand
+  >>> from hgclient import bprint, check, readchannel, runcommand
   >>> @check
   ... def rollback(server):
   ...     readchannel(server)
@@ -354,7 +354,7 @@
   ...     runcommand(server, [b'commit', b'-Am.'])
   ...     runcommand(server, [b'rollback'])
   ...     runcommand(server, [b'phase', b'-r', b'.'])
-  ...     print(b'')
+  ...     bprint(b'')
   *** runcommand phase -r . -p
   no phases changed
   *** runcommand commit -Am.
@@ -385,7 +385,7 @@
 
   $ touch .hgignore
   >>> import os
-  >>> from hgclient import check, readchannel, runcommand
+  >>> from hgclient import bprint, check, readchannel, runcommand
   >>> @check
   ... def hgignore(server):
   ...     readchannel(server)
@@ -397,7 +397,7 @@
   ...     f.write(b'ignored-file')
   ...     f.close()
   ...     runcommand(server, [b'status', b'-i', b'-u'])
-  ...     print(b'')
+  ...     bprint(b'')
   *** runcommand commit -Am.
   adding .hgignore
   *** runcommand status -i -u
@@ -408,7 +408,7 @@
 (issue4855):
 
   >>> import os
-  >>> from hgclient import check, readchannel, runcommand
+  >>> from hgclient import bprint, check, readchannel, runcommand
   >>> @check
   ... def phasesetscacheaftercommit(server):
   ...     readchannel(server)
@@ -423,7 +423,7 @@
   ...         os.system('hg commit -Aqm%d' % i)
   ...     # new commits should be listed as draft revisions
   ...     runcommand(server, [b'log', b'-qr', b'draft()'])
-  ...     print(b'')
+  ...     bprint(b'')
   *** runcommand log -qr draft()
   4:7966c8e3734d
   *** runcommand log -qr draft()
@@ -433,7 +433,7 @@
   
 
   >>> import os
-  >>> from hgclient import check, readchannel, runcommand
+  >>> from hgclient import bprint, check, readchannel, runcommand
   >>> @check
   ... def phasesetscacheafterstrip(server):
   ...     readchannel(server)
@@ -443,7 +443,7 @@
   ...     os.system('hg --config extensions.strip= strip -q 5')
   ...     # shouldn't abort by "unknown revision '6'"
   ...     runcommand(server, [b'log', b'-qr', b'draft()'])
-  ...     print(b'')
+  ...     bprint(b'')
   *** runcommand log -qr draft()
   4:7966c8e3734d
   5:41f6602d1c4f
@@ -668,19 +668,18 @@
 
 run commandserver in commandserver, which is silly but should work:
 
-  >>> from __future__ import print_function
-  >>> from hgclient import check, readchannel, runcommand, stringio
+  >>> from hgclient import bprint, check, readchannel, runcommand, stringio
   >>> @check
   ... def nested(server):
-  ...     print(b'%c, %r' % readchannel(server))
+  ...     bprint(b'%c, %r' % readchannel(server))
   ...     class nestedserver(object):
   ...         stdin = stringio(b'getencoding\n')
   ...         stdout = stringio()
   ...     runcommand(server, [b'serve', b'--cmdserver', b'pipe'],
   ...                output=nestedserver.stdout, input=nestedserver.stdin)
   ...     nestedserver.stdout.seek(0)
-  ...     print(b'%c, %r' % readchannel(nestedserver))  # hello
-  ...     print(b'%c, %r' % readchannel(nestedserver))  # getencoding
+  ...     bprint(b'%c, %r' % readchannel(nestedserver))  # hello
+  ...     bprint(b'%c, %r' % readchannel(nestedserver))  # getencoding
   o, 'capabilities: getencoding runcommand\nencoding: *\npid: *' (glob)
   *** runcommand serve --cmdserver pipe
   o, 'capabilities: getencoding runcommand\nencoding: *\npid: *' (glob)
@@ -691,12 +690,11 @@
 
   $ cd ..
 
-  >>> from __future__ import print_function
-  >>> from hgclient import check, readchannel, runcommand
+  >>> from hgclient import bprint, check, readchannel, runcommand
   >>> @check
   ... def hellomessage(server):
   ...     ch, data = readchannel(server)
-  ...     print(b'%c, %r' % (ch, data))
+  ...     bprint(b'%c, %r' % (ch, data))
   ...     # run an arbitrary command to make sure the next thing the server
   ...     # sends isn't part of the hello message
   ...     runcommand(server, [b'id'])
@@ -732,12 +730,11 @@
 
 #if unix-socket unix-permissions
 
-  >>> from __future__ import print_function
-  >>> from hgclient import check, readchannel, runcommand, stringio, unixserver
+  >>> from hgclient import bprint, check, readchannel, runcommand, stringio, unixserver
   >>> server = unixserver(b'.hg/server.sock', b'.hg/server.log')
   >>> def hellomessage(conn):
   ...     ch, data = readchannel(conn)
-  ...     print(b'%c, %r' % (ch, data))
+  ...     bprint(b'%c, %r' % (ch, data))
   ...     runcommand(conn, [b'id'])
   >>> check(hellomessage, server.connect)
   o, 'capabilities: getencoding runcommand\nencoding: *\npid: *' (glob)
@@ -784,15 +781,14 @@
   > [cmdserver]
   > log = inexistent/path.log
   > EOF
-  >>> from __future__ import print_function
-  >>> from hgclient import check, readchannel, unixserver
+  >>> from hgclient import bprint, check, readchannel, unixserver
   >>> server = unixserver(b'.hg/server.sock', b'.hg/server.log')
   >>> def earlycrash(conn):
   ...     while True:
   ...         try:
   ...             ch, data = readchannel(conn)
   ...             if not data.startswith(b'  '):
-  ...                 print(b'%c, %r' % (ch, data))
+  ...                 bprint(b'%c, %r' % (ch, data))
   ...         except EOFError:
   ...             break
   >>> check(earlycrash, server.connect)