A package for comparing snapshots of data and tracking differences when function change
Project description
snapdiff
Here's the README content as one continuous Markdown block:
snapdiff
snapdiff is a Python package for capturing snapshots of function input and output data to track changes over time. It’s designed for use in testing and debugging, allowing you to compare function results across different runs and log any differences.
Features
- Snapshot Mode: Saves a snapshot of function inputs and outputs.
- Diff Mode: Compares current function outputs with previously saved snapshots, logging differences.
- Customizable Diff Functions: Use built-in or custom diff functions to handle comparisons.
- Logging: Configurable logging options to monitor differences across function runs.
Installation
Install snapdiff using pip:
pip install snapdiff
Basic Usage
Setting Up Snapshots
Decorate a function with @snapper(mode="snap") to take a snapshot of inputs and outputs. This is useful for capturing a function's behavior for later comparisons.
from snapdiff import snapper
@snapper(mode="snap")
def example_function(a, b):
return a + b
# Taking a snapshot
example_function(2, 3)
Comparing with Snapshots
Switch to mode="diff" to check if the function’s behavior has changed compared to the previous snapshot.
from snapdiff import snapper
@snapper(mode="diff")
def example_function(a, b):
return a + b
# This will compare the result of the current call with the saved snapshot
example_function(2, 3)
If there’s any difference in input or output, it will be logged.
Advanced Usage
Custom Diff Functions
You can supply a custom diff function for cases where the built-in DeepDiff does not suit your needs.
from snapdiff import snapper
def custom_diff(a, b):
return {"difference": a - b} if a != b else {}
@snapper(mode="diff", diff_func=custom_diff)
def example_function(a, b):
return a * b
example_function(4, 5)
Logging Options
To enable or disable logging to a file, use the log_to_file parameter when initializing the Snapper decorator.
from snapdiff import snapper
@snapper(mode="diff", log_to_file=False)
def example_function(a, b):
return a ** b
Configuration
snapdiff allows configuration using a YAML file named snapdiff_config.yaml to specify default directories for snapshots, log files, and subtype-specific options.
License
MIT License
For full documentation and examples, visit the GitHub repository.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file snapdiff-0.1.2.tar.gz.
File metadata
- Download URL: snapdiff-0.1.2.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7422a9e2761a3c8eef3c084cdaa91df99f8c5b0cef830b36f5fb564616c23170
|
|
| MD5 |
acb3cfa74ac944ab375db1d99de1a2f0
|
|
| BLAKE2b-256 |
59c56d1ace563b9917982753a32eae96c835913a82f6caa1d576bb250b9adce2
|
File details
Details for the file snapdiff-0.1.2-py3-none-any.whl.
File metadata
- Download URL: snapdiff-0.1.2-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f63f1b509fdb4b52c97f7862816f89367eda28ab3b6ba7ce3b763f9746ef9b0f
|
|
| MD5 |
3592184d6a82f874076aa97040927056
|
|
| BLAKE2b-256 |
cff76a882236521ca877dcfd99dc0262e7da539561c0d4a9e2eab520204c0404
|