MCPcopy Index your code
hub / github.com/python/cpython / test_train_buffer_protocol_samples

Method test_train_buffer_protocol_samples

Lib/test/test_zstd.py:1453–1486  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1451 _zstd.finalize_dict(TRAINED_DICT.dict_content, b'', (), 100, 5)
1452
1453 def test_train_buffer_protocol_samples(self):
1454 def _nbytes(dat):
1455 if isinstance(dat, (bytes, bytearray)):
1456 return len(dat)
1457 return memoryview(dat).nbytes
1458
1459 # prepare samples
1460 chunk_lst = []
1461 wrong_size_lst = []
1462 correct_size_lst = []
1463 for _ in range(300):
1464 arr = array.array('Q', [random.randint(0, 20) for i in range(20)])
1465 chunk_lst.append(arr)
1466 correct_size_lst.append(_nbytes(arr))
1467 wrong_size_lst.append(len(arr))
1468 concatenation = b''.join(chunk_lst)
1469
1470 # wrong size list
1471 with self.assertRaisesRegex(ValueError,
1472 "The samples size tuple doesn't match the concatenation's size"):
1473 _zstd.train_dict(concatenation, tuple(wrong_size_lst), 100*_1K)
1474
1475 # correct size list
1476 _zstd.train_dict(concatenation, tuple(correct_size_lst), 3*_1K)
1477
1478 # wrong size list
1479 with self.assertRaisesRegex(ValueError,
1480 "The samples size tuple doesn't match the concatenation's size"):
1481 _zstd.finalize_dict(TRAINED_DICT.dict_content,
1482 concatenation, tuple(wrong_size_lst), 300*_1K, 5)
1483
1484 # correct size list
1485 _zstd.finalize_dict(TRAINED_DICT.dict_content,
1486 concatenation, tuple(correct_size_lst), 300*_1K, 5)
1487
1488 def test_as_prefix(self):
1489 # V1

Callers

nothing calls this directly

Calls 5

_nbytesFunction · 0.85
randintMethod · 0.80
assertRaisesRegexMethod · 0.80
appendMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected