mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
* dvc: refactor config
Advantages:
- read like a dict
- modify as a dict for testing or manipulation purposes
- wrap modifications into context manager to save them:
with config.edit("local") as conf:
conf["core"]["remote"] = "new-default"
Design decisions:
- dropped string constants
- remote sections are parsed into a simple subdict upon load
- remote config schema is now defined by url scheme
- relative paths are handled transparently upon load/save
- user config and remote manipulations are moved to commands
- same dev manipulations are done by simply modifying a config dict
* test: do not set cache.type for remotes that doesn't support it
* dvc: fix windows absolute paths validation in config
* test: fix windows separate drive test
* dvc: stylistic fixes in config
74 lines
2.0 KiB
Python
74 lines
2.0 KiB
Python
import os
|
|
|
|
from dvc.scm.git.tree import GitTree
|
|
from dvc.cache import Cache
|
|
from dvc.repo import Repo
|
|
from dvc.system import System
|
|
from dvc.compat import fspath
|
|
|
|
|
|
def test_destroy(tmp_dir, dvc):
|
|
dvc.config["cache"]["type"] = ["symlink"]
|
|
dvc.cache = Cache(dvc)
|
|
|
|
tmp_dir.dvc_gen("file", "text")
|
|
tmp_dir.dvc_gen({"dir": {"file": "lorem", "subdir/file": "ipsum"}})
|
|
|
|
dvc.destroy()
|
|
|
|
# Remove all the files related to DVC
|
|
for path in [".dvc", "file.dvc", "dir.dvc"]:
|
|
assert not (tmp_dir / path).exists()
|
|
|
|
# Leave the rest of the files
|
|
for path in ["file", "dir/file", "dir/subdir/file"]:
|
|
assert (tmp_dir / path).is_file()
|
|
|
|
# Make sure that data was unprotected after `destroy`
|
|
for path in ["file", "dir", "dir/file", "dir/subdir", "dir/subdir/file"]:
|
|
assert not System.is_symlink(fspath(tmp_dir / path))
|
|
|
|
|
|
def test_collect(tmp_dir, scm, dvc, run_copy):
|
|
def collect_outs(*args, **kwargs):
|
|
return set(
|
|
str(out)
|
|
for stage in dvc.collect(*args, **kwargs)
|
|
for out in stage.outs
|
|
)
|
|
|
|
tmp_dir.dvc_gen("foo", "foo")
|
|
run_copy("foo", "bar")
|
|
scm.add([".gitignore", "foo.dvc", "bar.dvc"])
|
|
scm.commit("Add foo and bar")
|
|
|
|
scm.checkout("new-branch", create_new=True)
|
|
|
|
run_copy("bar", "buzz")
|
|
scm.add([".gitignore", "buzz.dvc"])
|
|
scm.commit("Add buzz")
|
|
|
|
assert collect_outs("bar.dvc", with_deps=True) == {"foo", "bar"}
|
|
|
|
dvc.tree = GitTree(scm.repo, "new-branch")
|
|
|
|
assert collect_outs("buzz.dvc", with_deps=True) == {"foo", "bar", "buzz"}
|
|
assert collect_outs("buzz.dvc", with_deps=False) == {"buzz"}
|
|
|
|
|
|
def test_stages(tmp_dir, dvc):
|
|
def stages():
|
|
return set(stage.relpath for stage in Repo(fspath(tmp_dir)).stages)
|
|
|
|
tmp_dir.dvc_gen({"file": "a", "dir/file": "b", "dir/subdir/file": "c"})
|
|
|
|
assert stages() == {
|
|
"file.dvc",
|
|
os.path.join("dir", "file.dvc"),
|
|
os.path.join("dir", "subdir", "file.dvc"),
|
|
}
|
|
|
|
tmp_dir.gen(".dvcignore", "dir")
|
|
|
|
assert stages() == {"file.dvc"}
|