Skip to content

Commit

Permalink
tests: use --single-stage
Browse files Browse the repository at this point in the history
  • Loading branch information
efiop committed May 4, 2020
1 parent bc7f177 commit 93d7b91
Show file tree
Hide file tree
Showing 15 changed files with 71 additions and 47 deletions.
16 changes: 8 additions & 8 deletions tests/func/metrics/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -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))

Expand All @@ -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))

Expand All @@ -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))

Expand All @@ -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")

Expand All @@ -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": {
Expand All @@ -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")

Expand All @@ -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")

Expand Down
12 changes: 6 additions & 6 deletions tests/func/metrics/test_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
16 changes: 8 additions & 8 deletions tests/func/params/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ 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() == {}


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")

Expand All @@ -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"}}
Expand All @@ -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")

Expand All @@ -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")

Expand All @@ -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")

Expand All @@ -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")

Expand All @@ -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")

Expand Down
10 changes: 5 additions & 5 deletions tests/func/params/test_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@ 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"}}
}


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")

Expand Down
4 changes: 3 additions & 1 deletion tests/func/test_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
4 changes: 3 additions & 1 deletion tests/func/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions tests/func/test_ls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion tests/func/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/func/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions tests/func/test_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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")

Expand Down
4 changes: 3 additions & 1 deletion tests/func/test_stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -124,6 +125,7 @@ def test_remote_output(self):
main(
[
"run",
"--single-stage",
"-O",
"remote://storage/file",
"echo file > {path}".format(path=file_path),
Expand Down Expand Up @@ -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")
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/command/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def test_run(mocker, dvc):
always_changed=True,
cmd="command",
name="nam",
single_stage=False,
)


Expand All @@ -89,6 +90,7 @@ def test_run_args_from_cli(mocker, dvc):
always_changed=False,
cmd="echo foo",
name=None,
single_stage=False,
)


Expand All @@ -115,4 +117,5 @@ def test_run_args_with_spaces(mocker, dvc):
always_changed=False,
cmd='echo "foo bar"',
name=None,
single_stage=False,
)
6 changes: 3 additions & 3 deletions tests/unit/repo/test_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,21 @@ 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
mock_collect_graph.reset_mock()
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
mock_collect_graph.reset_mock()
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
Loading

0 comments on commit 93d7b91

Please sign in to comment.