MCPcopy Create free account
hub / github.com/dask/dask / test_config_set_value

Function test_config_set_value

dask/tests/test_cli.py:78–122  ·  view source on GitHub ↗
(
    tmp_conf_dir,
    value,
    empty_config,
    file,
    existing_key_config_file,
)

Source from the content-addressed store, hash-verified

76@pytest.mark.parametrize("file", (None, "bar.yaml", "foo/bar.yaml"))
77@pytest.mark.parametrize("existing_key_config_file", (True, False))
78def test_config_set_value(
79 tmp_conf_dir,
80 value,
81 empty_config,
82 file,
83 existing_key_config_file,
84):
85 # Potentially custom file location, CLI defaulting to the default dir / 'dask.yaml'
86 config_file = tmp_conf_dir / (file or "dask.yaml")
87
88 if not empty_config:
89 expected_conf = {"dataframe": {"foo": "bar"}}
90 config_file.parent.mkdir(parents=True, exist_ok=True)
91 config_file.write_text(yaml.dump(expected_conf))
92 else:
93 expected_conf = dict()
94 assert not config_file.exists()
95
96 cmd = ["fizz.buzz", str(value)]
97
98 # default dask config location when file not specified or first file containing key
99 if file:
100 cmd.extend(["--file", str(config_file)])
101
102 runner = CliRunner()
103
104 if existing_key_config_file and not file:
105 # Now we want to ensure the config file being used is this one b/c it already
106 # has this key and hasn't explicitly provided a different file to use.
107 config_file = pathlib.Path(tmp_conf_dir) / "existing_conf.yaml"
108 cmd_ = ["fizz.buzz", "foobar", "--file", str(config_file)]
109 runner.invoke(dask.cli.config_set, cmd_, catch_exceptions=False)
110
111 # Expected config is now just what's in this file, not the default file
112 expected_conf = {"fizz": {"buzz": "foobar"}}
113
114 result = runner.invoke(dask.cli.config_set, cmd, catch_exceptions=False)
115
116 expected = f"Updated [fizz.buzz] to [{value}], config saved to {config_file}\n"
117 assert expected == result.output
118
119 actual_conf = yaml.safe_load(config_file.read_text())
120
121 expected_conf.update({"fizz": {"buzz": value}})
122 assert expected_conf == actual_conf
123
124
125def test_config_find(tmp_conf_dir):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected