Completed
Push — master ( bff43f...8c5ef8 )
by Bjorn
51s
created

test_pfindall()   B

Complexity

Conditions 5

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 5
c 1
b 0
f 1
dl 0
loc 22
rs 8.3411
1
# -*- coding: utf-8 -*-
2
import os
3
from yamldirs import create_files
4
from dkfileutils import pfind
5
from dkfileutils.path import Path
6
from dkfileutils.pfind import pfindall
7
8
BASEDIR = os.path.dirname(__file__)
9
10
11
def test_pfind():
12
    assert pfind.pfind(BASEDIR, 'setup.py') == os.path.abspath(BASEDIR + '/../setup.py')
13
14
15
def test_notfound():
16
    assert pfind.pfind(BASEDIR, 'this-file-does-not-exist') is None
17
18
19
def test_pfindall():
20
    files = """
21
        a:
22
            - a1.txt
23
            - a1:
24
                - a2:
25
                    - a3.txt
26
                - a2.txt    
27
    """
28
    with create_files(files) as root:
29
        root = Path(root)
30
31
        assert dict(pfindall('a/a1/a2', 'a3.txt')) == {
32
            'a3.txt': root / 'a/a1/a2/a3.txt',
33
        }
34
35
        assert dict(pfindall('a/a1/a2', 'a2.txt', 'a3.txt')) == {
36
            'a3.txt': root / 'a/a1/a2/a3.txt',
37
            'a2.txt': root / 'a/a1/a2.txt',
38
        }
39
40
        assert dict(pfindall('a/a1/a2', 'a1.txt', 'a2.txt', 'a3.txt')) == {
41
            'a3.txt': root / 'a/a1/a2/a3.txt',
42
            'a2.txt': root / 'a/a1/a2.txt',
43
            'a1.txt': root / 'a/a1.txt',
44
        }
45