/
test_external_repo.py
37 lines (26 loc) 路 1.13 KB
/
test_external_repo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import os
from mock import patch
from dvc.repo import Repo
from dvc.external_repo import external_repo
from dvc.scm.git import Git
from dvc.utils.fs import path_isin
def test_external_repo(erepo):
url = erepo.root_dir
# We will share cache dir, to fetch version file
cache_dir = erepo.dvc.cache.local.cache_dir
with patch.object(Git, "clone", wraps=Git.clone) as mock:
with external_repo(url, cache_dir=cache_dir) as repo:
with repo.open(os.path.join(repo.root_dir, "version")) as fd:
assert fd.read() == "master"
with external_repo(url, rev="branch", cache_dir=cache_dir) as repo:
with repo.open(os.path.join(repo.root_dir, "version")) as fd:
assert fd.read() == "branch"
# Check cache_dir is unset
with external_repo(url) as repo:
assert path_isin(repo.cache.local.cache_dir, repo.root_dir)
assert mock.call_count == 1
def test_external_repo_import_without_remote(erepo, dvc_repo):
src = erepo.CODE
dst = dvc_repo.root_dir
Repo.get(erepo.root_dir, src, dst)
assert os.path.exists(dst + "/" + erepo.CODE)