All skills
lexler avatar

/approval-tests

@83aee6a
by Lada Kesselerlexler/skill-factory238 stars
61

Writes approval tests (snapshot/golden master testing) for Python, JavaScript/TypeScript, or Java. Use when verifying complex output, characterization testing legacy code, testing combinations, or working with .approved/.received files.

Use this Skill: https://skilld.dev/gh/lexler/skill-factory/approval-tests

This session only. Nothing lands on disk.

referencespythonapi.md

≈1.1k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Python ApprovalTests API

Contents

For combination testing, see combinations.md. For scrubbers, see scrubbers.md. For logging verification, see logging.md.

Core Verify Functions

from approvaltests import (
    verify,
    verify_as_json,
    verify_all,
    verify_xml,
    verify_html,
    verify_file,
    verify_exception,
    verify_binary,
)

verify()

Basic string verification.

from approvaltests import verify

verify("Hello World")

verify_as_json()

Object to pretty-printed JSON. Preferred for structured data.

from approvaltests import verify_as_json

verify_as_json(user)
verify_as_json({"users": users, "count": len(users)})

verify_all()

Collection with header label and optional formatter.

from approvaltests import verify_all

verify_all("Users", users)
verify_all("Prices", items, lambda x: f"{x.name}: ${x.price}")

verify_xml()

Pretty-prints XML before verification.

from approvaltests import verify_xml

verify_xml(xml_string)

verify_html()

Pretty-prints HTML before verification. Requires beautifulsoup4.

from approvaltests import verify_html

verify_html(html_string)

verify_file()

Verify contents of an existing file.

from approvaltests import verify_file

verify_file("output/report.txt")

verify_exception()

Verify exception message.

from approvaltests import verify_exception

verify_exception(lambda: divide(1, 0))

verify_binary()

Binary data (images, PDFs). Second argument is file extension.

from approvaltests import verify_binary

verify_binary(image_bytes, ".png")

Options Class

Fluent configuration. All methods return new Options instance.

from approvaltests import verify, Options

options = (Options()
    .with_reporter(reporter)
    .with_scrubber(my_scrubber)
    .for_file.with_extension(".json"))

verify(data, options=options)

Methods

  • with_reporter(reporter) - Set failure reporter
  • with_scrubber(fn) - Set scrubber function
  • add_scrubber(fn) - Chain additional scrubber
  • with_namer(namer) - Custom file naming
  • with_comparator(cmp) - Custom comparison logic
  • for_file.with_extension(".ext") - Set file extension
  • for_file.with_additional_information("suffix") - Add suffix to filename
  • inline() - Enable inline approvals (see inline.md)

Storyboard

Captures state progression over multiple frames. Use for state machines, animations, multi-step workflows.

from approvaltests import verify
from approvaltests.storyboard import Storyboard

story = Storyboard()
story.add_description("Testing game state transitions")
story.add_frame(game.get_state())
game.move("north")
story.add_frame(game.get_state(), title="After moving north")
game.pick_up("sword")
story.add_frame(game.get_state(), title="After picking up sword")
verify(story)

Output stacks frames vertically:

Testing game state transitions

Initial Frame:
room: entrance
inventory: []

After moving north:
room: hallway
inventory: []

After picking up sword:
room: hallway
inventory: [sword]

Context manager form:

from approvaltests import verify_storyboard

with verify_storyboard() as story:
    story.add_frame(state1)
    do_something()
    story.add_frame(state2)

MarkdownTable

Test multiple inputs against multiple functions in a grid.

from approvaltests import verify
from approvaltests.utilities.markdown_table import MarkdownTable

inputs = ["hello", "WORLD", "MiXeD"]
table = MarkdownTable.with_headers("Input", "upper()", "lower()", "len()")
table.add_rows_for_inputs(inputs, str.upper, str.lower, len)
verify(table)

Output:

| Input | upper() | lower() | len() |
| ----- | ------- | ------- | ----- |
| hello | HELLO   | hello   | 5     |
| WORLD | WORLD   | world   | 5     |
| MiXeD | MIXED   | mixed   | 5     |

Command Line

Test CLI output:

from approvaltests.utilities.command_line_approvals import verify_command_line

verify_command_line("python --version")

Test argparse help:

from approvaltests import verify_argument_parser

verify_argument_parser(parser)

Source: SKILL.md on GitHub

1 warning6d4 checks · Risk SAFE
  • Gen Agent Trust Hub6d

    The skill provides instructions and patterns for implementing approval testing (snapshot testing) across multiple programming languages. It includes capabilities for file system operations, command execution for testing CLI tools, and launching external diff reporters, which are consistent with the skill's purpose. The analysis identified an indirect prompt injection surface when verifying external or untrusted data.

  • Socket6d

    No alerts

  • Snyk6d

    Risk: LOW · No issues

  • Runlayer7mo

    25/25 files flagged

Signed by skilld at 83aee6a. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last month.

Steadyupdated 8 months ago

README badge

README badge for lexler/skill-factory/approval-tests