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

Class TestSuite

Tools/picklebench/memory_dos_impact.py:429–502  ·  view source on GitHub ↗

Manage a suite of benchmark tests.

Source from the content-addressed store, hash-verified

427
428
429class TestSuite:
430 """Manage a suite of benchmark tests."""
431
432 def __init__(self, sizes: List[int], protocol: int = 5, iterations: int = 3):
433 self.sizes = sizes
434 self.protocol = protocol
435 self.iterations = iterations
436 self.results = {}
437
438 def run_test(self, name: str, obj: Any) -> Dict[str, Any]:
439 """Run benchmark for a single test object."""
440 bench = PickleBenchmark(obj, self.protocol, self.iterations)
441 results = bench.run_all()
442 results['test_name'] = name
443 results['object_type'] = type(obj).__name__
444 return results
445
446 def run_all_tests(self) -> Dict[str, Dict[str, Any]]:
447 """Run comprehensive test suite across all sizes and types."""
448 all_results = {}
449
450 for size in self.sizes:
451 size_key = f"{size / (1 << 20):.2f}MB"
452 all_results[size_key] = {}
453
454 # Test 1: Large bytes object (BINBYTES8)
455 test_name = f"bytes_{size_key}"
456 obj = DataGenerator.large_bytes(size)
457 all_results[size_key][test_name] = self.run_test(test_name, obj)
458
459 # Test 2: Large ASCII string (BINUNICODE8)
460 test_name = f"string_ascii_{size_key}"
461 obj = DataGenerator.large_string_ascii(size)
462 all_results[size_key][test_name] = self.run_test(test_name, obj)
463
464 # Test 3: Large multibyte UTF-8 string
465 if size >= 3:
466 test_name = f"string_utf8_{size_key}"
467 obj = DataGenerator.large_string_multibyte(size)
468 all_results[size_key][test_name] = self.run_test(test_name, obj)
469
470 # Test 4: Large bytearray (BYTEARRAY8, protocol 5)
471 if self.protocol >= 5:
472 test_name = f"bytearray_{size_key}"
473 obj = DataGenerator.large_bytearray(size)
474 all_results[size_key][test_name] = self.run_test(test_name, obj)
475
476 # Test 5: List of large objects (repeated chunking)
477 if size >= MIN_READ_BUF_SIZE * 2:
478 test_name = f"list_large_items_{size_key}"
479 item_size = size // 5
480 obj = DataGenerator.list_of_large_bytes(item_size, 5)
481 all_results[size_key][test_name] = self.run_test(test_name, obj)
482
483 # Test 6: Dict with large values
484 if size >= MIN_READ_BUF_SIZE * 2:
485 test_name = f"dict_large_values_{size_key}"
486 value_size = size // 3

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…