tests: port test-wireproto.py to Python 3
authorAugie Fackler <augie@google.com>
Fri, 27 Apr 2018 11:55:04 -0400
changeset 37923 40381a88bab4
parent 37922 0d95ad9fc5f4
child 37924 32106c474086
tests: port test-wireproto.py to Python 3 A little bit of output churn because we now get b'' prefixes on output in both 2 and 3, but for this test I'm more comfortable knowing that we're using bytestrs everywhere. Differential Revision: https://phab.mercurial-scm.org/D3510
contrib/python3-whitelist
tests/test-wireproto.py
tests/test-wireproto.py.out
--- a/contrib/python3-whitelist	Fri Apr 27 11:50:24 2018 -0400
+++ b/contrib/python3-whitelist	Fri Apr 27 11:55:04 2018 -0400
@@ -471,5 +471,6 @@
 test-wireproto-clientreactor.py
 test-wireproto-framing.py
 test-wireproto-serverreactor.py
+test-wireproto.py
 test-wsgirequest.py
 test-xdg.t
--- a/tests/test-wireproto.py	Fri Apr 27 11:50:24 2018 -0400
+++ b/tests/test-wireproto.py	Fri Apr 27 11:55:04 2018 -0400
@@ -1,5 +1,7 @@
 from __future__ import absolute_import, print_function
 
+import sys
+
 from mercurial import (
     error,
     pycompat,
@@ -9,6 +11,9 @@
     wireprotov1peer,
     wireprotov1server,
 )
+from mercurial.utils import (
+    stringutil,
+)
 stringio = util.stringio
 
 class proto(object):
@@ -92,10 +97,15 @@
 srv = serverrepo()
 clt = clientpeer(srv, uimod.ui())
 
-print(clt.greet(b"Foobar"))
+def printb(data, end=b'\n'):
+    out = getattr(sys.stdout, 'buffer', sys.stdout)
+    out.write(data + end)
+    out.flush()
+
+printb(clt.greet(b"Foobar"))
 
 with clt.commandexecutor() as e:
     fgreet1 = e.callcommand(b'greet', {b'name': b'Fo, =;:<o'})
     fgreet2 = e.callcommand(b'greet', {b'name': b'Bar'})
 
-print([f.result() for f in (fgreet1, fgreet2)])
+printb(stringutil.pprint([f.result() for f in (fgreet1, fgreet2)]))
--- a/tests/test-wireproto.py.out	Fri Apr 27 11:50:24 2018 -0400
+++ b/tests/test-wireproto.py.out	Fri Apr 27 11:55:04 2018 -0400
@@ -1,2 +1,2 @@
 Hello, Foobar
-['Hello, Fo, =;:<o', 'Hello, Bar']
+[b'Hello, Fo, =;:<o', b'Hello, Bar']