|
1
|
|
|
# pylint: disable=no-self-use,redefined-outer-name |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
import pytest |
|
4
|
|
|
|
|
5
|
|
|
from gdm.config import Config, load |
|
6
|
|
|
|
|
7
|
|
|
from .conftest import FILES |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
class TestConfig: |
|
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
def test_init_defaults(self): |
|
13
|
|
|
"""Verify a configuration has a default filename and location.""" |
|
14
|
|
|
config = Config('mock/root') |
|
15
|
|
|
|
|
16
|
|
|
assert 'mock/root' == config.root |
|
17
|
|
|
assert 'gdm.yml' == config.filename |
|
18
|
|
|
assert 'gdm_sources' == config.location |
|
19
|
|
|
assert [] == config.sources |
|
20
|
|
|
|
|
21
|
|
|
def test_init_filename(self): |
|
22
|
|
|
"""Verify the filename can be customized.""" |
|
23
|
|
|
config = Config('mock/root', 'mock.custom') |
|
24
|
|
|
|
|
25
|
|
|
assert 'mock.custom' == config.filename |
|
26
|
|
|
assert 'gdm_sources' == config.location |
|
27
|
|
|
|
|
28
|
|
|
def test_init_location(self): |
|
29
|
|
|
"""Verify the location can be customized.""" |
|
30
|
|
|
config = Config('mock/root', location='.gdm') |
|
31
|
|
|
|
|
32
|
|
|
assert 'gdm.yml' == config.filename |
|
33
|
|
|
assert '.gdm' == config.location |
|
34
|
|
|
|
|
35
|
|
|
def test_path(self): |
|
36
|
|
|
"""Verify a configuration's path is correct.""" |
|
37
|
|
|
config = Config('mock/root') |
|
38
|
|
|
|
|
39
|
|
|
assert "mock/root/gdm.yml" == config.path |
|
40
|
|
|
|
|
41
|
|
|
@pytest.mark.integration |
|
42
|
|
|
def test_install_and_list(self): |
|
43
|
|
|
"""Verify the correct dependencies are installed.""" |
|
44
|
|
|
config = Config(FILES) |
|
45
|
|
|
|
|
46
|
|
|
count = config.install_deps() |
|
47
|
|
|
assert 7 == count |
|
48
|
|
|
|
|
49
|
|
|
deps = list(config.get_deps()) |
|
50
|
|
|
assert 7 == len(deps) |
|
51
|
|
|
assert 'https://github.com/jacebrowning/gdm-demo' == deps[0][1] |
|
52
|
|
|
assert 'eb37743011a398b208dd9f9ef79a408c0fc10d48' == deps[0][2] |
|
53
|
|
|
assert 'https://github.com/jacebrowning/gdm-demo' == deps[1][1] |
|
54
|
|
|
assert 'ddbe17ef173538d1fda29bd99a14bab3c5d86e78' == deps[1][2] |
|
55
|
|
|
assert 'https://github.com/jacebrowning/gdm-demo' == deps[2][1] |
|
56
|
|
|
assert 'fb693447579235391a45ca170959b5583c5042d8' == deps[2][2] |
|
57
|
|
|
assert 'https://github.com/jacebrowning/gdm-demo' == deps[3][1] |
|
58
|
|
|
# master branch always changes --------------------- deps[3][2] |
|
59
|
|
|
assert 'https://github.com/jacebrowning/gdm-demo' == deps[4][1] |
|
60
|
|
|
# master branch always changes --------------------- deps[4][2] |
|
61
|
|
|
assert 'https://github.com/jacebrowning/gdm-demo' == deps[5][1] |
|
62
|
|
|
assert '7bd138fe7359561a8c2ff9d195dff238794ccc04' == deps[5][2] |
|
63
|
|
|
assert 'https://github.com/jacebrowning/gdm-demo' == deps[6][1] |
|
64
|
|
|
assert '2da24fca34af3748e3cab61db81a2ae8b35aec94' == deps[6][2] |
|
65
|
|
|
|
|
66
|
|
|
assert 5 == len(list(config.get_deps(depth=2))) |
|
67
|
|
|
|
|
68
|
|
|
assert 3 == len(list(config.get_deps(depth=1))) |
|
69
|
|
|
|
|
70
|
|
|
assert 0 == len(list(config.get_deps(depth=0))) |
|
71
|
|
|
|
|
72
|
|
|
@pytest.mark.integration |
|
73
|
|
|
def test_install_with_dirs(self): |
|
74
|
|
|
"""Verify the dependency list can be filtered.""" |
|
75
|
|
|
config = Config(FILES) |
|
76
|
|
|
|
|
77
|
|
|
count = config.install_deps('gdm_2', 'gdm_3') |
|
78
|
|
|
assert 2 == count |
|
79
|
|
|
|
|
80
|
|
|
def test_install_with_dirs_unknown(self): |
|
81
|
|
|
"""Verify zero dependencies are installed with an unknown dependency.""" |
|
82
|
|
|
config = Config(FILES) |
|
83
|
|
|
|
|
84
|
|
|
count = config.install_deps('foobar') |
|
85
|
|
|
assert 0 == count |
|
86
|
|
|
|
|
87
|
|
|
def test_install_with_depth_0(self): |
|
88
|
|
|
"""Verify an install depth of 0 installs nothing.""" |
|
89
|
|
|
config = Config(FILES) |
|
90
|
|
|
|
|
91
|
|
|
count = config.install_deps(depth=0) |
|
92
|
|
|
assert 0 == count |
|
93
|
|
|
|
|
94
|
|
|
@pytest.mark.integration |
|
95
|
|
|
def test_install_with_depth_1(self): |
|
96
|
|
|
"""Verify an install depth of 1 installs the direct dependencies.""" |
|
97
|
|
|
config = Config(FILES) |
|
98
|
|
|
|
|
99
|
|
|
count = config.install_deps(depth=1) |
|
100
|
|
|
assert 3 == count |
|
101
|
|
|
|
|
102
|
|
|
@pytest.mark.integration |
|
103
|
|
|
def test_install_with_depth_2(self): |
|
104
|
|
|
"""Verify an install depth of 2 installs 1 level of nesting.""" |
|
105
|
|
|
config = Config(FILES) |
|
106
|
|
|
|
|
107
|
|
|
count = config.install_deps(depth=2) |
|
108
|
|
|
assert 5 == count |
|
109
|
|
|
|
|
110
|
|
|
|
|
111
|
|
|
class TestLoad: |
|
|
|
|
|
|
112
|
|
|
|
|
113
|
|
|
def test_load_from_directory_with_config_file(self): |
|
|
|
|
|
|
114
|
|
|
config = load(FILES) |
|
115
|
|
|
|
|
116
|
|
|
assert None is not config |
|
117
|
|
|
|
|
118
|
|
|
def test_load_from_directory_without_config_file(self, tmpdir): |
|
|
|
|
|
|
119
|
|
|
tmpdir.chdir() |
|
120
|
|
|
|
|
121
|
|
|
config = load() |
|
122
|
|
|
|
|
123
|
|
|
assert None is config |
|
124
|
|
|
|
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.