Skip to main content

Add your description here

Project description

Shrinkplz

shrinkplz is a command line tool to help shrink failing test data, similar to git bisect.

shrinkplz can take some input data causing a test failure, and then attempt shrinking it by cutting out lines from the input data until it starts passing.

At the end of the shrinkplz session, you should have a (locally) minimal input data for your test that is still failing.

Installation

This command is available on PyPI

uv tool add shrinkplz

Use Cases

  • Shrinking a failing SQL script, removing irrelevant statements
  • Shrinking a failing CI test run, by removing elements from the test list
  • Shrinking large input data to a program until it starts working again

Quick Start

Start a shrinking session by calling:

shrinkplz start some-test-data

shrinkplz expects a unicode file, and will attempt to shrink it by bisecting the lines themselves.

Once you've started a session, a file called current-input is created. This is the currently shrunk test data.

Once you have started your session, run your test with this test data or otherwise check your conditions:

./run_my_test.py current-input
# ... and then investigating the result

Once you have finished testing the data in current-input, you should mark it with the mark command

# if the test now passes
shrinkplz mark pass 

# if the test is still failing
shrinkplz mark fail

# if the test data is invalid (e.g. the data has become malformed)
shrinkplz mark invalid

Once you mark the result, current-input gets replaced with another candidate for testing.

Each mark gives shrinkplz more information about how it can shrink data.

  • shrinkplz mark fail indicates that current-input is enough to cause the failure, so discards any test data from the original input that isn't in current-input

  • shrinkplz mark pass indicates that current-input is missing the data that causes a failure, so we will restore the chunk of data that we removed

  • shrinplz mark invalid similarly indicates that the chunk of data shouldn't be removed, though without inferring more

After shrinking as much as it can, shrinkplz will write out something like:

Completed our search!
The smallest known data is copied
to current-input

From there, the session is over and current-input represents the result of the search

Script

Just like with git bisect, shrinkplz can be scripted. This is especially valuable for larger pieces of test data, where a shrinking session might require hundreds or thousands of test runs.

shrinkplz script my-test-script my-test-input 

shrinkplz script takes two inputs:

  • a test script, that will be run by shrinkplz to determine how to mark input data.

    The test script's error code determines what the marking is. A return code of 0 means to mark the data as pass, a return code of 125 indicates marking the data as invalid, and any other return code indicates a fail

  • the test input to shrink

The test script is called without arguments, but just like when running a shrinking session manually, current-input will be available as the current input

#!/usr/bin/env bash
# an example shrink script
uv run my-prog.py < current-input

At the end of the shrinkplz script session, current-input will be the shrunk test data

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

shrinkplz-0.1.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file shrinkplz-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: shrinkplz-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.6

File hashes

Hashes for shrinkplz-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7af29fb216c1a000db7f19030b789c7a6bf6ca98bb61e9af9766d9ba1299d7a5
MD5 d4c4f81479ee7dc95f2e0921bc040fa4
BLAKE2b-256 52041d5175d52a7e0ebc2d0e11935cd22ab1f07616805029b9dd85272f0a42f2

See more details on using hashes here.

Supported by

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