import toml
import yaml
import json


def mock_settings_file(request, monkeypatch, tmpdir, file_extension):
    """Temporarily write a settings file and return the filepath and the expected settings outcome."""
    ext = file_extension
    p = tmpdir.mkdir("sub").join("settings" + ext)

    expected_result = {"testgroup": {"testvar": 123}, "othergroup": {"blabla": 555}}

    if ext == ".toml":
        p.write(toml.dumps(expected_result))
    elif ext in [".yml", ".yaml"]:
        p.write("---\n" + yaml.dump(expected_result))
    elif ext == ".json":
        p.write(json.dumps(expected_result))
    else:  # pragma: nocover
        raise NotImplementedError("Invalid file extension :{}.".format(ext))

    return str(p), expected_result