mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
50 lines
1.2 KiB
Python
50 lines
1.2 KiB
Python
import os
|
|
|
|
import pytest
|
|
|
|
from dvc.exceptions import URLMissingError
|
|
from dvc.repo import Repo
|
|
|
|
|
|
def match_files(entries, expected):
|
|
entries_content = {(d["path"], d["isdir"]) for d in entries}
|
|
expected_content = {(d["path"], d["isdir"]) for d in expected}
|
|
assert entries_content == expected_content
|
|
|
|
|
|
@pytest.mark.parametrize("fname", ["foo", "foo.dvc", "dir/foo"])
|
|
def test_file(tmp_dir, fname):
|
|
tmp_dir.gen({fname: "foo contents"})
|
|
|
|
(d,) = Repo.ls_url(fname)
|
|
assert d["isdir"] is False
|
|
assert os.path.normpath(d["path"]) == os.path.abspath(fname)
|
|
|
|
|
|
def test_dir(tmp_dir):
|
|
tmp_dir.gen({"dir/foo": "foo contents", "dir/subdir/bar": "bar contents"})
|
|
|
|
result = Repo.ls_url("dir")
|
|
match_files(
|
|
result,
|
|
[{"path": "foo", "isdir": False}, {"path": "subdir", "isdir": True}],
|
|
)
|
|
|
|
|
|
def test_recursive(tmp_dir):
|
|
tmp_dir.gen({"dir/foo": "foo contents", "dir/subdir/bar": "bar contents"})
|
|
|
|
result = Repo.ls_url("dir", recursive=True)
|
|
match_files(
|
|
result,
|
|
[
|
|
{"path": "foo", "isdir": False},
|
|
{"path": "subdir/bar", "isdir": False},
|
|
],
|
|
)
|
|
|
|
|
|
def test_nonexistent(tmp_dir):
|
|
with pytest.raises(URLMissingError):
|
|
Repo.ls_url("nonexistent")
|