| 1 |
import io |
| 2 |
import unittest |
| 3 |
|
| 4 |
import silenttestrunner |
| 5 |
|
| 6 |
from mercurial import ( |
| 7 |
wireprotoserver, |
| 8 |
wireprotov1server, |
| 9 |
) |
| 10 |
|
| 11 |
from mercurial.utils import procutil |
| 12 |
|
| 13 |
|
| 14 |
class SSHServerGetArgsTests(unittest.TestCase): |
| 15 |
def testparseknown(self): |
| 16 |
tests = [ |
| 17 |
(b'* 0\nnodes 0\n', [b'', {}]), |
| 18 |
( |
| 19 |
b'* 0\nnodes 40\n1111111111111111111111111111111111111111\n', |
| 20 |
[b'1111111111111111111111111111111111111111', {}], |
| 21 |
), |
| 22 |
] |
| 23 |
for input, expected in tests: |
| 24 |
self.assertparse(b'known', input, expected) |
| 25 |
|
| 26 |
def assertparse(self, cmd, input, expected): |
| 27 |
server = mockserver(input) |
| 28 |
ui = server._ui |
| 29 |
proto = wireprotoserver.sshv1protocolhandler(ui, ui.fin, ui.fout) |
| 30 |
_func, spec = wireprotov1server.commands[cmd] |
| 31 |
self.assertEqual(proto.getargs(spec), expected) |
| 32 |
|
| 33 |
|
| 34 |
def mockserver(inbytes): |
| 35 |
ui = mockui(inbytes) |
| 36 |
repo = mockrepo(ui) |
| 37 |
# note: this test unfortunately doesn't really test anything about |
| 38 |
# `sshserver` class anymore: the entirety of logic of that class lives |
| 39 |
# in `serveuntil`, and that function is not even called by this test. |
| 40 |
return wireprotoserver.sshserver(ui, repo) |
| 41 |
|
| 42 |
|
| 43 |
class mockrepo: |
| 44 |
def __init__(self, ui): |
| 45 |
self.ui = ui |
| 46 |
|
| 47 |
|
| 48 |
class mockui: |
| 49 |
def __init__(self, inbytes): |
| 50 |
self.fin = io.BytesIO(inbytes) |
| 51 |
self.fout = io.BytesIO() |
| 52 |
self.ferr = io.BytesIO() |
| 53 |
|
| 54 |
def protectfinout(self): |
| 55 |
return self.fin, self.fout |
| 56 |
|
| 57 |
def restorefinout(self, fin, fout): |
| 58 |
pass |
| 59 |
|
| 60 |
|
| 61 |
if __name__ == '__main__': |
| 62 |
# Don't call into msvcrt to set BytesIO to binary mode |
| 63 |
procutil.setbinary = lambda fp: True |
| 64 |
silenttestrunner.main(__name__) |