test_changed_glob()   F
last analyzed

Complexity

Conditions 16

Size

Total Lines 46

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 16
dl 0
loc 46
rs 2.6716
c 0
b 0
f 0

How to fix   Complexity   

Complexity

Complex classes like test_changed_glob() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
# -*- coding: utf-8 -*-
2
from __future__ import print_function
3
import os
4
from hashlib import md5
5
from yamldirs import create_files
6
from dkfileutils import changed, path
7
from dkfileutils.changed import Directory
8
9
10
def test_empty_digest():
11
    files = """
12
        emptydir: []
13
    """
14
    with create_files(files) as directory:
15
        assert changed.digest('emptydir') == md5(b"").hexdigest()
16
17
18
def test_changed():
19
    files = """
20
        emptydir: []
21
    """
22
    with create_files(files) as directory:
23
        assert changed.changed('emptydir')
24
25
26
def test_changed_glob():
27
    files = """
28
        a:
29
            b:
30
                c:
31
                    d.txt: hello world
32
            e:
33
                f.rst: thanks for all the fish
34
    """
35
    with create_files(files) as _root:
36
        adir = changed.Directory('a')
37
        print('digest:', changed.digest(adir))
38
39
        # should be changed first time
40
        assert adir.changed(glob='**/*')
41
        assert adir.changed(glob='**/*.txt')
42
        assert adir.changed(glob='**/*.rst')
43
44
        print('digest:', changed.digest(adir))
45
46
        # not changed second time
47
        assert not adir.changed(glob='**/*')
48
        assert not adir.changed(glob='**/*.txt')
49
        assert not adir.changed(glob='**/*.rst')
50
51
        dtxt = adir / 'b' / 'c' / 'd.txt'
52
        with dtxt.open('a') as fp:
53
            print('appended', file=fp)
54
55
        print("DTXT:", dtxt.read())
56
        os.chdir(_root)
57
58
        print('digest:', changed.digest(adir))
59
        print('cwd:', os.getcwd())
60
        adir = changed.Directory('a')
61
        assert adir.changed(glob='**/*')
62
        assert adir.changed(glob='**/*.txt')
63
        assert not adir.changed(glob='**/*.rst')
64
65
        frst = adir / 'e' / 'f.rst'
66
        with frst.open('a') as fp:
67
            print('appended', file=fp)
68
69
        assert adir.changed(glob='**/*')
70
        assert not adir.changed(glob='**/*.txt')
71
        assert adir.changed(glob='**/*.rst')
72
73
74
def test_missing():
75
    assert changed.changed("this-directory-doesnt-exist")
76
77
78
def test_multifiles():
79
    files = """
80
        a:
81
            - b: |
82
                hello
83
            - c: |
84
                world
85
    """
86
    with create_files(files) as directory:
87
        assert changed.changed('a')
88
        assert not Directory('a').changed()
89