Skip to content

Commit c58ccb0

Browse files
author
Deepak kudi
committed
test: cover ASCII help output fallback
1 parent 7b8d933 commit c58ccb0

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

tests/test_httpie.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import httpie
88
import httpie.__main__
99
from .fixtures import FILE_CONTENT, FILE_PATH
10+
from httpie.cli.argparser import BaseHTTPieArgumentParser
1011
from httpie.cli.exceptions import ParseError
1112
from httpie.context import Environment
1213
from httpie.encoding import UTF8
@@ -50,6 +51,36 @@ def test_help_with_ascii_stdout():
5051
assert 'https://github.com/httpie/cli/issues' in r
5152

5253

54+
def test_help_message_encodes_binary_stream_without_buffer():
55+
output = io.BytesIO()
56+
parser = BaseHTTPieArgumentParser()
57+
parser.env = MockEnvironment(stdout_encoding='ascii')
58+
59+
parser._print_message('\u00e9', output)
60+
61+
assert output.getvalue() == b'\\xe9'
62+
63+
64+
def test_help_message_reraises_non_text_unicode_errors():
65+
class UnicodeErrorStream:
66+
encoding = 'ascii'
67+
68+
def write(self, message):
69+
raise UnicodeEncodeError(
70+
'ascii',
71+
'\u00e9',
72+
0,
73+
1,
74+
'ordinal not in range',
75+
)
76+
77+
parser = BaseHTTPieArgumentParser()
78+
parser.env = MockEnvironment()
79+
80+
with pytest.raises(UnicodeEncodeError):
81+
parser._print_message(b'help', UnicodeErrorStream())
82+
83+
5384
def test_version():
5485
r = http('--version', tolerate_error_exit_status=True)
5586
assert r.exit_status == ExitStatus.SUCCESS

0 commit comments

Comments
 (0)