Completed
Pull Request — develop (#140)
by
unknown
24:17 queued 14:16
created

TestConfig   A

Complexity

Total Complexity 34

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 92
rs 9.2
wmc 34
1
# pylint: disable=no-self-use,redefined-outer-name,unused-variable,expression-not-assigned,misplaced-comparison-constant
2
3
import os
4
import pytest
5
from expecter import expect
6
7
from gitman.models import Config, load_config
8
9
from .conftest import FILES
10
11
12
class TestConfig:
13
14
    def test_init_defaults(self):
15
        """Verify a configuration has a default filename and location."""
16
        config = Config('mock/root')
17
18
        assert 'mock/root' == config.root
19
        assert 'gitman.yml' == config.filename
20
        assert 'gitman_sources' == config.location
21
        assert [] == config.sources
22
23
    def test_init_filename(self):
24
        """Verify the filename can be customized."""
25
        config = Config('mock/root', 'mock.custom')
26
27
        assert 'mock.custom' == config.filename
28
        assert 'gitman_sources' == config.location
29
30
    def test_init_location(self):
31
        """Verify the location can be customized."""
32
        config = Config('mock/root', location='.gitman')
33
34
        assert 'gitman.yml' == config.filename
35
        assert '.gitman' == config.location
36
37
    def test_path(self):
38
        """Verify a configuration's path is correct."""
39
        config = Config('mock/root')
40
41
        assert os.path.normpath("mock/root/gitman.yml") == config.path
42
43
    @pytest.mark.integration
44
    def test_install_and_list(self):
45
        """Verify the correct dependencies are installed."""
46
        config = Config(FILES)
47
48
        count = config.install_dependencies()
49
        assert 7 == count
50
51
        deps = list(config.get_dependencies())
52
        assert 7 == len(deps)
53
        assert '1de84ca1d315f81b035cd7b0ecf87ca2025cdacd' == deps[0][2]
54
        assert '050290bca3f14e13fd616604202b579853e7bfb0' == deps[1][2]
55
        assert 'fb693447579235391a45ca170959b5583c5042d8' == deps[2][2]
56
        # master branch always changes --------------------- deps[3][2]
57
        # master branch always changes --------------------- deps[4][2]
58
        assert '7bd138fe7359561a8c2ff9d195dff238794ccc04' == deps[5][2]
59
        assert '2da24fca34af3748e3cab61db81a2ae8b35aec94' == deps[6][2]
60
61
        assert 5 == len(list(config.get_dependencies(depth=2)))
62
63
        assert 3 == len(list(config.get_dependencies(depth=1)))
64
65
        assert 0 == len(list(config.get_dependencies(depth=0)))
66
67
    @pytest.mark.integration
68
    def test_install_with_dirs(self):
69
        """Verify the dependency list can be filtered."""
70
        config = Config(FILES)
71
72
        count = config.install_dependencies('gitman_2', 'gitman_3')
73
        assert 2 == count
74
75
    def test_install_with_dirs_unknown(self):
76
        """Verify zero dependencies are installed with an unknown dependency."""
77
        config = Config(FILES)
78
79
        count = config.install_dependencies('foobar')
80
        assert 0 == count
81
82
    def test_install_with_depth_0(self):
83
        """Verify an install depth of 0 installs nothing."""
84
        config = Config(FILES)
85
86
        count = config.install_dependencies(depth=0)
87
        assert 0 == count
88
89
    @pytest.mark.integration
90
    def test_install_with_depth_1(self):
91
        """Verify an install depth of 1 installs the direct dependencies."""
92
        config = Config(FILES)
93
94
        count = config.install_dependencies(depth=1)
95
        assert 3 == count
96
97
    @pytest.mark.integration
98
    def test_install_with_depth_2(self):
99
        """Verify an install depth of 2 installs 1 level of nesting."""
100
        config = Config(FILES)
101
102
        count = config.install_dependencies(depth=2)
103
        assert 5 == count
104
105
106
def describe_config():
107
108
    @pytest.fixture
109
    def config():
110
        return Config('m/root', 'm.ext', 'm/location')
111
112
    def describe_get_path():
113
114
        def it_defaults_to_sources_location(config):
115
            expect(config.get_path()) == 
0 ignored issues
show
introduced by
invalid syntax
Loading history...
116
            os.path.normpath("m/root/m/location")
117
118
        def it_can_get_the_config_path(config):
119
            expect(config.get_path('__config__')) == 
120
            os.path.normpath("m/root/m.ext")
121
122
        def it_can_get_log_path(config):
123
            expect(config.get_path('__log__')) == 
124
            os.path.normpath("m/root/m/location/gitman.log")
125
126
        def it_can_get_dependency_path(config):
127
            expect(config.get_path('foobar')) == 
128
            os.path.normpath("m/root/m/location/foobar")
129
130
131
class TestLoad:
132
133
    def test_load_from_directory_with_config_file(self):
134
        config = load_config(FILES)
135
136
        assert None is not config
137
138
    def test_load_from_directory_without_config_file(self, tmpdir):
139
        tmpdir.chdir()
140
141
        config = load_config()
142
143
        assert None is config
144