From 93d7b9173b8630db7cc21df606040677dc3753d7 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Mon, 4 May 2020 20:23:49 +0300 Subject: [PATCH] tests: use --single-stage --- tests/func/metrics/test_diff.py | 16 ++++++++-------- tests/func/metrics/test_show.py | 12 ++++++------ tests/func/params/test_diff.py | 16 ++++++++-------- tests/func/params/test_show.py | 10 +++++----- tests/func/test_get.py | 4 +++- tests/func/test_import.py | 4 +++- tests/func/test_ls.py | 1 + tests/func/test_plot.py | 2 +- tests/func/test_remote.py | 2 +- tests/func/test_repo.py | 6 +++--- tests/func/test_stage.py | 4 +++- tests/unit/command/test_run.py | 3 +++ tests/unit/repo/test_repo.py | 6 +++--- tests/unit/repo/test_reproduce.py | 28 +++++++++++++++++++++------- tests/unit/test_stage.py | 4 ++-- 15 files changed, 71 insertions(+), 47 deletions(-) diff --git a/tests/func/metrics/test_diff.py b/tests/func/metrics/test_diff.py index cae538f91e..08c1f10ac9 100644 --- a/tests/func/metrics/test_diff.py +++ b/tests/func/metrics/test_diff.py @@ -5,7 +5,7 @@ def test_metrics_diff_simple(tmp_dir, scm, dvc): def _gen(val): tmp_dir.gen({"m.yaml": str(val)}) - dvc.run(cmd="", metrics=["m.yaml"]) + dvc.run(cmd="", metrics=["m.yaml"], single_stage=True) dvc.scm.add(["m.yaml.dvc"]) dvc.scm.commit(str(val)) @@ -22,7 +22,7 @@ def test_metrics_diff_yaml(tmp_dir, scm, dvc): def _gen(val): metrics = {"a": {"b": {"c": val, "d": 1, "e": str(val)}}} tmp_dir.gen({"m.yaml": yaml.dump(metrics)}) - dvc.run(cmd="", metrics=["m.yaml"]) + dvc.run(cmd="", metrics=["m.yaml"], single_stage=True) dvc.scm.add(["m.yaml.dvc"]) dvc.scm.commit(str(val)) @@ -39,7 +39,7 @@ def test_metrics_diff_json(tmp_dir, scm, dvc): def _gen(val): metrics = {"a": {"b": {"c": val, "d": 1, "e": str(val)}}} tmp_dir.gen({"m.json": json.dumps(metrics)}) - dvc.run(cmd="", metrics=["m.json"]) + dvc.run(cmd="", metrics=["m.json"], single_stage=True) dvc.scm.add(["m.json.dvc"]) dvc.scm.commit(str(val)) @@ -55,7 +55,7 @@ def test_metrics_diff_json_unchanged(tmp_dir, scm, dvc): def _gen(val): metrics = {"a": {"b": {"c": val, "d": 1, "e": str(val)}}} tmp_dir.gen({"m.json": json.dumps(metrics)}) - dvc.run(cmd="", metrics=["m.json"]) + dvc.run(cmd="", metrics=["m.json"], single_stage=True) dvc.scm.add(["m.json.dvc"]) dvc.scm.commit(str(val)) @@ -69,7 +69,7 @@ def _gen(val): def test_metrics_diff_broken_json(tmp_dir, scm, dvc): metrics = {"a": {"b": {"c": 1, "d": 1, "e": "3"}}} tmp_dir.gen({"m.json": json.dumps(metrics)}) - dvc.run(cmd="", metrics_no_cache=["m.json"]) + dvc.run(cmd="", metrics_no_cache=["m.json"], single_stage=True) dvc.scm.add(["m.json.dvc", "m.json"]) dvc.scm.commit("add metrics") @@ -91,7 +91,7 @@ def test_metrics_diff_no_metrics(tmp_dir, scm, dvc): def test_metrics_diff_new_metric(tmp_dir, scm, dvc): metrics = {"a": {"b": {"c": 1, "d": 1, "e": "3"}}} tmp_dir.gen({"m.json": json.dumps(metrics)}) - dvc.run(cmd="", metrics_no_cache=["m.json"]) + dvc.run(cmd="", metrics_no_cache=["m.json"], single_stage=True) assert dvc.metrics.diff() == { "m.json": { @@ -104,7 +104,7 @@ def test_metrics_diff_new_metric(tmp_dir, scm, dvc): def test_metrics_diff_deleted_metric(tmp_dir, scm, dvc): metrics = {"a": {"b": {"c": 1, "d": 1, "e": "3"}}} tmp_dir.gen({"m.json": json.dumps(metrics)}) - dvc.run(cmd="", metrics_no_cache=["m.json"]) + dvc.run(cmd="", metrics_no_cache=["m.json"], single_stage=True) dvc.scm.add(["m.json.dvc", "m.json"]) dvc.scm.commit("add metrics") @@ -120,7 +120,7 @@ def test_metrics_diff_deleted_metric(tmp_dir, scm, dvc): def test_metrics_diff_with_unchanged(tmp_dir, scm, dvc): tmp_dir.gen("metrics.yaml", "foo: 1\nxyz: 10") - dvc.run(metrics_no_cache=["metrics.yaml"]) + dvc.run(metrics_no_cache=["metrics.yaml"], single_stage=True) scm.add(["metrics.yaml", "metrics.yaml.dvc"]) scm.commit("1") diff --git a/tests/func/metrics/test_show.py b/tests/func/metrics/test_show.py index 608aa0522c..d21d44828e 100644 --- a/tests/func/metrics/test_show.py +++ b/tests/func/metrics/test_show.py @@ -10,34 +10,34 @@ def test_show_empty(dvc): def test_show_simple(tmp_dir, dvc): tmp_dir.gen("metrics.yaml", "1.1") - dvc.run(metrics=["metrics.yaml"]) + dvc.run(metrics=["metrics.yaml"], single_stage=True) assert dvc.metrics.show() == {"": {"metrics.yaml": 1.1}} def test_show(tmp_dir, dvc): tmp_dir.gen("metrics.yaml", "foo: 1.1") - dvc.run(metrics=["metrics.yaml"]) + dvc.run(metrics=["metrics.yaml"], single_stage=True) assert dvc.metrics.show() == {"": {"metrics.yaml": {"foo": 1.1}}} def test_show_multiple(tmp_dir, dvc): tmp_dir.gen("foo", "foo: 1\n") tmp_dir.gen("baz", "baz: 2\n") - dvc.run(fname="foo.dvc", metrics=["foo"]) - dvc.run(fname="baz.dvc", metrics=["baz"]) + dvc.run(fname="foo.dvc", metrics=["foo"], single_stage=True) + dvc.run(fname="baz.dvc", metrics=["baz"], single_stage=True) assert dvc.metrics.show() == {"": {"foo": {"foo": 1}, "baz": {"baz": 2}}} def test_show_invalid_metric(tmp_dir, dvc): tmp_dir.gen("metrics.yaml", "foo:\n- bar\n- baz\nxyz: string") - dvc.run(metrics=["metrics.yaml"]) + dvc.run(metrics=["metrics.yaml"], single_stage=True) with pytest.raises(NoMetricsError): dvc.metrics.show() def test_show_branch(tmp_dir, scm, dvc): tmp_dir.gen("metrics.yaml", "foo: 1") - dvc.run(metrics_no_cache=["metrics.yaml"]) + dvc.run(metrics_no_cache=["metrics.yaml"], single_stage=True) scm.add(["metrics.yaml", "metrics.yaml.dvc"]) scm.commit("init") diff --git a/tests/func/params/test_diff.py b/tests/func/params/test_diff.py index 3dab45066d..d34bbaf897 100644 --- a/tests/func/params/test_diff.py +++ b/tests/func/params/test_diff.py @@ -4,7 +4,7 @@ def test_diff_no_params(tmp_dir, scm, dvc): def test_diff_no_changes(tmp_dir, scm, dvc): tmp_dir.gen("params.yaml", "foo: bar") - dvc.run(params=["foo"]) + dvc.run(params=["foo"], single_stage=True) scm.add(["params.yaml", "Dvcfile"]) scm.commit("bar") assert dvc.params.diff() == {} @@ -12,7 +12,7 @@ def test_diff_no_changes(tmp_dir, scm, dvc): def test_diff(tmp_dir, scm, dvc): tmp_dir.gen("params.yaml", "foo: bar") - dvc.run(params=["foo"]) + dvc.run(params=["foo"], single_stage=True) scm.add(["params.yaml", "Dvcfile"]) scm.commit("bar") @@ -26,7 +26,7 @@ def test_diff(tmp_dir, scm, dvc): def test_diff_new(tmp_dir, scm, dvc): tmp_dir.gen("params.yaml", "foo: bar") - dvc.run(params=["foo"]) + dvc.run(params=["foo"], single_stage=True) assert dvc.params.diff() == { "params.yaml": {"foo": {"old": None, "new": "bar"}} @@ -35,7 +35,7 @@ def test_diff_new(tmp_dir, scm, dvc): def test_diff_deleted(tmp_dir, scm, dvc): tmp_dir.gen("params.yaml", "foo: bar") - dvc.run(params=["foo"]) + dvc.run(params=["foo"], single_stage=True) scm.add(["params.yaml", "Dvcfile"]) scm.commit("bar") @@ -48,7 +48,7 @@ def test_diff_deleted(tmp_dir, scm, dvc): def test_diff_deleted_config(tmp_dir, scm, dvc): tmp_dir.gen("params.yaml", "foo: bar") - dvc.run(params=["foo"]) + dvc.run(params=["foo"], single_stage=True) scm.add(["params.yaml", "Dvcfile"]) scm.commit("bar") @@ -61,7 +61,7 @@ def test_diff_deleted_config(tmp_dir, scm, dvc): def test_diff_list(tmp_dir, scm, dvc): tmp_dir.gen("params.yaml", "foo:\n- bar\n- baz") - dvc.run(params=["foo"]) + dvc.run(params=["foo"], single_stage=True) scm.add(["params.yaml", "Dvcfile"]) scm.commit("foo") @@ -76,7 +76,7 @@ def test_diff_list(tmp_dir, scm, dvc): def test_diff_dict(tmp_dir, scm, dvc): tmp_dir.gen("params.yaml", "foo:\n bar: baz") - dvc.run(params=["foo"]) + dvc.run(params=["foo"], single_stage=True) scm.add(["params.yaml", "Dvcfile"]) scm.commit("foo") @@ -89,7 +89,7 @@ def test_diff_dict(tmp_dir, scm, dvc): def test_diff_with_unchanged(tmp_dir, scm, dvc): tmp_dir.gen("params.yaml", "foo: bar\nxyz: val") - dvc.run(params=["foo,xyz"]) + dvc.run(params=["foo,xyz"], single_stage=True) scm.add(["params.yaml", "Dvcfile"]) scm.commit("bar") diff --git a/tests/func/params/test_show.py b/tests/func/params/test_show.py index e1f72cb3c4..2f903cb5b9 100644 --- a/tests/func/params/test_show.py +++ b/tests/func/params/test_show.py @@ -10,14 +10,14 @@ def test_show_empty(dvc): def test_show(tmp_dir, dvc): tmp_dir.gen("params.yaml", "foo: bar") - dvc.run(params=["foo"]) + dvc.run(params=["foo"], single_stage=True) assert dvc.params.show() == {"": {"params.yaml": {"foo": "bar"}}} def test_show_multiple(tmp_dir, dvc): tmp_dir.gen("params.yaml", "foo: bar\nbaz: qux\n") - dvc.run(fname="foo.dvc", params=["foo"]) - dvc.run(fname="baz.dvc", params=["baz"]) + dvc.run(fname="foo.dvc", params=["foo"], single_stage=True) + dvc.run(fname="baz.dvc", params=["baz"], single_stage=True) assert dvc.params.show() == { "": {"params.yaml": {"foo": "bar", "baz": "qux"}} } @@ -25,13 +25,13 @@ def test_show_multiple(tmp_dir, dvc): def test_show_list(tmp_dir, dvc): tmp_dir.gen("params.yaml", "foo:\n- bar\n- baz\n") - dvc.run(params=["foo"]) + dvc.run(params=["foo"], single_stage=True) assert dvc.params.show() == {"": {"params.yaml": {"foo": ["bar", "baz"]}}} def test_show_branch(tmp_dir, scm, dvc): tmp_dir.gen("params.yaml", "foo: bar") - dvc.run(params=["foo"]) + dvc.run(params=["foo"], single_stage=True) scm.add(["params.yaml", "Dvcfile"]) scm.commit("init") diff --git a/tests/func/test_get.py b/tests/func/test_get.py index 7185ed4c5b..582212ed2c 100644 --- a/tests/func/test_get.py +++ b/tests/func/test_get.py @@ -114,7 +114,9 @@ def test_non_cached_output(tmp_dir, erepo_dir): with erepo_dir.chdir(): erepo_dir.dvc.run( - outs_no_cache=[src], cmd="echo hello > non_cached_file" + outs_no_cache=[src], + cmd="echo hello > non_cached_file", + single_stage=True, ) erepo_dir.scm_add([src, src + ".dvc"], commit="add non-cached output") diff --git a/tests/func/test_import.py b/tests/func/test_import.py index ce49acc50f..53d28b88b5 100644 --- a/tests/func/test_import.py +++ b/tests/func/test_import.py @@ -142,7 +142,9 @@ def test_import_non_cached(erepo_dir, tmp_dir, dvc, scm): with erepo_dir.chdir(): erepo_dir.dvc.run( - cmd="echo hello > {}".format(src), outs_no_cache=[src], + cmd="echo hello > {}".format(src), + outs_no_cache=[src], + single_stage=True, ) erepo_dir.scm_add([fspath(erepo_dir / src)], commit="add a non-cached out") diff --git a/tests/func/test_ls.py b/tests/func/test_ls.py index af3842d69a..bcf3205741 100644 --- a/tests/func/test_ls.py +++ b/tests/func/test_ls.py @@ -43,6 +43,7 @@ def create_dvc_pipeline(tmp_dir, dvc): "outs": [os.path.join("out", "file")], "deps": ["dep"], "fname": "out.dvc", + "single_stage": True, } ) tmp_dir.scm_add(["out.dvc"], commit="run") diff --git a/tests/func/test_plot.py b/tests/func/test_plot.py index 6be11320f8..683192a331 100644 --- a/tests/func/test_plot.py +++ b/tests/func/test_plot.py @@ -27,7 +27,7 @@ def _remove_whitespace(value): def _run_with_metric(tmp_dir, metric_filename, commit=None, tag=None): - tmp_dir.dvc.run(metrics_no_cache=[metric_filename]) + tmp_dir.dvc.run(metrics_no_cache=[metric_filename], single_stage=True) if hasattr(tmp_dir.dvc, "scm"): tmp_dir.dvc.scm.add([metric_filename, metric_filename + ".dvc"]) if commit: diff --git a/tests/func/test_remote.py b/tests/func/test_remote.py index 6f56a4bd76..946ad69f10 100644 --- a/tests/func/test_remote.py +++ b/tests/func/test_remote.py @@ -241,7 +241,7 @@ def test_external_dir_resource_on_no_cache(tmp_dir, dvc, tmp_path_factory): dvc.cache.local = None with pytest.raises(RemoteCacheRequiredError): - dvc.run(deps=[fspath(external_dir)]) + dvc.run(deps=[fspath(external_dir)], single_stage=True) def test_push_order(tmp_dir, dvc, tmp_path_factory, mocker): diff --git a/tests/func/test_repo.py b/tests/func/test_repo.py index a178cfe198..cde0b37d69 100644 --- a/tests/func/test_repo.py +++ b/tests/func/test_repo.py @@ -15,7 +15,7 @@ def test_destroy(tmp_dir, dvc, run_copy): tmp_dir.dvc_gen("file", "text") tmp_dir.dvc_gen({"dir": {"file": "lorem", "subdir/file": "ipsum"}}) - run_copy("file", "file2") + run_copy("file", "file2", single_stage=True) run_copy("file2", "file3", name="copy-file2-file3") run_copy("file3", "file4", name="copy-file3-file4") @@ -66,13 +66,13 @@ def collect_outs(*args, **kwargs): ) tmp_dir.dvc_gen("foo", "foo") - run_copy("foo", "bar") + run_copy("foo", "bar", single_stage=True) scm.add([".gitignore", "foo.dvc", "bar.dvc"]) scm.commit("Add foo and bar") scm.checkout("new-branch", create_new=True) - run_copy("bar", "buzz") + run_copy("bar", "buzz", single_stage=True) scm.add([".gitignore", "buzz.dvc"]) scm.commit("Add buzz") diff --git a/tests/func/test_stage.py b/tests/func/test_stage.py index 711e76724e..9981b9a34b 100644 --- a/tests/func/test_stage.py +++ b/tests/func/test_stage.py @@ -97,6 +97,7 @@ def test_ignored_in_checksum(self): cmd="echo test > {}".format(self.FOO), deps=[self.BAR], outs=[self.FOO], + single_stage=True, ) d = stage.dumpd() @@ -124,6 +125,7 @@ def test_remote_output(self): main( [ "run", + "--single-stage", "-O", "remote://storage/file", "echo file > {path}".format(path=file_path), @@ -196,7 +198,7 @@ def test_parent_repo_collect_stages(tmp_dir, scm, dvc): def test_stage_addressing(tmp_dir, dvc, run_copy): tmp_dir.dvc_gen("foo", "foo") - stage1 = run_copy("foo", "bar") + stage1 = run_copy("foo", "bar", single_stage=True) assert stage1.addressing == "bar.dvc" stage2 = run_copy("bar", "baz", name="copy-bar-baz") diff --git a/tests/unit/command/test_run.py b/tests/unit/command/test_run.py index 08bbe3fb2d..e595b1db6e 100644 --- a/tests/unit/command/test_run.py +++ b/tests/unit/command/test_run.py @@ -63,6 +63,7 @@ def test_run(mocker, dvc): always_changed=True, cmd="command", name="nam", + single_stage=False, ) @@ -89,6 +90,7 @@ def test_run_args_from_cli(mocker, dvc): always_changed=False, cmd="echo foo", name=None, + single_stage=False, ) @@ -115,4 +117,5 @@ def test_run_args_with_spaces(mocker, dvc): always_changed=False, cmd='echo "foo bar"', name=None, + single_stage=False, ) diff --git a/tests/unit/repo/test_repo.py b/tests/unit/repo/test_repo.py index fbd3f11ef5..b4a95e0a8f 100644 --- a/tests/unit/repo/test_repo.py +++ b/tests/unit/repo/test_repo.py @@ -94,7 +94,7 @@ def test_skip_graph_checks(tmp_dir, dvc, mocker, run_copy): # sanity check tmp_dir.gen("foo", "foo text") dvc.add("foo") - run_copy("foo", "bar") + run_copy("foo", "bar", single_stage=True) assert mock_collect_graph.called # check that our hack can be enabled @@ -102,7 +102,7 @@ def test_skip_graph_checks(tmp_dir, dvc, mocker, run_copy): dvc._skip_graph_checks = True tmp_dir.gen("baz", "baz text") dvc.add("baz") - run_copy("baz", "qux") + run_copy("baz", "qux", single_stage=True) assert not mock_collect_graph.called # check that our hack can be disabled @@ -110,5 +110,5 @@ def test_skip_graph_checks(tmp_dir, dvc, mocker, run_copy): dvc._skip_graph_checks = False tmp_dir.gen("quux", "quux text") dvc.add("quux") - run_copy("quux", "quuz") + run_copy("quux", "quuz", single_stage=True) assert mock_collect_graph.called diff --git a/tests/unit/repo/test_reproduce.py b/tests/unit/repo/test_reproduce.py index 7df9603f36..1050e7660e 100644 --- a/tests/unit/repo/test_reproduce.py +++ b/tests/unit/repo/test_reproduce.py @@ -5,9 +5,15 @@ def test_get_active_graph(tmp_dir, dvc): (pre_foo_stage,) = tmp_dir.dvc_gen({"pre-foo": "pre-foo"}) - foo_stage = dvc.run(deps=["pre-foo"], outs=["foo"], cmd="echo foo > foo") - bar_stage = dvc.run(deps=["foo"], outs=["bar"], cmd="echo bar > bar") - baz_stage = dvc.run(deps=["foo"], outs=["baz"], cmd="echo baz > baz") + foo_stage = dvc.run( + single_stage=True, deps=["pre-foo"], outs=["foo"], cmd="echo foo > foo" + ) + bar_stage = dvc.run( + single_stage=True, deps=["foo"], outs=["bar"], cmd="echo bar > bar" + ) + baz_stage = dvc.run( + single_stage=True, deps=["foo"], outs=["baz"], cmd="echo baz > baz" + ) dvc.lock_stage("bar.dvc") @@ -31,10 +37,18 @@ def test_get_active_graph(tmp_dir, dvc): def test_number_reproduces(reproduce_stage_mock, tmp_dir, dvc): tmp_dir.dvc_gen({"pre-foo": "pre-foo"}) - dvc.run(deps=["pre-foo"], outs=["foo"], cmd="echo foo > foo") - dvc.run(deps=["foo"], outs=["bar"], cmd="echo bar > bar") - dvc.run(deps=["foo"], outs=["baz"], cmd="echo baz > baz") - dvc.run(deps=["bar"], outs=["boop"], cmd="echo boop > boop") + dvc.run( + single_stage=True, deps=["pre-foo"], outs=["foo"], cmd="echo foo > foo" + ) + dvc.run( + single_stage=True, deps=["foo"], outs=["bar"], cmd="echo bar > bar" + ) + dvc.run( + single_stage=True, deps=["foo"], outs=["baz"], cmd="echo baz > baz" + ) + dvc.run( + single_stage=True, deps=["bar"], outs=["boop"], cmd="echo boop > boop" + ) reproduce_stage_mock.reset_mock() diff --git a/tests/unit/test_stage.py b/tests/unit/test_stage.py index c7d41a6ef0..dcfb771c45 100644 --- a/tests/unit/test_stage.py +++ b/tests/unit/test_stage.py @@ -88,7 +88,7 @@ def test_stage_run_ignore_sigint(dvc, mocker): popen = mocker.patch.object(subprocess, "Popen", return_value=proc) signal_mock = mocker.patch("signal.signal") - dvc.run(cmd="path") + dvc.run(cmd="path", single_stage=True) assert popen.called_once() assert communicate.called_once_with() @@ -106,7 +106,7 @@ def test_always_changed(dvc): def test_stage_cache(tmp_dir, dvc, run_copy, mocker): tmp_dir.gen("dep", "dep") - stage = run_copy("dep", "out") + stage = run_copy("dep", "out", single_stage=True) with dvc.lock, dvc.state: stage.remove(remove_outs=True, force=True)