FawltyDeps icon indicating copy to clipboard operation
FawltyDeps copied to clipboard

Tests if the generated toml config is loaded correctly as the same `Settings` object: property -based check

Open mknorps opened this issue 1 year ago • 0 comments

Test if the operation of generating pyproject.toml FawltyDeps section via:

fawltydeps --generate-toml-config

is loaded again gives the same object.

This will be best achieved with the property-based test of function and its inverse. The same may be done for toml settings -> Settings object ->` toml settings check.

Proposed outline of the hypothesis-based test:

generate_settings = strategies.just(Settings()) # here we need to write proper strategies

@given(setting_example=generate_settings)
def test_property__load_printed_config_gives_the_same_object(setting_example, tmp_path):
    with open(tmp_path / "pyproject.toml") as f:
        print_toml_config(setting_example, out=f)

    settings_loaded = Settings.config(config_file=tmp_path / "pyproject.toml").create()

    assert setting_example == settings_loaded

It is possible, that refactor of Setting object will be needed or some clever way to use temporary directories in a hypothesis check.

mknorps avatar Apr 06 '23 14:04 mknorps