Completed
Pull Request — develop (#140)
by
unknown
18:50 queued 08:53
created

describe_config()   C

Complexity

Conditions 7

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
cc 7
c 3
b 1
f 0
dl 0
loc 25
rs 5.5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A it_defaults_to_sources_location() 0 2 1
A it_can_get_the_config_path() 0 2 1
A it_can_get_dependency_path() 0 2 1
A it_can_get_log_path() 0 2 1
B describe_get_path() 0 19 5
1
# pylint: disable=no-self-use,redefined-outer-name,unused-variable,expression-not-assigned,misplaced-comparison-constant
0 ignored issues
show
introduced by
Bad option value 'misplaced-comparison-constant'
Loading history...
2
3
import os
4
import pytest
5
from expecter import expect
0 ignored issues
show
Configuration introduced by
The import expecter could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
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()) == os.path.normpath(
116
                "m/root/m/location"
117
            )
118
119
        def it_can_get_the_config_path(config):
120
            expect(config.get_path('__config__')) == os.path.normpath(
121
                "m/root/m.ext"
122
            )
123
124
        def it_can_get_log_path(config):
125
            expect(config.get_path('__log__')) == os.path.normpath(
126
                "m/root/m/location/gitman.log"
127
            )
128
129
        def it_can_get_dependency_path(config):
130
            expect(config.get_path('foobar')) == os.path.normpath(
131
                "m/root/m/location/foobar"
132
            )
133
134
135
class TestLoad:
136
137
    def test_load_from_directory_with_config_file(self):
138
        config = load_config(FILES)
139
140
        assert None is not config
141
142
    def test_load_from_directory_without_config_file(self, tmpdir):
143
        tmpdir.chdir()
144
145
        config = load_config()
146
147
        assert None is config
148