Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: test: convert to dir helpers 1 #2898

Merged
merged 1 commit into from
Dec 6, 2019
Merged
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
46 changes: 24 additions & 22 deletions tests/func/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,20 @@ def test(self):
self.assertTrue(stages[0] is not None)


def test_add_file_in_dir(repo_dir, dvc_repo):
stage, = dvc_repo.add(repo_dir.DATA_SUB)
def test_add_file_in_dir(tmp_dir, dvc):
tmp_dir.gen({"dir": {"subdir": {"subdata": "subdata content"}}})
subdir_path = os.path.join("dir", "subdir", "subdata")

stage, = dvc.add(subdir_path)

assert stage is not None
assert len(stage.deps) == 0
assert len(stage.outs) == 1
assert stage.relpath == repo_dir.DATA_SUB + ".dvc"
assert stage.relpath == subdir_path + ".dvc"

# Current dir should not be taken into account
assert stage.wdir == os.path.dirname(stage.path)
assert stage.outs[0].def_path == "data_sub"
assert stage.outs[0].def_path == "subdata"


class TestAddExternalLocalFile(TestDvc):
Expand Down Expand Up @@ -529,37 +532,36 @@ def test_windows_should_add_when_cache_on_different_drive(
assert ret == 0


def test_readding_dir_should_not_unprotect_all(dvc_repo, repo_dir):
dvc_repo.cache.local.cache_types = ["symlink"]
dvc_repo.cache.local.protected = True
def test_readding_dir_should_not_unprotect_all(tmp_dir, dvc, mocker):
tmp_dir.gen("dir/data", "data")

dvc_repo.add(repo_dir.DATA_DIR)
new_file = os.path.join(repo_dir.DATA_DIR, "new_file")
dvc.cache.local.cache_types = ["symlink"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add an empty line after tmp_dir.gen(), up to you.

dvc.cache.local.protected = True

repo_dir.create(new_file, "new_content")
dvc.add("dir")
tmp_dir.gen("dir/new_file", "new_file_content")

unprotect_spy = spy(RemoteLOCAL.unprotect)
with patch.object(RemoteLOCAL, "unprotect", unprotect_spy):
dvc_repo.add(repo_dir.DATA_DIR)
mocker.patch.object(RemoteLOCAL, "unprotect", unprotect_spy)
dvc.add("dir")

assert not unprotect_spy.mock.called
assert System.is_symlink(new_file)
assert System.is_symlink(os.path.join("dir", "new_file"))


def test_should_not_checkout_when_adding_cached_copy(repo_dir, dvc_repo):
dvc_repo.cache.local.cache_types = ["copy"]
def test_should_not_checkout_when_adding_cached_copy(tmp_dir, dvc, mocker):
dvc.cache.local.cache_types = ["copy"]

dvc_repo.add(repo_dir.FOO)
dvc_repo.add(repo_dir.BAR)
tmp_dir.dvc_gen({"foo": "foo", "bar": "bar"})

shutil.copy(repo_dir.BAR, repo_dir.FOO)
shutil.copy("bar", "foo")

copy_spy = spy(dvc_repo.cache.local.copy)
copy_spy = spy(dvc.cache.local.copy)
mocker.patch.object(dvc.cache.local, "copy", copy_spy)

with patch.object(dvc_repo.cache.local, "copy", copy_spy):
dvc_repo.add(repo_dir.FOO)
dvc.add("foo")

assert copy_spy.mock.call_count == 0
assert copy_spy.mock.call_count == 0


@pytest.mark.parametrize(
Expand Down