Completed
Push — master ( 4ecf0c...8e8e85 )
by Bjorn
01:03
created

test_listfiles()   A

Complexity

Conditions 3

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
cc 3
c 4
b 0
f 0
dl 0
loc 8
rs 9.4285
1
# -*- coding: utf-8 -*-
2
import os
3
4
from dkfileutils.listfiles import list_files, read_skipfile
5
from yamldirs import create_files
6
7
BASEDIR = os.path.dirname(__file__)
8
print "FILE:", __file__
9
print "BSDIR:", BASEDIR
10
print "cwd:", os.getcwd()
11
12
13
# def _files(fit):
14
#     return [y for x, y in fit]
15
16
17
def test_skipfile():
18
    assert read_skipfile('.', ['foo']) == ['foo']
19
20
21
def test_skippy():
22
    files = """
23
        - a
24
        - b
25
        - f:
26
            - .dotfile
27
        - __pycache__:
28
            - c
29
        - htmlcov:
30
            - d
31
        - e.pyc
32
        - foo.egg-info:
33
            - e
34
    """
35
    with create_files(files) as root:
36
        assert {fname for _hex, fname in list_files(root)} == {'a', 'b'}
37
38
        assert {fname for _hex, fname in list_files(root)} == {'a', 'b'}
39
40
        assert [fname for _hex, fname in list_files(os.path.join(root, '.dotdir'))] == []
41
42
43
def test_dot_path():
44
    files = """
45
        - a:
46
            - .skipfile: |
47
                b/.c/d/e
48
            - b:
49
                - .c:
50
                    - d:
51
                        - e: |
52
                            hello
53
                        - f: |
54
                            world
55
            - g
56
    """
57
    print "test_dot_path"
58
    with create_files(files) as directory:
59
        os.chdir(directory)
60
        assert [fname for _hex, fname in list_files('a')] == ['g']
61
62
63
def test_listfiles():
64
    files = """
65
       - a
66
       - b
67
       - c
68
    """
69
    with create_files(files) as directory:
70
        assert set(list_files(digest=False)) == {'a', 'b', 'c'}
71
        
72