mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-29 15:28:28 +01:00
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.
This commit is contained in:
committed by
Ruslan Kuprieiev
parent
67aaf6a192
commit
fa7619dfee
@@ -0,0 +1,34 @@
|
||||
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")
|
||||
Reference in New Issue
Block a user