Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dvc/dependency/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def _get_checksum(self, locked=True):

# We are polluting our repo cache with some dir listing here
if tree.isdir(path):
return self.repo.cache.local.get_hash(path, tree)
return self.repo.cache.local.get_hash(path, tree=tree)
return tree.get_file_hash(path)

def status(self):
Expand Down
11 changes: 11 additions & 0 deletions tests/dir_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,17 @@ def branch(self, name, new=False):
finally:
self.scm.checkout(old)

def read_text(self, *args, **kwargs): # pylint: disable=signature-differs
# NOTE: on windows we'll get PermissionError instead of
# IsADirectoryError when we try to `open` a directory, so we can't
# rely on exception flow control
if self.is_dir():
return {
path.name: path.read_text(*args, **kwargs)
for path in self.iterdir()
}
return super().read_text(*args, **kwargs)


def _coerce_filenames(filenames):
if isinstance(filenames, (str, bytes, pathlib.PurePath)):
Expand Down
8 changes: 2 additions & 6 deletions tests/func/test_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from dvc.repo.get import GetDVCFileError
from dvc.system import System
from dvc.utils.fs import makedirs
from tests.utils import trees_equal


def test_get_repo_file(tmp_dir, erepo_dir):
Expand All @@ -29,8 +28,7 @@ def test_get_repo_dir(tmp_dir, erepo_dir):

Repo.get(os.fspath(erepo_dir), "dir", "dir_imported")

assert os.path.isdir("dir_imported")
trees_equal(erepo_dir / "dir", "dir_imported")
assert (tmp_dir / "dir_imported").read_text() == {"file": "contents"}


@pytest.mark.parametrize(
Expand All @@ -44,7 +42,6 @@ def test_get_git_file(tmp_dir, erepo):

Repo.get(os.fspath(erepo), src, dst)

assert (tmp_dir / dst).is_file()
assert (tmp_dir / dst).read_text() == "hello"


Expand All @@ -61,8 +58,7 @@ def test_get_git_dir(tmp_dir, erepo):

Repo.get(os.fspath(erepo), src, dst)

assert (tmp_dir / dst).is_dir()
trees_equal(erepo / src, tmp_dir / dst)
assert (tmp_dir / dst).read_text() == {"dir": {"file.txt": "hello"}}


def test_cache_type_is_properly_overridden(tmp_dir, erepo_dir):
Expand Down
10 changes: 3 additions & 7 deletions tests/func/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from dvc.exceptions import DownloadError, PathMissingError
from dvc.system import System
from dvc.utils.fs import makedirs, remove
from tests.utils import trees_equal


def test_import(tmp_dir, scm, dvc, erepo_dir):
Expand Down Expand Up @@ -73,8 +72,7 @@ def test_import_git_dir(tmp_dir, scm, dvc, git_dir, src_is_dvc):

stage = dvc.imp(os.fspath(git_dir), "src", "dst")

assert (tmp_dir / "dst").is_dir()
trees_equal(git_dir / "src", tmp_dir / "dst")
assert (tmp_dir / "dst").read_text() == {"file.txt": "hello"}
assert tmp_dir.scm.repo.git.check_ignore(os.fspath(tmp_dir / "dst"))
assert stage.deps[0].def_repo == {
"url": os.fspath(git_dir),
Expand All @@ -88,8 +86,7 @@ def test_import_dir(tmp_dir, scm, dvc, erepo_dir):

stage = dvc.imp(os.fspath(erepo_dir), "dir", "dir_imported")

assert os.path.isdir("dir_imported")
trees_equal(erepo_dir / "dir", "dir_imported")
assert (tmp_dir / "dir_imported").read_text() == {"foo": "foo content"}
assert scm.repo.git.check_ignore("dir_imported")
assert stage.deps[0].def_repo == {
"url": os.fspath(erepo_dir),
Expand Down Expand Up @@ -222,8 +219,7 @@ def test_pull_imported_directory_stage(tmp_dir, dvc, erepo_dir):

dvc.pull(["dir_imported.dvc"])

assert os.path.isdir("dir_imported")
trees_equal(erepo_dir / "dir", "dir_imported")
assert (tmp_dir / "dir_imported").read_text() == {"foo": "foo content"}


def test_download_error_pulling_imported_stage(tmp_dir, dvc, erepo_dir):
Expand Down
51 changes: 47 additions & 4 deletions tests/func/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,69 @@ def test_update_import(tmp_dir, dvc, erepo_dir, cached):
gen = erepo_dir.dvc_gen if cached else erepo_dir.scm_gen

with erepo_dir.branch("branch", new=True), erepo_dir.chdir():
gen("version", "branch", "add version file")
gen(
{
"version": "branch",
"dir": {"version": "branch", "subdir": {"file": "file"}},
},
commit="add version file",
)
old_rev = erepo_dir.scm.get_rev()

stage = dvc.imp(os.fspath(erepo_dir), "version", "version", rev="branch")
dir_stage = dvc.imp(os.fspath(erepo_dir), "dir", "dir", rev="branch")
assert dvc.status() == {}

assert (tmp_dir / "version").read_text() == "branch"
assert (tmp_dir / "dir").read_text() == {
"version": "branch",
"subdir": {"file": "file"},
}
assert stage.deps[0].def_repo["rev_lock"] == old_rev
assert dir_stage.deps[0].def_repo["rev_lock"] == old_rev

# Update version file
with erepo_dir.branch("branch", new=False), erepo_dir.chdir():
gen("version", "updated", "update version content")
gen(
{
"version": "updated",
"dir": {"version": "updated", "subdir": {"file": "file"}},
},
commit="update version content",
)
new_rev = erepo_dir.scm.get_rev()

assert old_rev != new_rev

dvc.update([stage.path])
assert dvc.status() == {
"dir.dvc": [
{
"changed deps": {
f"dir ({os.fspath(erepo_dir)})": "update available"
}
}
],
"version.dvc": [
{
"changed deps": {
f"version ({os.fspath(erepo_dir)})": "update available"
}
}
],
}

(stage,) = dvc.update(stage.path)
(dir_stage,) = dvc.update(dir_stage.path)
assert dvc.status() == {}

assert (tmp_dir / "version").read_text() == "updated"
assert (tmp_dir / "dir").read_text() == {
"version": "updated",
"subdir": {"file": "file"},
}

stage = Dvcfile(dvc, stage.path).stage
assert stage.deps[0].def_repo["rev_lock"] == new_rev
assert dir_stage.deps[0].def_repo["rev_lock"] == new_rev


def test_update_import_after_remote_updates_to_dvc(tmp_dir, dvc, erepo_dir):
Expand Down
11 changes: 0 additions & 11 deletions tests/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
from contextlib import contextmanager
from filecmp import dircmp

from dvc.scm import Git

Expand All @@ -20,15 +19,5 @@ def cd(newdir):
os.chdir(prevdir)


def trees_equal(dir_path_1, dir_path_2):

comparison = dircmp(dir_path_1, dir_path_2)

assert set(comparison.left_only) == set(comparison.right_only) == set()

for d in comparison.common_dirs:
trees_equal(os.path.join(dir_path_1, d), os.path.join(dir_path_2, d))


def to_posixpath(path):
return path.replace("\\", "/")