D2534: py3: port tests/test-wireproto.py to Python 3

pulkit (Pulkit Goyal) phabricator at mercurial-scm.org
Thu Mar 1 20:13:06 EST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rHGb5821f9745ca: py3: port tests/test-wireproto.py to Python 3 (authored by pulkit, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2534?vs=6313&id=6315

REVISION DETAIL
  https://phab.mercurial-scm.org/D2534

AFFECTED FILES
  tests/test-wireproto.py

CHANGE DETAILS

diff --git a/tests/test-wireproto.py b/tests/test-wireproto.py
--- a/tests/test-wireproto.py
+++ b/tests/test-wireproto.py
@@ -2,6 +2,7 @@
 
 from mercurial import (
     error,
+    pycompat,
     util,
     wireproto,
     wireprototypes,
@@ -13,7 +14,7 @@
         self.args = args
     def getargs(self, spec):
         args = self.args
-        args.setdefault('*', {})
+        args.setdefault(b'*', {})
         names = spec.split()
         return [args[n] for n in names]
 
@@ -26,7 +27,7 @@
         return self.serverrepo.ui
 
     def url(self):
-        return 'test'
+        return b'test'
 
     def local(self):
         return None
@@ -41,9 +42,10 @@
         pass
 
     def capabilities(self):
-        return ['batch']
+        return [b'batch']
 
     def _call(self, cmd, **args):
+        args = pycompat.byteskwargs(args)
         res = wireproto.dispatch(self.serverrepo, proto(args), cmd)
         if isinstance(res, wireprototypes.bytesresponse):
             return res.data
@@ -58,31 +60,31 @@
     @wireproto.batchable
     def greet(self, name):
         f = wireproto.future()
-        yield {'name': mangle(name)}, f
+        yield {b'name': mangle(name)}, f
         yield unmangle(f.value)
 
 class serverrepo(object):
     def greet(self, name):
-        return "Hello, " + name
+        return b"Hello, " + name
 
     def filtered(self, name):
         return self
 
 def mangle(s):
-    return ''.join(chr(ord(c) + 1) for c in s)
+    return b''.join(pycompat.bytechr(ord(c) + 1) for c in pycompat.bytestr(s))
 def unmangle(s):
-    return ''.join(chr(ord(c) - 1) for c in s)
+    return b''.join(pycompat.bytechr(ord(c) - 1) for c in pycompat.bytestr(s))
 
 def greet(repo, proto, name):
     return mangle(repo.greet(unmangle(name)))
 
-wireproto.commands['greet'] = (greet, 'name',)
+wireproto.commands[b'greet'] = (greet, b'name',)
 
 srv = serverrepo()
 clt = clientpeer(srv)
 
-print(clt.greet("Foobar"))
+print(clt.greet(b"Foobar"))
 b = clt.iterbatch()
-map(b.greet, ('Fo, =;:<o', 'Bar'))
+list(map(b.greet, (b'Fo, =;:<o', b'Bar')))
 b.submit()
 print([r for r in b.results()])



To: pulkit, #hg-reviewers, durin42
Cc: mercurial-devel


More information about the Mercurial-devel mailing list