Files
dvc/tests/func/test_ls_url.py
T
Ronan Lamy fa7619dfee ls-url: create basic version of dvc ls-url command
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.
2022-10-04 14:37:29 +03:00

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")