mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-04 23:09:44 +01:00
* dvc: use lockfile as yaml instead of json * refactor Dvcfile into Pipeline file and Single stage file * fix tests * dvc: fix outputs * add more tests for collection of outputs * add tests for data cloud/get/import/ls * tests: test for checkouts * Allow other checksums other than md5 * tests: use iterdir instead of os.listdir * cleanup errors reported by cc and ds * utils: throw DvcException instead of plain Exception * tests: use yaml.load instead of json.load * run: split assignments * Update dvc/stage/exceptions.py Co-authored-by: Ruslan Kuprieiev <[email protected]>
74 lines
2.0 KiB
Python
74 lines
2.0 KiB
Python
import pytest
|
|
|
|
from dvc.stage.exceptions import StageCommitError
|
|
from dvc.utils.stage import dump_stage_file
|
|
from dvc.utils.stage import load_stage_file
|
|
|
|
|
|
def test_commit_recursive(tmp_dir, dvc):
|
|
tmp_dir.gen({"dir": {"file": "text1", "subdir": {"file2": "text2"}}})
|
|
stages = dvc.add("dir", recursive=True, no_commit=True)
|
|
|
|
assert len(stages) == 2
|
|
assert dvc.status() != {}
|
|
|
|
dvc.commit("dir", recursive=True)
|
|
assert dvc.status() == {}
|
|
|
|
|
|
def test_commit_force(tmp_dir, dvc):
|
|
tmp_dir.gen({"dir": {"file": "text1", "file2": "text2"}})
|
|
(stage,) = dvc.add("dir", no_commit=True)
|
|
|
|
with dvc.state:
|
|
assert stage.outs[0].changed_cache()
|
|
|
|
tmp_dir.gen("dir/file", "file content modified")
|
|
|
|
with dvc.state:
|
|
assert stage.outs[0].changed_cache()
|
|
|
|
with pytest.raises(StageCommitError):
|
|
dvc.commit(stage.path)
|
|
|
|
with dvc.state:
|
|
assert stage.outs[0].changed_cache()
|
|
|
|
dvc.commit(stage.path, force=True)
|
|
assert dvc.status([stage.path]) == {}
|
|
|
|
|
|
@pytest.mark.parametrize("run_kw", [{}, {"name": "copy"}])
|
|
def test_commit_with_deps(tmp_dir, dvc, run_copy, run_kw):
|
|
tmp_dir.gen("foo", "foo")
|
|
(foo_stage,) = dvc.add("foo", no_commit=True)
|
|
assert foo_stage is not None
|
|
assert len(foo_stage.outs) == 1
|
|
|
|
stage = run_copy("foo", "file", no_commit=True, **run_kw)
|
|
assert stage is not None
|
|
assert len(stage.outs) == 1
|
|
|
|
with dvc.state:
|
|
assert foo_stage.outs[0].changed_cache()
|
|
assert stage.outs[0].changed_cache()
|
|
|
|
dvc.commit(stage.path, with_deps=True)
|
|
with dvc.state:
|
|
assert not foo_stage.outs[0].changed_cache()
|
|
assert not stage.outs[0].changed_cache()
|
|
|
|
|
|
def test_commit_changed_md5(tmp_dir, dvc):
|
|
tmp_dir.gen({"file": "file content"})
|
|
(stage,) = dvc.add("file", no_commit=True)
|
|
|
|
stage_file_content = load_stage_file(stage.path)
|
|
stage_file_content["md5"] = "1111111111"
|
|
dump_stage_file(stage.path, stage_file_content)
|
|
|
|
with pytest.raises(StageCommitError):
|
|
dvc.commit(stage.path)
|
|
|
|
dvc.commit(stage.path, force=True)
|