1"""Test list""" 2 3import os 4import pytest 5 6 7@pytest.mark.parametrize( 8 'location', [ 9 'work', 10 'outside', 11 'subdir', 12 ]) 13@pytest.mark.usefixtures('ds1_copy') 14def test_list(runner, yadm_cmd, paths, ds1, location): 15 """List tests""" 16 if location == 'work': 17 run_dir = paths.work 18 elif location == 'outside': 19 run_dir = paths.work.join('..') 20 elif location == 'subdir': 21 # first directory with tracked data 22 run_dir = paths.work.join(ds1.tracked_dirs[0]) 23 with run_dir.as_cwd(): 24 # test with '-a' 25 # should get all tracked files, relative to the work path 26 run = runner(command=yadm_cmd('list', '-a')) 27 assert run.success 28 assert run.err == '' 29 returned_files = set(run.out.splitlines()) 30 expected_files = {e.path for e in ds1 if e.tracked} 31 assert returned_files == expected_files 32 # test without '-a' 33 # should get all tracked files, relative to the work path unless in a 34 # subdir, then those should be a limited set of files, relative to the 35 # subdir 36 run = runner(command=yadm_cmd('list')) 37 assert run.success 38 assert run.err == '' 39 returned_files = set(run.out.splitlines()) 40 if location == 'subdir': 41 basepath = os.path.basename(os.getcwd()) 42 # only expect files within the subdir 43 # names should be relative to subdir 44 expected_files = { 45 e.path[len(basepath)+1:] 46 for e in ds1 if e.tracked and e.path.startswith(basepath) 47 } 48 assert returned_files == expected_files 49