Skip to main content
Documentation Status https://travis-ci.org/dmgass/baseline.svg?branch=master

This tool streamlines creation and maintenance of tests which compare string output against a baseline. It offers a mechanism to compare a string against a baselined copy and update the baselined copy to match the new value when a mismatch occurs. The update process includes a manual step to facilitate a review of the change before acceptance. The tool uses multi-line string format for string baselines to improve readability for human review.

Quick Start

Create an empty baseline with a triple quoted multi-line string. Place the ending triple quote on a separate line and indent it to the level you wish the string baseline update to be indented to. Add a compare of the string being tested to the baseline string. Then save the file as fox.py:

from baseline import Baseline

expected = Baseline("""
    """)

test_string = """THE QUICK BROWN FOX
    JUMPS
OVER THE LAZY DOG."""

assert test_string == expected

Run fox.py and observe that the assert raises an exception since the strings are not equal. Because the comparison failed, the tool located the triple quoted baseline string in the source file and updated it with the mis-compared value. When the interpreter exited, the tool saved the updated source file but changed the file name to fox.py.update:

from baseline import Baseline

expected = Baseline("""
    THE QUICK BROWN FOX
        JUMPS
    OVER THE LAZY DOG.
    """)

test_string = """THE QUICK BROWN FOX
    JUMPS
OVER THE LAZY DOG."""

assert test_string == expected

After reviewing the change with your favorite file differencing tool, accept the change by either manually overwriting the original file or use the baseline command line tool to scan the directory for updated scripts:

$ python -m baseline *
Found baseline updates for:
  fox.py

Hit [ENTER] to accept, [Ctrl-C] to cancel

Pressing Enter causes the tool to overwrite the scripts with the new baseline updates and remove the temporary .py.update files.

Run fox.py again and observe the assert does not raise an exception nor is a copy of the source file update generated. If in the future the test value changes, the assert raises an exception and causes a new source file update to be generated. Simply repeat the review and acceptance step and you are back in business!

Release files for baseline 1.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for baseline 1.2.1
File Interpreter ABI Platform
baseline-1.2.1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Release files / baseline-1.2.1-py2.py3-none-any.whl

Download URL baseline-1.2.1-py2.py3-none-any.whl
Size 15.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
1f8046d5ecd9402cf6a2edde79ab7a5a61da9292808f9ea077f6025c548bfcfc
BLAKE2b-256 checksum
How to use checksums
80c9e0173857e1350599a0b0eb6c8bc059a345aebdb947839f3d25835b5a44f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.23.0 setuptools/51.1.0.post20201221 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.8.7

Release history Release notifications | RSS feed

This release

1.2.1 This release

1 release file

1.2.0

1 release file

1.1.2

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.0

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page