(self)
| 277 | write("\n", [s * 51]) # 0 bytes in, 510 bytes out |
| 278 | |
| 279 | def test_bytes(self): |
| 280 | for stream_name, level, fileno in STREAM_INFO: |
| 281 | with self.stream_context(stream_name, level): |
| 282 | stream = getattr(sys, stream_name).buffer |
| 283 | tag = f"python.{stream_name}" |
| 284 | self.assertEqual(f"<BinaryLogStream '{tag}'>", repr(stream)) |
| 285 | self.assertIs(stream.writable(), True) |
| 286 | self.assertIs(stream.readable(), False) |
| 287 | self.assertEqual(stream.fileno(), fileno) |
| 288 | |
| 289 | def write(b, lines=None, *, write_len=None): |
| 290 | if write_len is None: |
| 291 | write_len = len(b) |
| 292 | self.assertEqual(write_len, stream.write(b)) |
| 293 | if lines is None: |
| 294 | lines = [b.decode()] |
| 295 | self.assert_logs(level, tag, lines) |
| 296 | |
| 297 | # Single-line messages, |
| 298 | write(b"", []) |
| 299 | |
| 300 | write(b"a") |
| 301 | write(b"Hello") |
| 302 | write(b"Hello world") |
| 303 | write(b" ") |
| 304 | write(b" ") |
| 305 | |
| 306 | # Non-ASCII text |
| 307 | write(b"ol\xc3\xa9") # Spanish |
| 308 | write(b"\xe4\xb8\xad\xe6\x96\x87") # Chinese |
| 309 | |
| 310 | # Non-BMP emoji |
| 311 | write(b"\xf0\x9f\x98\x80") |
| 312 | |
| 313 | # Null bytes are logged using "modified UTF-8". |
| 314 | write(b"\x00", [r"\xc0\x80"]) |
| 315 | write(b"a\x00", [r"a\xc0\x80"]) |
| 316 | write(b"\x00b", [r"\xc0\x80b"]) |
| 317 | write(b"a\x00b", [r"a\xc0\x80b"]) |
| 318 | |
| 319 | # Invalid UTF-8 |
| 320 | write(b"\xff", [r"\xff"]) |
| 321 | write(b"a\xff", [r"a\xff"]) |
| 322 | write(b"\xffb", [r"\xffb"]) |
| 323 | write(b"a\xffb", [r"a\xffb"]) |
| 324 | |
| 325 | # Log entries containing newlines are shown differently by |
| 326 | # `logcat -v tag`, `logcat -v long`, and Android Studio. We |
| 327 | # currently use `logcat -v tag`, which shows each line as if it |
| 328 | # was a separate log entry, but strips a single trailing |
| 329 | # newline. |
| 330 | write(b"\nx", [" ", "x"]) |
| 331 | write(b"\na\n", [" ", "a"]) |
| 332 | write(b"\n", [" "]) |
| 333 | write(b"\n\n", [" ", ""]) |
| 334 | write(b"b\n", ["b"]) |
| 335 | write(b"c\n\n", ["c", ""]) |
| 336 | write(b"d\ne", ["d", "e"]) |
nothing calls this directly
no test coverage detected