mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-09 23:10:24 +01:00
For now, this only takes a URL (or local path) and lists its contents if the protocol supports it. The command fails if the target doesn't exist and returns the (absolute) path to the target if it's not a directory.
35 lines
851 B
Python
35 lines
851 B
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
|
|
|
|
|
|
def test_file(tmp_dir):
|
|
tmp_dir.gen({"foo": "foo contents"})
|
|
|
|
result = Repo.ls_url("foo")
|
|
match_files(result, [{"path": os.path.abspath("foo"), "isdir": False}])
|
|
|
|
|
|
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_nonexistent(tmp_dir):
|
|
with pytest.raises(URLMissingError):
|
|
Repo.ls_url("nonexistent")
|