mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
get: test: from non-dvc master: refactor
This commit is contained in:
@@ -84,7 +84,10 @@ def _git_checkout(repo_path, revision):
|
||||
from dvc.scm import Git
|
||||
|
||||
git = Git(repo_path)
|
||||
git.checkout(revision)
|
||||
try:
|
||||
git.checkout(revision)
|
||||
finally:
|
||||
git.close()
|
||||
|
||||
|
||||
def clean_repos():
|
||||
|
||||
+1
-7
@@ -13,7 +13,7 @@ from .basic_env import TestGitFixture
|
||||
from dvc.remote.config import RemoteConfig
|
||||
from dvc.remote.ssh.connection import SSHConnection
|
||||
from dvc.repo import Repo as DvcRepo
|
||||
from dvc.utils.compat import cast_bytes_py2, fspath
|
||||
from dvc.utils.compat import cast_bytes_py2
|
||||
|
||||
# Prevent updater and analytics from running their processes
|
||||
os.environ[cast_bytes_py2("DVC_TEST")] = cast_bytes_py2("true")
|
||||
@@ -190,9 +190,3 @@ def git_erepo():
|
||||
repo.setUp()
|
||||
yield repo
|
||||
repo.tearDown()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def empty_dir(tmp_path, monkeypatch):
|
||||
monkeypatch.chdir(tmp_path)
|
||||
return fspath(tmp_path)
|
||||
|
||||
+7
-31
@@ -9,10 +9,10 @@ import pytest
|
||||
from dvc.config import Config
|
||||
from dvc.exceptions import GetDVCFileError
|
||||
from dvc.exceptions import UrlNotDvcRepoError
|
||||
from dvc.remote import RemoteConfig
|
||||
from dvc.repo import Repo
|
||||
from dvc.system import System
|
||||
from dvc.utils import makedirs
|
||||
from dvc.utils.compat import fspath
|
||||
from tests.utils import trees_equal
|
||||
|
||||
|
||||
@@ -91,41 +91,17 @@ def test_get_to_dir(dname, erepo):
|
||||
assert filecmp.cmp(erepo.FOO, dst, shallow=False)
|
||||
|
||||
|
||||
def test_get_from_non_dvc_master(empty_dir, git_erepo, caplog):
|
||||
storage = git_erepo.mkdtemp()
|
||||
|
||||
dvc_branch = "dvc_test"
|
||||
git_erepo.git.git.checkout("master", b=dvc_branch)
|
||||
|
||||
dvc_repo = Repo.init(git_erepo._root_dir)
|
||||
stage, = dvc_repo.add([git_erepo.FOO])
|
||||
|
||||
rconfig = RemoteConfig(dvc_repo.config)
|
||||
rconfig.add("upstream", storage, default=True)
|
||||
|
||||
dvc_repo.push()
|
||||
dvc_repo.scm.add([dvc_repo.config.config_file])
|
||||
|
||||
dvc_repo.scm.add([".dvc", stage.relpath])
|
||||
dvc_repo.scm.commit("dvc branch initial")
|
||||
|
||||
git_erepo.git.git.checkout("master")
|
||||
|
||||
os.chdir(empty_dir)
|
||||
def test_get_from_non_dvc_master(erepo, tmp_path, monkeypatch, caplog):
|
||||
monkeypatch.chdir(fspath(tmp_path))
|
||||
erepo.dvc.scm.repo.index.remove([".dvc"], r=True)
|
||||
erepo.dvc.scm.commit("remove .dvc")
|
||||
|
||||
caplog.clear()
|
||||
imported_file = "foo_imported"
|
||||
with caplog.at_level(logging.INFO, logger="dvc"):
|
||||
Repo.get(
|
||||
git_erepo._root_dir,
|
||||
git_erepo.FOO,
|
||||
out=imported_file,
|
||||
rev=dvc_branch,
|
||||
)
|
||||
Repo.get(erepo._root_dir, erepo.FOO, out=imported_file, rev="branch")
|
||||
|
||||
assert caplog.text == ""
|
||||
assert filecmp.cmp(
|
||||
os.path.join(git_erepo._root_dir, git_erepo.FOO),
|
||||
imported_file,
|
||||
shallow=False,
|
||||
os.path.join(erepo._root_dir, erepo.FOO), imported_file, shallow=False
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user