MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_bytes

Method test_bytes

Lib/test/test_android.py:264–369  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

262 write("\n", [s * 51]) # 0 bytes in, 510 bytes out
263
264 def test_bytes(self):
265 for stream_name, level, fileno in STREAM_INFO:
266 with self.stream_context(stream_name, level):
267 stream = getattr(sys, stream_name).buffer
268 tag = f"python.{stream_name}"
269 self.assertEqual(f"<BinaryLogStream '{tag}'>", repr(stream))
270 self.assertIs(stream.writable(), True)
271 self.assertIs(stream.readable(), False)
272 self.assertEqual(stream.fileno(), fileno)
273
274 def write(b, lines=None, *, write_len=None):
275 if write_len is None:
276 write_len = len(b)
277 self.assertEqual(write_len, stream.write(b))
278 if lines is None:
279 lines = [b.decode()]
280 self.assert_logs(level, tag, lines)
281
282 # Single-line messages,
283 write(b"", [])
284
285 write(b"a")
286 write(b"Hello")
287 write(b"Hello world")
288 write(b" ")
289 write(b" ")
290
291 # Non-ASCII text
292 write(b"ol\xc3\xa9") # Spanish
293 write(b"\xe4\xb8\xad\xe6\x96\x87") # Chinese
294
295 # Non-BMP emoji
296 write(b"\xf0\x9f\x98\x80")
297
298 # Null bytes are logged using "modified UTF-8".
299 write(b"\x00", [r"\xc0\x80"])
300 write(b"a\x00", [r"a\xc0\x80"])
301 write(b"\x00b", [r"\xc0\x80b"])
302 write(b"a\x00b", [r"a\xc0\x80b"])
303
304 # Invalid UTF-8
305 write(b"\xff", [r"\xff"])
306 write(b"a\xff", [r"a\xff"])
307 write(b"\xffb", [r"\xffb"])
308 write(b"a\xffb", [r"a\xffb"])
309
310 # Log entries containing newlines are shown differently by
311 # `logcat -v tag`, `logcat -v long`, and Android Studio. We
312 # currently use `logcat -v tag`, which shows each line as if it
313 # was a separate log entry, but strips a single trailing
314 # newline.
315 #
316 # On newer versions of Android, all three of the above tools (or
317 # maybe Logcat itself) will also strip any number of leading
318 # newlines.
319 write(b"\nx", ["", "x"] if api_level < 30 else ["x"])
320 write(b"\na\n", ["", "a"] if api_level < 30 else ["a"])
321 write(b"\n", [""])

Callers

nothing calls this directly

Calls 13

stream_contextMethod · 0.95
getattrFunction · 0.85
reprFunction · 0.85
arrayClass · 0.85
subTestMethod · 0.80
assertRaisesRegexMethod · 0.80
writeFunction · 0.50
assertEqualMethod · 0.45
assertIsMethod · 0.45
writableMethod · 0.45
readableMethod · 0.45
filenoMethod · 0.45

Tested by

no test coverage detected