Skip to content
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
52 changes: 51 additions & 1 deletion tests/func/test_get.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import logging
import os

import mock
import pytest

from dvc.cache import Cache
from dvc.exceptions import PathMissingError
from dvc.exceptions import ConfirmRemoveError, PathMissingError
from dvc.external_repo import IsADVCRepoError
from dvc.main import main
from dvc.repo import Repo
Expand All @@ -24,6 +25,55 @@ def test_get_repo_file(tmp_dir, erepo_dir):
assert (tmp_dir / "file_imported").read_text() == "contents"


def test_get_repo_file_replace_without_confirmation(tmp_dir, erepo_dir):
with erepo_dir.chdir():
erepo_dir.dvc_gen("file", "contents", commit="create file")
erepo_dir.dvc_gen(
"file2", "something different", commit="create file2"
)

Repo.get(os.fspath(erepo_dir), "file", "file_imported")
# getting another file with a name that already exists in Repo.
with pytest.raises(ConfirmRemoveError):
Repo.get(os.fspath(erepo_dir), "file2", "file_imported")

assert os.path.isfile("file_imported")
assert (tmp_dir / "file_imported").read_text() == "contents"


def test_get_repo_file_replace_yes(tmp_dir, erepo_dir):
with erepo_dir.chdir():
erepo_dir.dvc_gen("file", "contents", commit="create file")
erepo_dir.dvc_gen(
"file2", "something different", commit="create file2"
)

Repo.get(os.fspath(erepo_dir), "file", "file_imported")
# getting another file with a name that already exists in Repo.
with mock.patch("dvc.prompt.confirm", return_value=True):
Repo.get(os.fspath(erepo_dir), "file2", "file_imported")

assert os.path.isfile("file_imported")
assert (tmp_dir / "file_imported").read_text() == "something different"


def test_get_repo_file_replace_no(tmp_dir, erepo_dir):
with erepo_dir.chdir():
erepo_dir.dvc_gen("file", "contents", commit="create file")
erepo_dir.dvc_gen(
"file2", "something different", commit="create file2"
)

Repo.get(os.fspath(erepo_dir), "file", "file_imported")
# getting another file with a name that already exists in Repo.
with mock.patch("dvc.prompt.confirm", return_value=False):
with pytest.raises(ConfirmRemoveError):
Repo.get(os.fspath(erepo_dir), "file2", "file_imported")

assert os.path.isfile("file_imported")
assert (tmp_dir / "file_imported").read_text() == "contents"


def test_get_repo_dir(tmp_dir, erepo_dir):
with erepo_dir.chdir():
erepo_dir.dvc_gen({"dir": {"file": "contents"}}, commit="create dir")
Expand Down