Mercurial > hg
annotate tests/test-sshserver.py @ 44984:bfef35bb4ecb
absorb: preserve branch-closing changesets even if empty
This makes the behavior consistent with 'hg commit', which allows to create
otherwise empty changesets if they close the branch. A lost branch closure can
inadvertently re-open a branch, so it should be preserved.
author | Manuel Jacob <me@manueljacob.de> |
---|---|
date | Mon, 01 Jun 2020 11:07:33 +0200 |
parents | 2372284d9457 |
children | 6000f5b25c9b |
rev | line source |
---|---|
35752
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
1 from __future__ import absolute_import, print_function |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
2 |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
3 import io |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
4 import unittest |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
5 |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
6 import silenttestrunner |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
7 |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
8 from mercurial import ( |
35859
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35772
diff
changeset
|
9 wireprotoserver, |
37785
b4d85bc122bd
wireproto: rename wireproto to wireprotov1server (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37120
diff
changeset
|
10 wireprotov1server, |
35752
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
11 ) |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
12 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41285
diff
changeset
|
13 from mercurial.utils import procutil |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41285
diff
changeset
|
14 |
37120
a8a902d7176e
procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36214
diff
changeset
|
15 |
35752
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
16 class SSHServerGetArgsTests(unittest.TestCase): |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
17 def testparseknown(self): |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
18 tests = [ |
36212
7a46f0735904
py3: add b'' to test-sshserver.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36065
diff
changeset
|
19 (b'* 0\nnodes 0\n', [b'', {}]), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41285
diff
changeset
|
20 ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41285
diff
changeset
|
21 b'* 0\nnodes 40\n1111111111111111111111111111111111111111\n', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41285
diff
changeset
|
22 [b'1111111111111111111111111111111111111111', {}], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41285
diff
changeset
|
23 ), |
35752
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
24 ] |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
25 for input, expected in tests: |
36212
7a46f0735904
py3: add b'' to test-sshserver.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36065
diff
changeset
|
26 self.assertparse(b'known', input, expected) |
35752
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
27 |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
28 def assertparse(self, cmd, input, expected): |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
29 server = mockserver(input) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41285
diff
changeset
|
30 proto = wireprotoserver.sshv1protocolhandler( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41285
diff
changeset
|
31 server._ui, server._fin, server._fout |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41285
diff
changeset
|
32 ) |
37785
b4d85bc122bd
wireproto: rename wireproto to wireprotov1server (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37120
diff
changeset
|
33 _func, spec = wireprotov1server.commands[cmd] |
36214
3b3a987bbbaa
wireprotoserver: move SSH server operation to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36212
diff
changeset
|
34 self.assertEqual(proto.getargs(spec), expected) |
35752
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
35 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41285
diff
changeset
|
36 |
35752
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
37 def mockserver(inbytes): |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
38 ui = mockui(inbytes) |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
39 repo = mockrepo(ui) |
35859
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35772
diff
changeset
|
40 return wireprotoserver.sshserver(ui, repo) |
35752
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
41 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41285
diff
changeset
|
42 |
35752
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
43 class mockrepo(object): |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
44 def __init__(self, ui): |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
45 self.ui = ui |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
46 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41285
diff
changeset
|
47 |
35752
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
48 class mockui(object): |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
49 def __init__(self, inbytes): |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
50 self.fin = io.BytesIO(inbytes) |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
51 self.fout = io.BytesIO() |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
52 self.ferr = io.BytesIO() |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
53 |
41285
cf8677cd7286
ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents:
37785
diff
changeset
|
54 def protectfinout(self): |
cf8677cd7286
ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents:
37785
diff
changeset
|
55 return self.fin, self.fout |
cf8677cd7286
ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents:
37785
diff
changeset
|
56 |
cf8677cd7286
ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents:
37785
diff
changeset
|
57 def restorefinout(self, fin, fout): |
cf8677cd7286
ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents:
37785
diff
changeset
|
58 pass |
cf8677cd7286
ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents:
37785
diff
changeset
|
59 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41285
diff
changeset
|
60 |
35752
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
61 if __name__ == '__main__': |
35772
7764ff13318e
test-sshserver: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
35752
diff
changeset
|
62 # Don't call into msvcrt to set BytesIO to binary mode |
37120
a8a902d7176e
procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36214
diff
changeset
|
63 procutil.setbinary = lambda fp: True |
35752
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
64 silenttestrunner.main(__name__) |