Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

snapdiff-0.1.1.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

snapdiff-0.1.1-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file snapdiff-0.1.1.tar.gz.

File metadata

  • Download URL: snapdiff-0.1.1.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for snapdiff-0.1.1.tar.gz
Algorithm Hash digest
SHA256 99f7ef8b090c3c2c7198f37ab0103d014fed0c9fe8b555e637d6ee0d0afb9fb3
MD5 2490497a2cffaa0a39d85b288f06a469
BLAKE2b-256 98d11dec358f83407c43119334d5fa95fbf39155489d2ff1a94a66b04de3a8d1

See more details on using hashes here.

File details

Details for the file snapdiff-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: snapdiff-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for snapdiff-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e068c825a5de290fff04a51ec153ce208f6a7f0763b678da8e30a99338196b44
MD5 0891710db6a05a5f408d81e8063ba2d5
BLAKE2b-256 d9e43b08a746f206d8edb45cb8d1caa7586472275576613f2350192ca0150318

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page