MCPcopy Create free account
hub / github.com/e2wugui/zeze / test_bytes

Method test_bytes

python/test/test_buffer.py:27–59  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

25 self.assertEqual(s.upper(), to_string(to_bytes(s)))
26
27 def test_bytes(self):
28 bb = ByteBuffer()
29 v = ByteBuffer.empty
30 bb.write_bytes(v)
31 self.assertEqual(1, bb.size())
32 self.assertEqual("00", bb.__str__())
33 self.assertEqual(to_string(v), to_string(bb.read_bytes()))
34 self.assertEqual(bb.ri, bb.wi)
35
36 v = b"\x01\x02"
37 bb.write_bytes(v)
38 self.assertEqual(3, bb.size())
39 self.assertEqual("02-01-02", bb.__str__())
40 self.assertEqual(to_string(v), to_string(bb.read_bytes()))
41 self.assertEqual(bb.ri, bb.wi)
42
43 s = "abc汉字123"
44 bb.write_string(s)
45 self.assertEqual(13, bb.size())
46 self.assertEqual("0C-61-62-63-E6-B1-89-E5-AD-97-31-32-33", bb.__str__())
47 self.assertEqual(s, bb.read_string())
48 self.assertEqual(bb.ri, bb.wi)
49
50 s = b"\xd9\x55\xde\xaa\xda\xaa\xdd\x55".decode('utf-16-be') # surrogate chars
51 b0 = s.encode('utf-8')
52 bb.reset()
53 bb.write_string(s)
54 self.assertEqual(4 * 2, len(b0))
55 self.assertEqual(4 * 2, ByteBuffer.utf8_size(s))
56 self.assertEqual(4 * 2, bb.buf[0])
57 self.assertEqual(b0, bb.read_bytes())
58 bb.ri = 0
59 self.assertEqual(s, bb.read_string())
60
61 def test_basic(self):
62 bb = ByteBuffer()

Callers

nothing calls this directly

Calls 12

write_bytesMethod · 0.95
sizeMethod · 0.95
__str__Method · 0.95
read_bytesMethod · 0.95
write_stringMethod · 0.95
read_stringMethod · 0.95
resetMethod · 0.95
ByteBufferClass · 0.90
to_stringFunction · 0.85
utf8_sizeMethod · 0.80
decodeMethod · 0.65
encodeMethod · 0.65

Tested by

no test coverage detected