diff tests/test-wireproto.py @ 36112:2f7290555c96

wireproto: introduce type for raw byte responses (API) Right now we simply return a str/bytes instance for simple responses. I want all wire protocol response types to be strongly typed. So let's invent and use a type for raw bytes responses. .. api:: Wire protocol command handlers now return a wireprototypes.bytesresponse instead of a raw bytes instance. Protocol handlers will continue handling bytes instances. However, any extensions wrapping wire protocol commands will need to handle the new type. Differential Revision: https://phab.mercurial-scm.org/D2089
author Gregory Szorc <gregory.szorc@gmail.com>
date Wed, 07 Feb 2018 20:27:36 -0800
parents dedab036215d
children c28de190e20a
line wrap: on
line diff
--- a/tests/test-wireproto.py	Wed Feb 07 16:29:05 2018 -0800
+++ b/tests/test-wireproto.py	Wed Feb 07 20:27:36 2018 -0800
@@ -1,8 +1,10 @@
 from __future__ import absolute_import, print_function
 
 from mercurial import (
+    error,
     util,
     wireproto,
+    wireprototypes,
 )
 stringio = util.stringio
 
@@ -42,7 +44,13 @@
         return ['batch']
 
     def _call(self, cmd, **args):
-        return wireproto.dispatch(self.serverrepo, proto(args), cmd)
+        res = wireproto.dispatch(self.serverrepo, proto(args), cmd)
+        if isinstance(res, wireprototypes.bytesresponse):
+            return res.data
+        elif isinstance(res, bytes):
+            return res
+        else:
+            raise error.Abort('dummy client does not support response type')
 
     def _callstream(self, cmd, **args):
         return stringio(self._call(cmd, **args))