mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
ls-url: add support for --tree/--level (#10664)
This commit is contained in:
+63
-1
@@ -6,8 +6,9 @@ from os.path import join
|
||||
|
||||
import pytest
|
||||
|
||||
from dvc.fs import MemoryFileSystem
|
||||
from dvc.repo import Repo
|
||||
from dvc.repo.ls import ls_tree
|
||||
from dvc.repo.ls import _ls_tree, ls_tree
|
||||
from dvc.scm import CloneError
|
||||
|
||||
FS_STRUCTURE = {
|
||||
@@ -998,3 +999,64 @@ def test_ls_tree_maxdepth(M, tmp_dir, scm, dvc):
|
||||
"structure.xml.dvc": None,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def test_fs_ls_tree():
|
||||
fs = MemoryFileSystem(global_store=False)
|
||||
fs.pipe({f: content.encode() for f, content in FS_STRUCTURE.items()})
|
||||
root = fs.root_marker
|
||||
|
||||
files = _ls_tree(fs, "README.md")
|
||||
assert _simplify_tree(files) == {"README.md": None}
|
||||
files = _ls_tree(fs, root)
|
||||
expected = {
|
||||
root: {
|
||||
".gitignore": None,
|
||||
"README.md": None,
|
||||
"model": {
|
||||
"script.py": None,
|
||||
"train.py": None,
|
||||
},
|
||||
}
|
||||
}
|
||||
assert _simplify_tree(files) == expected
|
||||
|
||||
files = _ls_tree(fs, "model")
|
||||
assert _simplify_tree(files) == {
|
||||
"model": {
|
||||
"script.py": None,
|
||||
"train.py": None,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def test_fs_ls_tree_maxdepth():
|
||||
fs = MemoryFileSystem(global_store=False)
|
||||
fs.pipe({f: content.encode() for f, content in FS_STRUCTURE.items()})
|
||||
|
||||
files = _ls_tree(fs, "/", maxdepth=0)
|
||||
assert _simplify_tree(files) == {"/": None}
|
||||
|
||||
files = _ls_tree(fs, "/", maxdepth=1)
|
||||
assert _simplify_tree(files) == {
|
||||
"/": {
|
||||
".gitignore": None,
|
||||
"README.md": None,
|
||||
"model": None,
|
||||
}
|
||||
}
|
||||
|
||||
files = _ls_tree(fs, "/", maxdepth=2)
|
||||
assert _simplify_tree(files) == {
|
||||
"/": {
|
||||
".gitignore": None,
|
||||
"README.md": None,
|
||||
"model": {
|
||||
"script.py": None,
|
||||
"train.py": None,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
files = _ls_tree(fs, "README.md", maxdepth=3)
|
||||
assert _simplify_tree(files) == {"README.md": None}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from dvc.cli import parse_args
|
||||
from dvc.commands.ls_url import CmdListUrl
|
||||
from dvc.config import Config
|
||||
from dvc.fs import LocalFileSystem
|
||||
|
||||
|
||||
def test_ls_url(mocker, M):
|
||||
@@ -12,12 +13,16 @@ def test_ls_url(mocker, M):
|
||||
assert cmd.run() == 0
|
||||
|
||||
m.assert_called_once_with(
|
||||
"src", recursive=False, fs_config=None, config=M.instance_of(Config)
|
||||
"src",
|
||||
recursive=False,
|
||||
maxdepth=None,
|
||||
fs_config=None,
|
||||
config=M.instance_of(Config),
|
||||
)
|
||||
|
||||
|
||||
def test_recursive(mocker, M):
|
||||
cli_args = parse_args(["ls-url", "-R", "src"])
|
||||
cli_args = parse_args(["ls-url", "-R", "-L", "2", "src"])
|
||||
assert cli_args.func == CmdListUrl
|
||||
cmd = cli_args.func(cli_args)
|
||||
m = mocker.patch("dvc.repo.Repo.ls_url", autospec=True)
|
||||
@@ -25,5 +30,16 @@ def test_recursive(mocker, M):
|
||||
assert cmd.run() == 0
|
||||
|
||||
m.assert_called_once_with(
|
||||
"src", recursive=True, fs_config=None, config=M.instance_of(Config)
|
||||
"src", recursive=True, maxdepth=2, fs_config=None, config=M.instance_of(Config)
|
||||
)
|
||||
|
||||
|
||||
def test_tree(mocker, M):
|
||||
cli_args = parse_args(["ls-url", "--tree", "--level", "2", "src"])
|
||||
assert cli_args.func == CmdListUrl
|
||||
cmd = cli_args.func(cli_args)
|
||||
m = mocker.patch("dvc.repo.ls._ls_tree", autospec=True)
|
||||
|
||||
assert cmd.run() == 0
|
||||
|
||||
m.assert_called_once_with(M.instance_of(LocalFileSystem), "src", maxdepth=2)
|
||||
|
||||
Reference in New Issue
Block a user