CodeSampleX

Ejemplo

rich 15.0.0: Render rich Console output to a string a test can assert on, and pin the escape codes, width, markup and highlighting that decide what the string holds

Muestra verificada para pypi rich 15.0.0: Render rich Console output to a string a test can assert on, and pin the escape codes, width, markup and…

sha256:3dae0c04df2ebeff413e9a4a6dc0213423def8b204f079fa3e738abce3780035

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
2
Claves de firma que lo compilaron
2
Entorno declarado python 3.12 linux x64 python 3.12 python pip

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
python 3.12 · linux alpine/x64 · docker ed25519:a2ec939a4c60e243 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · python@1
2026-08-14
python 3.12 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · python@1
2026-08-18

Caso

HOW
Objetivo
Render rich Console output to a string a test can assert on, and pin the escape codes, width, markup and highlighting that decide what the string holds
Paquetes
Símbolos
  • rich.console.Console
  • Console.capture
  • Console.export_text
  • force_terminal
  • color_system
  • rich.style.Style
  • rich.table.Table
  • rich.markup.escape
  • rich.errors.MarkupError
  • __rich__
  • __rich_console__
  • highlight
Entorno
python 3.12
Creado
2026-08-14T13:20:38Z

Contrato

  1. assert a Console writing to a StringIO reports is_terminal False and color_system None, and emits the markup's text with no escape byte in it
  2. assert force_terminal=True on the same StringIO emits the bold escape sequence, so the codes are a setting rather than a property of the output
  3. assert TERM and COLORTERM decide which color_system is detected and COLORTERM outranks TERM, while neither moves the bytes for bold, which is an attribute and not a colour
  4. assert color_system is settled in the constructor where width is read at access time, so one console follows the environment for its width and ignores it for its colours
  5. assert FORCE_COLOR in the environment turns is_terminal on for a plain file, which is how a CI log fills with escape codes nobody asked for
  6. assert TTY_COMPATIBLE is read before FORCE_COLOR and 0 defeats it while 1 turns is_terminal on by itself, so that fix stops working in a runner exporting it
  7. assert TERM=dumb leaves is_terminal True while dropping color_system to None, so the two are separate switches
  8. assert no_color=True still emits the bold code and only color_system=None suppresses every escape sequence
  9. assert a Style keeps the codes it rendered first, so the console that renders a colour first fixes its bytes for the process and a later console with a different color_system repeats them
  10. assert console.capture() returns the rendered text and redirects rather than tees, so the console's own file receives nothing while the capture is open
  11. assert a capture keeps the escape codes the console would have written, so it is not a way to get plain text
  12. assert nested captures do not nest: the inner result holds everything printed since the outer block began and the outer result holds only what followed
  13. assert record=True with export_text clears the recording by default, so a second call returns an empty string
  14. assert os.get_terminal_size raises with no tty and the console falls back to width 80 by height 25
  15. assert COLUMNS overrides that fallback and is read at access time, so an existing console changes width when the environment does, while an explicit width= beats COLUMNS
  16. assert a small Table renders identically at 40, 80 and 120 columns because it measures its content, while expand=True and overflowing text are what follow the console width
  17. assert markup is interpreted by default and markup=False renders the tags literally, both per-call and per-console
  18. assert markup deletes user text without an error for list[int], for a bracketed sentence and for an unknown style name, on a console emitting codes as well as one that is not
  19. assert a stray closing tag raises rich.errors.MarkupError, which is a ConsoleError and not a ValueError, and that escape() or markup=False prevents it
  20. assert emoji codes are substituted by default and that a Text object is never parsed for markup
  21. assert console.print uses __rich__ first, then __rich_console__, and that __rich__ wins when both exist and is looked up on the instance
  22. assert an object with neither hook is rendered with str() and not repr(), while a container is pretty-printed with repr() on its items
  23. assert the str() branch skips markup and emoji parsing, so printing an object cannot be injected the way printing a string can, while the highlighter is the one rewrite it does not skip
  24. assert a string returned from __rich__ goes through the highlighter, which splits the markup's style run in two on the number inside it
  25. assert the highlighter styles a bare number, a number inside a sentence and the shape of a repr unless highlight=False
  26. assert highlight=False changes nothing on a console that emits no codes, because the highlighter still runs and its spans have nowhere to go
  27. assert rich exports no __version__, so the version has to come from importlib.metadata

Archivos

  • csx.json
  • requirements.txt
  • src/__init__.py
  • src/report.py
  • test/contract.py

Descargar el artefacto de código fuente (tar.gz)

Seeder de origen

anonymous