|
7 | 7 | import httpie |
8 | 8 | import httpie.__main__ |
9 | 9 | from .fixtures import FILE_CONTENT, FILE_PATH |
| 10 | +from httpie.cli.argparser import BaseHTTPieArgumentParser |
10 | 11 | from httpie.cli.exceptions import ParseError |
11 | 12 | from httpie.context import Environment |
12 | 13 | from httpie.encoding import UTF8 |
@@ -50,6 +51,36 @@ def test_help_with_ascii_stdout(): |
50 | 51 | assert 'https://github.com/httpie/cli/issues' in r |
51 | 52 |
|
52 | 53 |
|
| 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 | + |
53 | 84 | def test_version(): |
54 | 85 | r = http('--version', tolerate_error_exit_status=True) |
55 | 86 | assert r.exit_status == ExitStatus.SUCCESS |
|
0 commit comments