##// END OF EJS Templates
tests: fix test-wireproto.py to work around serverrepo() not having a ui...
Augie Fackler -
r36962:65615c29 default
parent child Browse files
Show More
@@ -1,93 +1,95
1 1 from __future__ import absolute_import, print_function
2 2
3 3 from mercurial import (
4 4 error,
5 5 pycompat,
6 ui as uimod,
6 7 util,
7 8 wireproto,
8 9 wireprototypes,
9 10 )
10 11 stringio = util.stringio
11 12
12 13 class proto(object):
13 14 def __init__(self, args):
14 15 self.args = args
15 16 def getargs(self, spec):
16 17 args = self.args
17 18 args.setdefault(b'*', {})
18 19 names = spec.split()
19 20 return [args[n] for n in names]
20 21
21 22 def checkperm(self, perm):
22 23 pass
23 24
24 25 class clientpeer(wireproto.wirepeer):
25 def __init__(self, serverrepo):
26 def __init__(self, serverrepo, ui):
26 27 self.serverrepo = serverrepo
28 self._ui = ui
27 29
28 30 @property
29 31 def ui(self):
30 return self.serverrepo.ui
32 return self._ui
31 33
32 34 def url(self):
33 35 return b'test'
34 36
35 37 def local(self):
36 38 return None
37 39
38 40 def peer(self):
39 41 return self
40 42
41 43 def canpush(self):
42 44 return True
43 45
44 46 def close(self):
45 47 pass
46 48
47 49 def capabilities(self):
48 50 return [b'batch']
49 51
50 52 def _call(self, cmd, **args):
51 53 args = pycompat.byteskwargs(args)
52 54 res = wireproto.dispatch(self.serverrepo, proto(args), cmd)
53 55 if isinstance(res, wireprototypes.bytesresponse):
54 56 return res.data
55 57 elif isinstance(res, bytes):
56 58 return res
57 59 else:
58 60 raise error.Abort('dummy client does not support response type')
59 61
60 62 def _callstream(self, cmd, **args):
61 63 return stringio(self._call(cmd, **args))
62 64
63 65 @wireproto.batchable
64 66 def greet(self, name):
65 67 f = wireproto.future()
66 68 yield {b'name': mangle(name)}, f
67 69 yield unmangle(f.value)
68 70
69 71 class serverrepo(object):
70 72 def greet(self, name):
71 73 return b"Hello, " + name
72 74
73 75 def filtered(self, name):
74 76 return self
75 77
76 78 def mangle(s):
77 79 return b''.join(pycompat.bytechr(ord(c) + 1) for c in pycompat.bytestr(s))
78 80 def unmangle(s):
79 81 return b''.join(pycompat.bytechr(ord(c) - 1) for c in pycompat.bytestr(s))
80 82
81 83 def greet(repo, proto, name):
82 84 return mangle(repo.greet(unmangle(name)))
83 85
84 86 wireproto.commands[b'greet'] = (greet, b'name',)
85 87
86 88 srv = serverrepo()
87 clt = clientpeer(srv)
89 clt = clientpeer(srv, uimod.ui())
88 90
89 91 print(clt.greet(b"Foobar"))
90 92 b = clt.iterbatch()
91 93 list(map(b.greet, (b'Fo, =;:<o', b'Bar')))
92 94 b.submit()
93 95 print([r for r in b.results()])
General Comments 0
You need to be logged in to leave comments. Login now