CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-syrupy

Pytest snapshot testing utility that enables developers to write tests asserting immutability of computed results.

Overall
score

80%

Overview
Eval results
Files

task.mdevals/scenario-2/

Multi-stage Event Snapshots

A utility that summarizes and filters event records while validating outputs with snapshotting from the dependency.

Capabilities

Captures baseline and updated summaries in one test

  • With the initial events below, calling 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. @test
  • After adding the new purchase event below using add_event, a second snapshot in the same test must capture the updated summary showing incremented purchase counts, updated totals, and the later timestamp. @test

Stores a custom-named filtered view

  • Within the same test, capturing the purchase-only list returned by filter_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. @test

Test Data

Use 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_events
  • total_amount
  • per_kind counts keyed by kind
  • amount_per_kind totals keyed by kind
  • first_timestamp
  • last_timestamp

Implementation

@generates

API

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.
    """
    ...

Dependencies { .dependencies }

syrupy { .dependency }

Provides snapshot assertion support for pytest with auto-indexing and custom-named snapshots.

Install with Tessl CLI

npx tessl i tessl/pypi-syrupy

tile.json