Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ All notable changes to this project will be documented in this file.

*NOTE:* Version 0.X.X might have breaking changes in bumps of the minor version number. This is because the project is still in early development and the API is not yet stable. It will still be marked clearly in the release notes.

## [0.8.0]
- 🆕 Used integration with toolit to make snappylapy commands available for AI coding assistants

## [0.7.0] - 2025-08-27
- 🆕 Added csv serializer for pandas dataframes for making the deserialization work on windows and make a more suitable and human readable format.

Expand Down
36 changes: 25 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ poetry add snappylapy
- **Easy to Use**: Seamlessly integrates with pytest, enabling you to capture and verify snapshots with minimal setup. The fully typed fixtures and rich editor support provide intuitive code completion and guidance, making your workflow faster and more productive.
- **Customizable Output**: Store snapshots in a location (static or dynamic) of your choice, enabling you to organize and manage your test data effectively.
- **Editor Integration**: Can show a diff comparison in VS code when a snapshot test fails, for easy comparison between test results and snapshots.
- **AI Coding Agent Integration**: Snappylapy integrates its commands with AI coding agents such as GitHub Copilot, Cursor, and Claude Code.

## Benefits of Snapshot Testing
Snapshot testing is a powerful technique for verifying the output of your code by comparing it to a stored snapshot. This approach offers several benefits, including:
Expand All @@ -37,7 +38,7 @@ Snapshot testing is a powerful technique for verifying the output of your code b

## Why Snappylapy?

When working on a test suite for a project, it’s important to ensure tests are independent. This is to avoid situations where changes in one part of the code cause failures in tests for other unrelated areas, making it challenging to isolate and fix errors. Snappylapy addresses this by providing a mechanism to capture snapshots of your data and use them in your later tests, ensuring that each component can be tested independently. While also making sure that they are dependent enought to test the integration between them. It provides serialization and deserialization of the snapshots, making it easy to reuse them in different test cases. This is aimed at function working with large and complex data structures (dataframes or large nested dictionaries.)
When working on a test suite for a project, it’s important to ensure tests are independent. This is to avoid situations where changes in one part of the code cause failures in tests for other unrelated areas, making it challenging to isolate and fix errors. Snappylapy addresses this by providing a mechanism to capture snapshots of your data and use them in your later tests, ensuring that each component can be tested independently. While also making sure that they are dependent enough to test the integration between them. It provides serialization and deserialization of the snapshots, making it easy to reuse them in different test cases. This is aimed at function working with large and complex data structures (dataframes or large nested dictionaries.)

### Example

Expand Down Expand Up @@ -81,7 +82,7 @@ def test_load_snapshot_from_file(load_snapshot: LoadSnapshot):
assert data == {"name": "John Doe", "age": 31}
```

This can be great for external dependencies, for example an AI service, that might change response over time. With this approach we can isolate the changes to the service and still make succeding tests pass.
This can be great for external dependencies, for example an AI service, that might change response over time. With this approach we can isolate the changes to the service and still make succeeding tests pass.

## The output structure

Expand All @@ -103,16 +104,11 @@ Alternatively, you can use the CLI command to update snapshots:
snappylapy update
```

## Fixtures and roadmap
### Pytest Fixtures
Registers pytest fixtures:
- expect
- load_snapshot
- `expect`: A fixture that provides methods to create snapshot expectations for various data types (e.g., dict, list, string, bytes, DataFrame).
- `load_snapshot`: A fixture that loads snapshot data from a file.

Supported data types
- ✅ .txt - if you provide a string
- ✅ .json - for all other objects
- ✅ .csv - for pandas DataFrames
- ✅ custom (decode the data yourself and provide a file extension)

### Supported data types to snapshot test
Snappylapy uses jsonpickle to serialize into json, this means that it can handle almost any Python object out of the box, including:
Expand All @@ -124,7 +120,25 @@ Snappylapy uses jsonpickle to serialize into json, this means that it can handle

It is also possible to serialize objects yourself and provide them as a string or bytes data. Then it will be stored and loaded as-is. This means that with snappylapy it is possible to serialize and deserialize any Python object, even those not natively supported.

Snappylapy is your go-to tool for efficient and reliable snapshot testing in Python. By maintaining clear boundaries between different parts of your code, Snappylapy helps you isolate errors, streamline debugging, and ensure your code remains robust and maintainable.
Supported output file formats:
- ✅ .txt - if you provide a string
- ✅ .json - for all other objects
- ✅ .csv - for pandas DataFrames
- ✅ custom (decode the data yourself and provide a file extension)

### Tasks for VSCode integration (available for github copilot agents)
Snappylapy can make its CLI commands available for AI coding agents like GitHub Copilot, Cursor and Claude Code.

One example of how to do this is by registering tasks in VSCode. We use toolit, to make the integration seamless. To register the tasks, run the following command:

```bash
toolit create-vscode-tasks-json
```

> WARNING: This will overwrite any existing tasks.json file in the .vscode folder.


## Contributing
We welcome contributions to Snappylapy! If you have ideas for new features, improvements, or bug fixes, please open an issue or submit a pull request on our GitHub repository. We appreciate your feedback and support in making Snappylapy even better for the community.

Snappylapy is your go-to tool for efficient and reliable snapshot testing in Python. By maintaining clear boundaries between different parts of your code, Snappylapy helps you isolate errors, streamline debugging, and ensure your code remains robust and maintainable.
10 changes: 8 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ authors = [
{name = "Martin Møldrup"},
]
requires-python = "<4.0,>=3.9"
version = "0.7.0"
version = "0.8.0"
description = "A snapshot library for python optimized for easy of use, human readable snapshots and enabling decoupling of chained integration tests."
readme = "README.md"
classifiers = [
Expand Down Expand Up @@ -39,6 +39,7 @@ dependencies = [
"typer",
"typing-extensions ; python_full_version == '3.9.*'",
"levenshtein>=0.27.1",
"toolit>=0.5.0",
]

[project.urls]
Expand Down Expand Up @@ -88,5 +89,10 @@ dev = [
"mkdocs-literate-nav<1.0.0,>=0.6.1",
"mkdocs-section-index<1.0.0,>=0.3.9",
"pandas-stubs>=2.2.2.240807",
"toolit>=0.2.0",
]

[project.entry-points.toolit_plugins]
snappylapy_init = "snappylapy._cli:init"
snappylapy_clear = "snappylapy._cli:clear"
snappylapy_update = "snappylapy._cli:update"
snappylapy_diff = "snappylapy._cli:diff"
19 changes: 12 additions & 7 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.