Back to Repositories

Testing Rich Pretty Printer and Panel Rendering Capabilities in Textualize/rich

This stress test suite evaluates the Rich library’s Pretty printer and Panel rendering capabilities under varying width conditions. It systematically tests the formatting and display of complex nested data structures, including lists, dictionaries, tuples, and sets, while measuring performance.

Test Coverage Overview

The test provides comprehensive coverage of Rich’s Pretty and Panel components by iterating through different width configurations.

Key areas tested include:
  • Nested data structure rendering
  • Width-based formatting adaptation
  • Indent guide visualization
  • Performance monitoring across iterations

Implementation Analysis

The testing approach employs a width-based stress test pattern, systematically evaluating the rendering engine’s behavior across different terminal widths from 0 to 129.

Technical implementation features:
  • Console output manipulation
  • Performance timing wrapper
  • Nested data structure handling
  • Dynamic width adjustment testing

Technical Details

Testing components and configuration:
  • Rich Console object for output management
  • Panel component for bordered display
  • Pretty printer with indent guides enabled
  • Timer utility for performance measurement
  • Complex test data structure with mixed types

Best Practices Demonstrated

The test exemplifies robust stress testing practices by combining performance monitoring with comprehensive edge case coverage.

Notable practices include:
  • Systematic width iteration
  • Complex test data structure
  • Performance measurement integration
  • Comprehensive component integration testing

textualize/rich

tools/stress_test_pretty.py

            
from rich.console import Console
from rich.panel import Panel
from rich.pretty import Pretty
from rich._timer import timer

DATA = {
    "foo": [1, 2, 3, (), {}, (1, 2, 3), {4, 5, 6, (7, 8, 9)}, "Hello, World"],
    "bar": [None, (False, True)] * 2,
    "Dune": {
        "names": {
            "Paul Atreides",
            "Vladimir Harkonnen",
            "Thufir Hawat",
            "Duncan Idaho",
        }
    },
}
console = Console()
with timer("Stress test"):
    for w in range(130):
        console.print(Panel(Pretty(DATA, indent_guides=True), width=w))