2018-07-11 12:50:42 +00:00
|
|
|
"""Test list"""
|
|
|
|
|
|
|
|
import os
|
2023-07-10 14:14:33 +00:00
|
|
|
|
2018-07-11 12:50:42 +00:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
2023-07-10 19:43:17 +00:00
|
|
|
"location",
|
|
|
|
[
|
|
|
|
"work",
|
|
|
|
"outside",
|
|
|
|
"subdir",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
@pytest.mark.usefixtures("ds1_copy")
|
2020-11-17 20:38:31 +00:00
|
|
|
def test_list(runner, yadm_cmd, paths, ds1, location):
|
2018-07-11 12:50:42 +00:00
|
|
|
"""List tests"""
|
2023-07-10 19:43:17 +00:00
|
|
|
if location == "work":
|
2018-07-11 12:50:42 +00:00
|
|
|
run_dir = paths.work
|
2023-07-10 19:43:17 +00:00
|
|
|
elif location == "outside":
|
|
|
|
run_dir = paths.work.join("..")
|
|
|
|
elif location == "subdir":
|
2018-07-11 12:50:42 +00:00
|
|
|
# first directory with tracked data
|
|
|
|
run_dir = paths.work.join(ds1.tracked_dirs[0])
|
|
|
|
with run_dir.as_cwd():
|
|
|
|
# test with '-a'
|
|
|
|
# should get all tracked files, relative to the work path
|
2023-07-10 19:43:17 +00:00
|
|
|
run = runner(command=yadm_cmd("list", "-a"))
|
2018-07-11 12:50:42 +00:00
|
|
|
assert run.success
|
2023-07-10 19:43:17 +00:00
|
|
|
assert run.err == ""
|
2018-07-11 12:50:42 +00:00
|
|
|
returned_files = set(run.out.splitlines())
|
2019-09-26 13:46:05 +00:00
|
|
|
expected_files = {e.path for e in ds1 if e.tracked}
|
2018-07-11 12:50:42 +00:00
|
|
|
assert returned_files == expected_files
|
|
|
|
# test without '-a'
|
|
|
|
# should get all tracked files, relative to the work path unless in a
|
|
|
|
# subdir, then those should be a limited set of files, relative to the
|
|
|
|
# subdir
|
2023-07-10 19:43:17 +00:00
|
|
|
run = runner(command=yadm_cmd("list"))
|
2018-07-11 12:50:42 +00:00
|
|
|
assert run.success
|
2023-07-10 19:43:17 +00:00
|
|
|
assert run.err == ""
|
2018-07-11 12:50:42 +00:00
|
|
|
returned_files = set(run.out.splitlines())
|
2023-07-10 19:43:17 +00:00
|
|
|
if location == "subdir":
|
2018-07-11 12:50:42 +00:00
|
|
|
basepath = os.path.basename(os.getcwd())
|
|
|
|
# only expect files within the subdir
|
|
|
|
# names should be relative to subdir
|
2023-07-10 19:43:17 +00:00
|
|
|
index = len(basepath) + 1
|
|
|
|
expected_files = {e.path[index:] for e in ds1 if e.tracked and e.path.startswith(basepath)}
|
2018-07-11 12:50:42 +00:00
|
|
|
assert returned_files == expected_files
|