Skip to content

Commit af42531

Browse files
committed
tests: api: roll back erepo usage
1 parent 020c049 commit af42531

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

tests/func/test_api.py

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from dvc import api
99
from dvc.api import SummonError
10+
from dvc.compat import fspath
1011
from dvc.exceptions import FileMissingError
1112
from dvc.main import main
1213
from dvc.path_info import URLInfo
@@ -82,16 +83,15 @@ def test_open_external(remote_url, erepo_dir):
8283

8384

8485
@pytest.mark.parametrize("remote_url", all_remote_params, indirect=True)
85-
def test_missing(remote_url, tmp_dir, erepo_dir, monkeypatch):
86-
_set_remote_url_and_commit(erepo_dir.dvc, remote_url)
87-
with monkeypatch.context() as m:
88-
m.chdir(fspath(erepo_dir))
86+
def test_missing(remote_url, tmp_dir, dvc):
87+
tmp_dir.dvc_gen("foo", "foo")
88+
run_dvc("remote", "add", "-d", "upstream", remote_url)
8989

9090
# Remove cache to make foo missing
91-
shutil.rmtree(erepo_dir.dvc.cache.local.cache_dir)
91+
shutil.rmtree(dvc.cache.local.cache_dir)
9292

9393
with pytest.raises(FileMissingError):
94-
api.read("foo", repo=fspath(erepo_dir))
94+
api.read("foo")
9595

9696

9797
def _set_remote_url_and_commit(repo, remote_url):
@@ -108,27 +108,23 @@ def test_open_scm_controlled(tmp_dir, erepo_dir):
108108
assert fd.read() == "file content"
109109

110110

111-
def test_open_not_cached(dvc, erepo_dir, monkeypatch):
111+
def test_open_not_cached(dvc):
112+
metric_file = "metric.txt"
112113
metric_content = "0.6"
113-
with monkeypatch.context() as m:
114-
m.chdir(erepo_dir)
115-
erepo_dir.dvc.run(
116-
metrics_no_cache=["metric.txt"],
117-
cmd=(
118-
'python -c "{}"'.format(
119-
"open('{}', 'w').write('{}')".format(
120-
"metric.txt", metric_content
121-
)
122-
)
123-
),
124-
)
125-
126-
with api.open("metric.txt", repo=fspath(erepo_dir)) as fd:
114+
metric_code = "open('{}', 'w').write('{}')".format(
115+
metric_file, metric_content
116+
)
117+
dvc.run(
118+
metrics_no_cache=[metric_file],
119+
cmd=('python -c "{}"'.format(metric_code)),
120+
)
121+
122+
with api.open(metric_file) as fd:
127123
assert fd.read() == metric_content
128124

129-
os.remove(fspath(erepo_dir / "metric.txt"))
125+
os.remove(metric_file)
130126
with pytest.raises(FileMissingError):
131-
api.read("metric.txt", repo=fspath(erepo_dir))
127+
api.read(metric_file)
132128

133129

134130
def test_summon(tmp_dir, dvc, erepo_dir):

0 commit comments

Comments
 (0)