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 libvt.contrib.syrupy.vt_snapshot SnapshotAssertion¶
Return a
syrupyassertion bound toVtSnapshotExtension.- Depends on:
Registered automatically by
libvt_syrupywhensyrupyis active inpytest(and omitted frompytest --fixtureswhensyrupyis uninstalled or disabled via-p no:syrupy).- Returns:
syrupyassertion serializing terminals, snapshots, screens, region slices,tmuxcaptures, and nested dicts/tuples as boxed.ambrtext withstyles: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:
AmberSnapshotExtensionsyrupy.ambrextension for boxed VT andSGRsnapshots.Delegates serialization and diffing to
libvt.testingwhile integrating withsyrupy’s.ambrpersistence 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()¶libvt.contrib.syrupy.get_vt_snapshot_extension()¶
Return the lazily constructed
VtSnapshotExtensionclass.- Returns:
AmberSnapshotExtensionsubclass imported fromsyrupyon first call.- Return type:
Examples
>>> from libvt.contrib.syrupy import get_vt_snapshot_extension >>> ext_cls = get_vt_snapshot_extension() >>> ext_cls.__name__ 'VtSnapshotExtension'