mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-18 23:10:14 +01:00
install: tests: migrate to dir helpers
This commit is contained in:
+39
-46
@@ -1,12 +1,12 @@
|
||||
import os
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
from dvc.exceptions import GitHookAlreadyExistsError
|
||||
from dvc.main import main
|
||||
from dvc.stage import Stage
|
||||
from dvc.utils import file_md5
|
||||
from dvc.remote import RemoteConfig
|
||||
from dvc.utils import file_md5, fspath
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
@@ -14,10 +14,10 @@ from dvc.utils import file_md5
|
||||
)
|
||||
class TestInstall(object):
|
||||
def _hook(self, name):
|
||||
return os.path.join(".git", "hooks", name)
|
||||
return pathlib.Path(".git") / "hooks" / name
|
||||
|
||||
def test_should_create_hooks(self, git, dvc_repo):
|
||||
assert main(["install"]) == 0
|
||||
def test_should_create_hooks(self, scm, dvc):
|
||||
scm.install()
|
||||
|
||||
hooks_with_commands = [
|
||||
("post-checkout", "exec dvc checkout"),
|
||||
@@ -26,55 +26,48 @@ class TestInstall(object):
|
||||
]
|
||||
|
||||
for fname, command in hooks_with_commands:
|
||||
assert os.path.isfile(self._hook(fname))
|
||||
hook_path = self._hook(fname)
|
||||
assert hook_path.is_file()
|
||||
assert command in hook_path.read_text()
|
||||
|
||||
with open(self._hook(fname), "r") as fobj:
|
||||
assert command in fobj.read()
|
||||
|
||||
def test_should_fail_if_file_already_exists(self, git, dvc_repo):
|
||||
with open(self._hook("post-checkout"), "w") as fobj:
|
||||
fobj.write("hook content")
|
||||
def test_should_fail_if_file_already_exists(self, scm):
|
||||
self._hook("post-checkout").write_text("hook content")
|
||||
|
||||
with pytest.raises(GitHookAlreadyExistsError):
|
||||
dvc_repo.scm.install()
|
||||
scm.install()
|
||||
|
||||
def test_should_post_checkout_hook_checkout(self, repo_dir, git, dvc_repo):
|
||||
assert main(["install"]) == 0
|
||||
def test_should_post_checkout_hook_checkout(self, tmp_dir, scm, dvc):
|
||||
scm.install()
|
||||
tmp_dir.dvc_gen({"file": "file content"}, commit="add")
|
||||
|
||||
stage_file = repo_dir.FOO + Stage.STAGE_FILE_SUFFIX
|
||||
os.unlink("file")
|
||||
scm.checkout("new_branch", create_new=True)
|
||||
|
||||
dvc_repo.add(repo_dir.FOO)
|
||||
dvc_repo.scm.add([".gitignore", stage_file])
|
||||
dvc_repo.scm.commit("add")
|
||||
assert os.path.isfile("file")
|
||||
|
||||
os.unlink(repo_dir.FOO)
|
||||
dvc_repo.scm.checkout("new_branch", create_new=True)
|
||||
def test_should_pre_push_hook_push(
|
||||
self, tmp_dir, scm, dvc, tmp_path_factory
|
||||
):
|
||||
scm.install()
|
||||
|
||||
assert os.path.isfile(repo_dir.FOO)
|
||||
temp = tmp_path_factory.mktemp("external")
|
||||
git_remote = temp / "project.git"
|
||||
storage_path = temp / "dvc_storage"
|
||||
|
||||
def test_should_pre_push_hook_push(self, repo_dir, git, dvc_repo):
|
||||
assert main(["install"]) == 0
|
||||
RemoteConfig(dvc.config).add(
|
||||
"store", fspath(storage_path), default=True
|
||||
)
|
||||
tmp_dir.dvc_gen("file", "file_content", "commit message")
|
||||
|
||||
temp = repo_dir.mkdtemp()
|
||||
git_remote = os.path.join(temp, "project.git")
|
||||
storage_path = os.path.join(temp, "dvc_storage")
|
||||
file_checksum = file_md5("file")[0]
|
||||
expected_storage_path = (
|
||||
storage_path / file_checksum[:2] / file_checksum[2:]
|
||||
)
|
||||
|
||||
foo_checksum = file_md5(repo_dir.FOO)[0]
|
||||
expected_cache_path = dvc_repo.cache.local.get(foo_checksum)
|
||||
scm.repo.clone(fspath(git_remote))
|
||||
scm.repo.create_remote("origin", fspath(git_remote))
|
||||
|
||||
ret = main(["remote", "add", "-d", "store", storage_path])
|
||||
assert ret == 0
|
||||
|
||||
ret = main(["add", repo_dir.FOO])
|
||||
assert ret == 0
|
||||
|
||||
stage_file = repo_dir.FOO + Stage.STAGE_FILE_SUFFIX
|
||||
dvc_repo.scm.repo.index.add([stage_file, ".gitignore"])
|
||||
dvc_repo.scm.repo.index.commit("commit message")
|
||||
|
||||
dvc_repo.scm.repo.clone(git_remote)
|
||||
dvc_repo.scm.repo.create_remote("origin", git_remote)
|
||||
|
||||
dvc_repo.scm.repo.git.push("origin", "master")
|
||||
|
||||
assert os.path.isfile(expected_cache_path)
|
||||
assert not expected_storage_path.is_file()
|
||||
scm.repo.git.push("origin", "master")
|
||||
assert expected_storage_path.is_file()
|
||||
assert expected_storage_path.read_text() == "file_content"
|
||||
|
||||
Reference in New Issue
Block a user