Skip to main content

A humble library greasing the gears of golden file tests

Project description

goldie

A humble library greasing the gears of golden file tests.

Installation

pip install goldie

Example

This is an example of how to use goldie to test a script across multiple JSON files. The golden files will be used as a reference to compare the output of the script. Adding GOLDIE_UPDATE=1 to the environment variables will update the golden files with the output of the script. Find the full example in the example directory.

import unittest

import goldie


class TestExample(unittest.TestCase):
    def test_script(self):
        config = goldie.ConfigDirectoryTest(
            # We want to test all JSON files in the data directory.
            file_filter="data/*.json",
            run_configuration=goldie.ConfigRun(
                # We simply run the script in this directory.
                cmd="python",
                args=["script.py"],
                # The script reads from stdin and writes to stdout.
                input_mode=goldie.InputMode.STDIN,
                output_mode=goldie.OutputMode.STDOUT,
            ),
            comparison_configuration=goldie.ConfigComparison(
                # We want to leverage the JSON structure instead of comparing raw strings.
                comparison_type=goldie.ComparisonType.JSON,
                json_processing_config=goldie.ConfigProcessJson(
                    replacements=[
                        # We want to replace an unstable value with a stable one.
                        goldie.JsonReplacement(path="random", value=3),
                    ],
                ),
            ),
        )
        goldie.directory.run_unittest(self, config)


if __name__ == "__main__":
    unittest.main()

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

goldie-0.1.6.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

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

goldie-0.1.6-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file goldie-0.1.6.tar.gz.

File metadata

  • Download URL: goldie-0.1.6.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for goldie-0.1.6.tar.gz
Algorithm Hash digest
SHA256 0bf71c26690a65f42dfe819f70652a74d09c24233a4a1d2b9d64190836269de8
MD5 a3171e3b4bf3bac58d5e40ab86db9f1c
BLAKE2b-256 e842ed6d16833c1bbc22ff60798e3cc2d659bb8686f28726866d10c4ba9c7f64

See more details on using hashes here.

Provenance

The following attestation bundles were made for goldie-0.1.6.tar.gz:

Publisher: release.yml on merschformann/goldie

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file goldie-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: goldie-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 13.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for goldie-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 57f92ae7a95d76f5bed567b85f5f351c8dfd39b930637f0c1c68466fb3996cf7
MD5 1d9eeeef3e9dfcd7663635a0f0449d07
BLAKE2b-256 95605d6ea9cd10532eca3e5988f4cde191bb07995c7396d6f27b6d52f4fcf804

See more details on using hashes here.

Provenance

The following attestation bundles were made for goldie-0.1.6-py3-none-any.whl:

Publisher: release.yml on merschformann/goldie

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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