Skip to content

A humble library greasing the gears of golden file tests.

License

Notifications You must be signed in to change notification settings

merschformann/goldie

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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",
            config_file_test=goldie.ConfigFileTest(
                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="data.random", value=3),
                        ],
                    ),
                ),
            ),
        )
        goldie.testing.run_directory_unittest(self, config)


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

About

A humble library greasing the gears of golden file tests.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages