-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathtest_api.py
More file actions
36 lines (24 loc) · 896 Bytes
/
test_api.py
File metadata and controls
36 lines (24 loc) · 896 Bytes
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
import re
import pytest
from dvc import api
def test_open_raises_error_if_no_context(tmp_dir, dvc):
tmp_dir.dvc_gen("foo", "foo-text")
fd = api.open("foo")
with pytest.raises(
AttributeError, match=re.escape("should be used in a with statement.")
):
fd.read()
def test_open_rev_raises_error_on_wrong_mode(tmp_dir, dvc):
tmp_dir.dvc_gen("foo", "foo-text")
with pytest.raises(
ValueError, match=re.escape("Only reading `mode` is supported.")
):
with api.open("foo", mode="w"):
pass
def test_api_read_from_subdir_with_repo_arg(tmp_dir, dvc):
"""Ensure relative paths are resolved from repo root, not cwd."""
tmp_dir.dvc_gen({"data": {"data.xml": "contents"}})
subdir = tmp_dir / "src"
subdir.mkdir()
with subdir.chdir():
assert api.read("data/data.xml", repo=str(tmp_dir)) == "contents"