sapling/eden/scm/tests/test-sshserver.py
Jun Wu 3e0b781197 py3: only use binary stdin/stdout/stderr
Summary:
Drop stdoutbytes/stdinbytes. They make things unnecessarily complicated
(especially for chg / Rust dispatch entry point).

The new idea is IO are using bytes. Text are written in utf-8 (Python 3) or
local encoding (Python 2). To make stdout behave reasonably on systems not
using utf-8 locale (ex. Windows), we might add a Rust binding to Rust's stdout,
which does the right thing:
- When writing to stdout console, expect text to be utf-8 encoded and do proper decoding.
- Wehn writing to stdout file, write the raw bytes without translation.

Note Python's `sys.stdout.buffer` does not do translation when writing to stdout console
like Rust's stdout.

For now, my main motivation of this change is to fix chg on Python 3.

Reviewed By: xavierd

Differential Revision: D19702533

fbshipit-source-id: 74704c83e1b200ff66fb3a2d23d97ff21c7239c8
2020-02-03 18:26:57 -08:00

49 lines
1.2 KiB
Python

from __future__ import absolute_import, print_function
import io
import unittest
import silenttestrunner
from edenscm.mercurial import sshserver, wireproto
from hghave import require
class SSHServerGetArgsTests(unittest.TestCase):
def testparseknown(self):
tests = [
(b"* 0\nnodes 0\n", ["", {}]),
(
b"* 0\nnodes 40\n1111111111111111111111111111111111111111\n",
["1111111111111111111111111111111111111111", {}],
),
]
for input, expected in tests:
self.assertparse("known", input, expected)
def assertparse(self, cmd, input, expected):
server = mockserver(input)
_func, spec = wireproto.commands[cmd]
self.assertEqual(server.getargs(spec), expected)
def mockserver(inbytes):
ui = mockui(inbytes)
repo = mockrepo(ui)
return sshserver.sshserver(ui, repo)
class mockrepo(object):
def __init__(self, ui):
self.ui = ui
class mockui(object):
def __init__(self, inbytes):
self.fin = io.BytesIO(inbytes)
self.fout = io.BytesIO()
self.ferr = io.BytesIO()
if __name__ == "__main__":
silenttestrunner.main(__name__)