comparison tests/test-sshserver.py @ 35752:047581ddb6ce

sshserver: add a couple of tests for argument parsing I noticed that we didn't have any unit tests covering wire protocol argument parsing.
author Siddharth Agarwal <sid0@fb.com>
date Fri, 19 Jan 2018 14:25:09 -0800
parents
children 7764ff13318e
comparison
equal deleted inserted replaced
35751:6d65cef5b038 35752:047581ddb6ce
1 from __future__ import absolute_import, print_function
2
3 import io
4 import unittest
5
6 import silenttestrunner
7
8 from mercurial import (
9 sshserver,
10 wireproto,
11 )
12
13 class SSHServerGetArgsTests(unittest.TestCase):
14 def testparseknown(self):
15 tests = [
16 ('* 0\nnodes 0\n', ['', {}]),
17 ('* 0\nnodes 40\n1111111111111111111111111111111111111111\n',
18 ['1111111111111111111111111111111111111111', {}]),
19 ]
20 for input, expected in tests:
21 self.assertparse('known', input, expected)
22
23 def assertparse(self, cmd, input, expected):
24 server = mockserver(input)
25 _func, spec = wireproto.commands[cmd]
26 self.assertEqual(server.getargs(spec), expected)
27
28 def mockserver(inbytes):
29 ui = mockui(inbytes)
30 repo = mockrepo(ui)
31 return sshserver.sshserver(ui, repo)
32
33 class mockrepo(object):
34 def __init__(self, ui):
35 self.ui = ui
36
37 class mockui(object):
38 def __init__(self, inbytes):
39 self.fin = io.BytesIO(inbytes)
40 self.fout = io.BytesIO()
41 self.ferr = io.BytesIO()
42
43 if __name__ == '__main__':
44 silenttestrunner.main(__name__)