Пример #1
0
def test_get_full_path(files_setup):
    path, _, _ = files_setup
    findex = FilesIndex(path=os.path.join(path, '*'))
    file_name = 'file_1.txt'
    full_path = findex.get_fullpath(file_name)
    assert os.path.dirname(full_path) == path
    assert os.path.basename(full_path) == file_name
Пример #2
0
def test_create_subset(files_setup, index):
    path, _, _ = files_setup
    findex = FilesIndex(path=os.path.join(path, '*'))
    new_findex = findex.create_subset(index)
    file_name = 'file_1.txt'
    full_path = new_findex.get_fullpath(file_name)
    assert len(new_findex) == 1
    assert isinstance(new_findex.indices, np.ndarray)
    assert os.path.dirname(full_path) == path
    assert os.path.basename(full_path) == file_name
Пример #3
0
def test_build_from_index(files_setup):
    path, _, _ = files_setup
    files = ['file_{}.txt'.format(i) for i in range(3)]
    paths = dict(zip(files, [os.path.join(path, f) for f in files]))
    dsindex = DatasetIndex(files)
    findex = FilesIndex(index=dsindex, paths=paths, dirs=False)
    assert len(dsindex) == len(findex)
Пример #4
0
def index(request, files_setup):
    if isinstance(request.param, int):
        return DatasetIndex(request.param), np.arange(request.param)
    if isinstance(request.param, list):
        return DatasetIndex(request.param), request.param
    path, files = files_setup
    return FilesIndex(path=os.path.join(path, '*')), files
Пример #5
0
def test_same_name_in_differen_folders(files_setup):
    path, _, _ = files_setup
    path = os.path.join(path, '*', '*')
    with pytest.raises(ValueError):
        FilesIndex(path=path)
Пример #6
0
def test_build_dirs(files_setup):
    path, folder1, _ = files_setup
    path = os.path.join(path, '*')
    findex = FilesIndex(path=path, dirs=True, sort=True)
    assert len(findex) == 2
    assert findex.indices[0] == os.path.split(folder1)[1]
Пример #7
0
def test_build_no_ext(files_setup):
    path, _, _ = files_setup
    path = os.path.join(path, '*')
    findex = FilesIndex(path=path, no_ext=True)
    assert len(findex) == 3
    assert os.path.splitext(findex.indices[0])[1] == ''
Пример #8
0
def test_build_index_non_path(path, error):
    """ `path` should be string or list of strings """
    with pytest.raises(error):
        FilesIndex(path=path)
Пример #9
0
def test_build_index_empty(path, expectation):
    with expectation:
        findex = FilesIndex(path=path)
        assert len(findex) == 0
        assert isinstance(findex.index, np.ndarray)
Пример #10
0
def small_index(request, files_setup):
    if request.param is DatasetIndex:
        return DatasetIndex(1)
    path, _ = files_setup
    return FilesIndex(path=os.path.join(path, '*1.txt'))