Pytest snapshot testing utility that enables developers to write tests asserting immutability of computed results.
Overall
score
80%
A utility that summarizes and filters event records while validating outputs with snapshotting from the dependency.
summarize_events should produce counts per kind, totals, and first/last timestamps; the first snapshot in the test must record this baseline output before mutations. @testadd_event, a second snapshot in the same test must capture the updated summary showing incremented purchase counts, updated totals, and the later timestamp. @testfilter_events(events, "purchase") should be saved under a custom label rather than the auto-numbered sequence, and must include the newly added purchase at the end while preserving earlier order. @testUse these events:
[
{"id": 1, "kind": "signup", "amount": 0.0, "timestamp": "2024-01-01T00:00:00Z"},
{"id": 2, "kind": "purchase", "amount": 10.5, "timestamp": "2024-01-02T12:00:00Z"},
{"id": 3, "kind": "purchase", "amount": 5.0, "timestamp": "2024-01-05T18:30:00Z"}
]Add this event during the test:
{"id": 4, "kind": "purchase", "amount": 15.0, "timestamp": "2024-01-06T09:00:00Z"}Expected summary fields for snapshots:
total_eventstotal_amountper_kind counts keyed by kindamount_per_kind totals keyed by kindfirst_timestamplast_timestamp@generates
from typing import Any, Dict, List
Event = Dict[str, Any]
def summarize_events(events: List[Event]) -> Dict[str, Any]:
"""
Returns a summary dictionary containing total_events, total_amount,
per_kind counts, amount_per_kind totals, first_timestamp, and last_timestamp.
"""
...
def add_event(events: List[Event], event: Event) -> List[Event]:
"""
Returns a new list with the event appended; input should not be mutated.
"""
...
def filter_events(events: List[Event], kind: str) -> List[Event]:
"""
Returns events whose 'kind' matches the provided value, preserving input order.
"""
...Provides snapshot assertion support for pytest with auto-indexing and custom-named snapshots.
Install with Tessl CLI
npx tessl i tessl/pypi-syrupyevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10