mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
erepo: refactor download/fetch logic (#5234)
* erepo: don't use _get_tree_for * erepo: refactor download/fetch logic * dvc: unify handling existing output
This commit is contained in:
+18
-48
@@ -1,12 +1,9 @@
|
||||
import logging
|
||||
import os
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
|
||||
from dvc.cache import Cache
|
||||
from dvc.exceptions import ConfirmRemoveError, PathMissingError
|
||||
from dvc.external_repo import IsADVCRepoError
|
||||
from dvc.main import main
|
||||
from dvc.repo import Repo
|
||||
from dvc.repo.get import GetDVCFileError
|
||||
@@ -34,46 +31,13 @@ def test_get_repo_file_replace_without_confirmation(tmp_dir, erepo_dir):
|
||||
|
||||
Repo.get(os.fspath(erepo_dir), "file", "file_imported")
|
||||
# getting another file with a name that already exists in Repo.
|
||||
with pytest.raises(ConfirmRemoveError):
|
||||
with pytest.raises(FileExistsError):
|
||||
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")
|
||||
@@ -187,17 +151,17 @@ def test_non_cached_output(tmp_dir, erepo_dir):
|
||||
|
||||
# https://github.com/iterative/dvc/pull/2837#discussion_r352123053
|
||||
def test_absolute_file_outside_repo(tmp_dir, erepo_dir):
|
||||
with pytest.raises(PathMissingError):
|
||||
with pytest.raises(FileNotFoundError):
|
||||
Repo.get(os.fspath(erepo_dir), "/root/")
|
||||
|
||||
|
||||
def test_absolute_file_outside_git_repo(tmp_dir, git_dir):
|
||||
with pytest.raises(PathMissingError):
|
||||
with pytest.raises(FileNotFoundError):
|
||||
Repo.get(os.fspath(git_dir), "/root/")
|
||||
|
||||
|
||||
def test_unknown_path(tmp_dir, erepo_dir):
|
||||
with pytest.raises(PathMissingError):
|
||||
with pytest.raises(FileNotFoundError):
|
||||
Repo.get(os.fspath(erepo_dir), "a_non_existing_file")
|
||||
|
||||
|
||||
@@ -345,17 +309,23 @@ def test_granular_get_from_subrepos(tmp_dir, erepo_dir):
|
||||
assert (tmp_dir / "out").read_text() == "bar"
|
||||
|
||||
|
||||
def test_try_to_get_complete_repo(tmp_dir, dvc, erepo_dir):
|
||||
def test_get_complete_repo(tmp_dir, dvc, erepo_dir):
|
||||
with erepo_dir.chdir():
|
||||
erepo_dir.dvc_gen({"foo": "foo"}, commit="add foo")
|
||||
|
||||
subrepo = erepo_dir / "subrepo"
|
||||
make_subrepo(subrepo, erepo_dir.scm)
|
||||
with subrepo.chdir():
|
||||
subrepo.dvc_gen({"dir": {"bar": "bar"}}, commit="files in subrepo")
|
||||
|
||||
expected_message = "Cannot fetch a complete DVC repository"
|
||||
with pytest.raises(IsADVCRepoError) as exc_info:
|
||||
Repo.get(os.fspath(erepo_dir), "subrepo", out="out")
|
||||
assert f"{expected_message} 'subrepo'" == str(exc_info.value)
|
||||
Repo.get(os.fspath(erepo_dir), "subrepo", out="out_sub")
|
||||
assert (tmp_dir / "out_sub").read_text() == {
|
||||
".gitignore": "/dir\n",
|
||||
"dir": {"bar": "bar"},
|
||||
}
|
||||
|
||||
with pytest.raises(IsADVCRepoError) as exc_info:
|
||||
Repo.get(os.fspath(erepo_dir), ".", out="out")
|
||||
assert expected_message == str(exc_info.value)
|
||||
Repo.get(os.fspath(erepo_dir), ".", out="out")
|
||||
assert (tmp_dir / "out").read_text() == {
|
||||
".gitignore": "/foo\n",
|
||||
"foo": "foo",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user