Experiments: allow setting of list parameters (#4769)

* Allow setting of list parameteres

Check if dict is Mapping or list before using .get()

* Added test for dvc exp run with list paramater

* Add more tests for string parameter modification
This commit is contained in:
Sami Jawhar
2020-10-23 14:35:17 +09:00
committed by GitHub
parent ec05e6026f
commit 831e85682e
2 changed files with 36 additions and 1 deletions
@@ -93,6 +93,35 @@ def test_update_with_pull(tmp_dir, scm, dvc, mocker):
assert exp_scm.has_rev(rev)
@pytest.mark.parametrize(
"change, expected",
[
["foo.1.baz=3", "foo: [bar: 1, baz: 3]"],
["foo.0=bar", "foo: [bar, baz: 2]"],
["foo.1=- baz\n- goo", "foo: [bar: 1, [baz, goo]]"],
],
)
def test_modify_list_param(tmp_dir, scm, dvc, mocker, change, expected):
tmp_dir.gen("copy.py", COPY_SCRIPT)
tmp_dir.gen("params.yaml", "foo: [bar: 1, baz: 2]")
stage = dvc.run(
cmd="python copy.py params.yaml metrics.yaml",
metrics_no_cache=["metrics.yaml"],
params=["foo"],
name="copy-file",
)
scm.add(["dvc.yaml", "dvc.lock", "copy.py", "params.yaml", "metrics.yaml"])
scm.commit("init")
new_mock = mocker.spy(dvc.experiments, "new")
dvc.experiments.run(stage.addressing, params=[change])
new_mock.assert_called_once()
assert (
tmp_dir / ".dvc" / "experiments" / "metrics.yaml"
).read_text().strip() == expected
def test_checkout(tmp_dir, scm, dvc):
tmp_dir.gen("copy.py", COPY_SCRIPT)
tmp_dir.gen("params.yaml", "foo: 1")