Exemplo n.º 1
0
def test_filter_files_exclude_argument(testdir):
    filelist = ['base/foo/bar/baz',
                'base/foo/two/three',
                'base/one/two/foo']
    assert utils.filter_files(filelist, exclude=(re.compile(r'two'),)) == ['base/foo/bar/baz']
    assert utils.filter_files(filelist, exclude=(re.compile(r'foo$'),)) == ['base/foo/bar/baz', 'base/foo/two/three']
    assert utils.filter_files(filelist, exclude=('base/foo/*',)) == ['base/one/two/foo']
    assert utils.filter_files(filelist, exclude=(re.compile(r'foo/bar'),
                                                 '*/one/*')) == ['base/foo/two/three']
Exemplo n.º 2
0
def test_filter_files_ignores_hidden_parent_directories():
    filelist = ['.base/foo/.hidden',                '.base/foo/not_hidden',
                '.base/.hidden/.hidden',            '.base/.hiddendir/not_hidden',
                '.base/.hidden/not_hidden/.hidden', '.base/.hidden/not_hidden/not_hidden']
    assert utils.filter_files(filelist, hidden=False) == ['.base/foo/not_hidden']

    filelist = ['path/to/.hidden/base/foo/.hidden',                'path/to/.hidden/base/foo/not_hidden',
                'path/to/.hidden/base/.hidden/.hidden',            'path/to/.hidden/base/.hiddendir/not_hidden',
                'path/to/.hidden/base/.hidden/not_hidden/.hidden', 'path/to/.hidden/base/.hidden/not_hidden/not_hidden']
    assert utils.filter_files(filelist, hidden=False) == ['path/to/.hidden/base/foo/not_hidden']
Exemplo n.º 3
0
def test_filter_files_with_default_arguments():
    filelist = [
        'base/foo/.hidden', 'base/foo/not_hidden', 'base/.hidden/.hidden',
        'base/.hiddendir/not_hidden', 'base/.hidden/not_hidden/.hidden',
        'base/.hidden/not_hidden/not_hidden'
    ]
    assert utils.filter_files(filelist) == filelist
Exemplo n.º 4
0
def test_filter_files_with_getter_argument(testdir):
    items = [(123, 'foo/bar/baz', 456), (123, 'bar/two/three', 456),
             (123, 'one/two/foo', 456)]
    assert utils.filter_files(items,
                              getter=lambda i: i[1],
                              exclude=(re.compile(r'foo'), )) == [
                                  (123, 'bar/two/three', 456)
                              ]
Exemplo n.º 5
0
def test_filter_files_without_hidden_files_or_directories():
    filelist = [
        'base/foo/.hidden', 'base/foo/not_hidden', 'base/.hidden/.hidden',
        'base/.hiddendir/not_hidden', 'base/.hidden/not_hidden/.hidden',
        'base/.hidden/not_hidden/not_hidden'
    ]
    assert utils.filter_files(filelist,
                              hidden=False) == ['base/foo/not_hidden']
Exemplo n.º 6
0
def test_filter_files_without_empty_files(testdir):
    filelist = [str(Path(filepath).relative_to(testdir.parent))
                for filepath in utils.list_files(testdir)]
    cwd = os.getcwd()
    try:
        os.chdir(testdir.parent)
        assert utils.filter_files(filelist, empty=False) == sorted(['base/foo/.not_empty', 'base/foo/not_empty',
                                                                    'base/.bar/.not_empty', 'base/.bar/not_empty',
                                                                    'base/.bar/baz/.not_empty', 'base/.bar/baz/not_empty'])
    finally:
        os.chdir(cwd)
Exemplo n.º 7
0
def test_filter_files_with_absolute_and_relative_paths(testdir):
    filelist = [
        'foo/bar/one', 'foo/bar/two', '/some/where/foo/bar/three',
        '/some/where/foo/bar/four'
    ]
    assert utils.filter_files(filelist) == filelist
Exemplo n.º 8
0
def test_filter_files_with_no_common_path(testdir):
    filelist = ['foo/bar/baz', 'bar/two/three', 'one/two/foo']
    assert utils.filter_files(filelist) == filelist
    assert utils.filter_files(
        filelist, exclude=(re.compile(r'bar'), )) == ['one/two/foo']