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

Method test_bytearray_api

Lib/test/test_bytes.py:1321–1345  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1319 self.assertRaises(TypeError, hash, bytearray())
1320
1321 def test_bytearray_api(self):
1322 short_sample = b"Hello world\n"
1323 sample = short_sample + b"\0"*(20 - len(short_sample))
1324 tfn = tempfile.mktemp()
1325 try:
1326 # Prepare
1327 with open(tfn, "wb") as f:
1328 f.write(short_sample)
1329 # Test readinto
1330 with open(tfn, "rb") as f:
1331 b = bytearray(20)
1332 n = f.readinto(b)
1333 self.assertEqual(n, len(short_sample))
1334 self.assertEqual(list(b), list(sample))
1335 # Test writing in binary mode
1336 with open(tfn, "wb") as f:
1337 f.write(b)
1338 with open(tfn, "rb") as f:
1339 self.assertEqual(f.read(), sample)
1340 # Text mode is ambiguous; don't test
1341 finally:
1342 try:
1343 os.remove(tfn)
1344 except OSError:
1345 pass
1346
1347 def test_reverse(self):
1348 b = bytearray(b'hello')

Callers

nothing calls this directly

Calls 9

lenFunction · 0.85
listClass · 0.85
mktempMethod · 0.80
openFunction · 0.50
writeMethod · 0.45
readintoMethod · 0.45
assertEqualMethod · 0.45
readMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected