libvt.contrib.syrupy

Optional syrupy .ambr adapter and conditional pytest11 fixture built on top of libvt.testing’s tool-agnostic serialize_vt_snapshot(), vt_screen(), and format_vt_diff_lines() helpers. Install with the syrupy extra:

$ uv add --dev "libvt[syrupy]>=0.0.1a5,<0.1"

When syrupy is active in pytest, libvt_syrupy automatically registers vt_snapshot (and omits it from pytest --fixtures when syrupy is uninstalled or disabled via -p no:syrupy):

>>> import libvt
>>> from libvt.testing import vt_screen
>>> def test_tui_banner(vt_snapshot):
...     term = libvt.Terminal(rows=2, cols=18)
...     term.feed(b"\x1b[1;32mREADY\x1b[0m  pid=48210\r\nok")
...     assert vt_screen(term, scrubbers=[(r"pid=\d+", "pid=<PID>")]) == vt_snapshot
>>> class _VerifyAmbr:
...     def __eq__(self, other: object) -> bool:
...         out = vt_snapshot.extension.serialize(other)
...         return "│READY  pid=<PID>  │" in out and "bold fg=green" in out
>>> test_tui_banner(_VerifyAmbr())

See Testing Terminal Programs for using serialize_vt_snapshot() and vt_screen() without syrupy, or configuring project-wide .ambr scrubbers with VtSnapshotExtension.configure.

Fixture

fixture libvt.contrib.syrupy.vt_snapshot → SnapshotAssertion
fixture[source]
fixture[source]
fixture libvt.contrib.syrupy.vt_snapshot → SnapshotAssertion

Return a syrupy assertion bound to VtSnapshotExtension.

Depends on:

request

Registered automatically by libvt_syrupy when syrupy is active in pytest (and omitted from pytest --fixtures when syrupy is uninstalled or disabled via -p no:syrupy).

Returns:

syrupy assertion serializing terminals, snapshots, screens, region slices, tmux captures, and nested dicts/tuples as boxed .ambr text with styles: spans.

Examples

>>> from libvt import Terminal
>>> from libvt.testing import vt_screen
>>> term = Terminal(rows=1, cols=16)
>>> term.feed(b"\x1b[1;32mOK\x1b[0m  pid=48210")
>>> view = vt_screen(term, scrubbers=[(r"pid=\d+", "pid=<PID>")])
>>> print(vt_snapshot.extension.serialize(view))
size=16x1 cursor=(0,13,vis=True) alt=False modes=[]
┌────────────────┐
│OK  pid=<PID>   │
└────────────────┘
styles:
  r0[0..2]: bold fg=green

Extension

class libvt.contrib.syrupy.VtSnapshotExtension
class libvt.contrib.syrupy.VtSnapshotExtension

Bases: AmberSnapshotExtension

syrupy .ambr extension for boxed VT and SGR snapshots.

Delegates serialization and diffing to libvt.testing while integrating with syrupy’s .ambr persistence and TTY styling.

Examples

>>> from libvt import Terminal
>>> from libvt.contrib.syrupy import VtSnapshotExtension
>>> ext = VtSnapshotExtension()
>>> term = Terminal(rows=1, cols=10)
>>> term.feed(b"\x1b[1;32mREADY\x1b[0m")
>>> print(ext.serialize(term))
size=10x1 cursor=(0,5,vis=True) alt=False modes=[]
┌──────────┐
│READY     │
└──────────┘
styles:
  r0[0..5]: bold fg=green
libvt.contrib.syrupy.get_vt_snapshot_extension()
function[source]
function[source]
libvt.contrib.syrupy.get_vt_snapshot_extension()

Return the lazily constructed VtSnapshotExtension class.

Returns:

AmberSnapshotExtension subclass imported from syrupy on first call.

Return type:

type[VtSnapshotExtension]

Examples

>>> from libvt.contrib.syrupy import get_vt_snapshot_extension
>>> ext_cls = get_vt_snapshot_extension()
>>> ext_cls.__name__
'VtSnapshotExtension'