8 from mercurial import ( |
8 from mercurial import ( |
9 wireprotoserver, |
9 wireprotoserver, |
10 wireprotov1server, |
10 wireprotov1server, |
11 ) |
11 ) |
12 |
12 |
13 from mercurial.utils import ( |
13 from mercurial.utils import procutil |
14 procutil, |
14 |
15 ) |
|
16 |
15 |
17 class SSHServerGetArgsTests(unittest.TestCase): |
16 class SSHServerGetArgsTests(unittest.TestCase): |
18 def testparseknown(self): |
17 def testparseknown(self): |
19 tests = [ |
18 tests = [ |
20 (b'* 0\nnodes 0\n', [b'', {}]), |
19 (b'* 0\nnodes 0\n', [b'', {}]), |
21 (b'* 0\nnodes 40\n1111111111111111111111111111111111111111\n', |
20 ( |
22 [b'1111111111111111111111111111111111111111', {}]), |
21 b'* 0\nnodes 40\n1111111111111111111111111111111111111111\n', |
|
22 [b'1111111111111111111111111111111111111111', {}], |
|
23 ), |
23 ] |
24 ] |
24 for input, expected in tests: |
25 for input, expected in tests: |
25 self.assertparse(b'known', input, expected) |
26 self.assertparse(b'known', input, expected) |
26 |
27 |
27 def assertparse(self, cmd, input, expected): |
28 def assertparse(self, cmd, input, expected): |
28 server = mockserver(input) |
29 server = mockserver(input) |
29 proto = wireprotoserver.sshv1protocolhandler(server._ui, |
30 proto = wireprotoserver.sshv1protocolhandler( |
30 server._fin, |
31 server._ui, server._fin, server._fout |
31 server._fout) |
32 ) |
32 _func, spec = wireprotov1server.commands[cmd] |
33 _func, spec = wireprotov1server.commands[cmd] |
33 self.assertEqual(proto.getargs(spec), expected) |
34 self.assertEqual(proto.getargs(spec), expected) |
|
35 |
34 |
36 |
35 def mockserver(inbytes): |
37 def mockserver(inbytes): |
36 ui = mockui(inbytes) |
38 ui = mockui(inbytes) |
37 repo = mockrepo(ui) |
39 repo = mockrepo(ui) |
38 return wireprotoserver.sshserver(ui, repo) |
40 return wireprotoserver.sshserver(ui, repo) |
39 |
41 |
|
42 |
40 class mockrepo(object): |
43 class mockrepo(object): |
41 def __init__(self, ui): |
44 def __init__(self, ui): |
42 self.ui = ui |
45 self.ui = ui |
|
46 |
43 |
47 |
44 class mockui(object): |
48 class mockui(object): |
45 def __init__(self, inbytes): |
49 def __init__(self, inbytes): |
46 self.fin = io.BytesIO(inbytes) |
50 self.fin = io.BytesIO(inbytes) |
47 self.fout = io.BytesIO() |
51 self.fout = io.BytesIO() |
51 return self.fin, self.fout |
55 return self.fin, self.fout |
52 |
56 |
53 def restorefinout(self, fin, fout): |
57 def restorefinout(self, fin, fout): |
54 pass |
58 pass |
55 |
59 |
|
60 |
56 if __name__ == '__main__': |
61 if __name__ == '__main__': |
57 # Don't call into msvcrt to set BytesIO to binary mode |
62 # Don't call into msvcrt to set BytesIO to binary mode |
58 procutil.setbinary = lambda fp: True |
63 procutil.setbinary = lambda fp: True |
59 silenttestrunner.main(__name__) |
64 silenttestrunner.main(__name__) |