Completed
Pull Request — develop (#95)
by Jace
01:54
created

tests.it_should_fail_on_invalid_repositories()   A

Complexity

Conditions 3

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 3
dl 0
loc 7
rs 9.4285
1
# pylint: disable=no-self-use,redefined-outer-name,unused-variable,unused-argument
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
3
import os
4
import shutil
5
from contextlib import suppress
6
import logging
7
8
import pytest
9
from yorm.test import strip
0 ignored issues
show
Configuration introduced by
The import yorm.test 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...
10
11
import gdm
12
from gdm.config import Config
13
from gdm.exceptions import InvalidRepository
14
15
16
CONFIG = """
17
location: deps
18
sources:
19
- dir: gdm_1
20
  link: ''
21
  repo: https://github.com/jacebrowning/gdm-demo
22
  rev: example-branch
23
- dir: gdm_2
24
  link: ''
25
  repo: https://github.com/jacebrowning/gdm-demo
26
  rev: example-tag
27
- dir: gdm_3
28
  link: ''
29
  repo: https://github.com/jacebrowning/gdm-demo
30
  rev: 9bf18e16b956041f0267c21baad555a23237b52e
31
""".lstrip()
32
33
log = logging.getLogger(__name__)
34
35
36
@pytest.fixture
37
def config(root="/tmp/gdm-shared"):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
38
    with suppress(FileNotFoundError):
39
        shutil.rmtree(root)
40
    with suppress(FileExistsError):
41
        os.makedirs(root)
42
    os.chdir(root)
43
    log.info("Temporary directory: %s", root)
44
45
    os.system("touch .git")
46
    config = Config(root=root)
47
    config.__mapper__.text = CONFIG  # pylint: disable=no-member
48
49
    log.debug("File listing: %s", os.listdir(root))
50
51
    return config
52
53
54
def describe_install():
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
55
56
    def it_should_create_missing_directories(config):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
57
        assert not os.path.isdir(config.location)
58
59
        assert gdm.install('gdm_1', depth=1)
60
61
        assert ['gdm_1'] == os.listdir(config.location)
62
63
    def it_should_not_modify_config(config):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
64
        assert gdm.install('gdm_1', depth=1)
65
66
        assert CONFIG == config.__mapper__.text
67
68
    def it_should_use_locked_sources_if_available(config):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
69
        config.__mapper__.text = strip("""
70
        location: deps
71
        sources:
72
        - dir: gdm_1
73
          link: ''
74
          repo: https://github.com/jacebrowning/gdm-demo
75
          rev: example-branch
76
        sources_locked:
77
        - dir: gdm_2
78
          link: ''
79
          repo: https://github.com/jacebrowning/gdm-demo
80
          rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04
81
        """)
82
83
        assert gdm.install(depth=1)
84
85
        assert ['gdm_2'] == os.listdir(config.location)
86
87
    def describe_links():
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
88
89
        @pytest.fixture
90
        def config_with_link(config):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
91
            config.__mapper__.text = strip("""
92
            location: deps
93
            sources:
94
            - dir: gdm_1
95
              link: my_link
96
              repo: https://github.com/jacebrowning/gdm-demo
97
              rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04
98
            """)
99
100
            return config
101
102
        def it_should_create(config_with_link):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
103
            assert gdm.install(depth=1)
104
105
            assert 'my_link' in os.listdir()
106
107
        def it_should_not_overwrite(config_with_link):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
108
            os.system("touch my_link")
109
110
            with pytest.raises(RuntimeError):
111
                gdm.install(depth=1)
112
113
        def it_should_overwrite_with_force(config_with_link):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
114
            os.system("touch my_link")
115
116
            assert gdm.install(depth=1, force=True)
117
118
119
def describe_uninstall():
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
120
121
    def it_should_delete_dependencies_when_they_exist(config):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
122
        gdm.install('gdm_1', depth=1)
123
        assert os.path.isdir(config.location)
124
125
        assert gdm.uninstall()
126
127
        assert not os.path.exists(config.location)
128
129
    def it_should_not_fail_when_no_dependnecies_exist(config):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
130
        assert not os.path.isdir(config.location)
131
132
        assert gdm.uninstall()
133
134
135
def describe_update():
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
136
137
    def it_should_not_modify_config(config):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
138
        gdm.update('gdm_1', depth=1)
139
140
        assert CONFIG == config.__mapper__.text
141
142
    def it_should_lock_previously_locked_dependnecies(config):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
143
        config.__mapper__.text = strip("""
144
        location: deps
145
        sources:
146
        - dir: gdm_1
147
          link: ''
148
          repo: https://github.com/jacebrowning/gdm-demo
149
          rev: example-branch
150
        - dir: gdm_2
151
          link: ''
152
          repo: https://github.com/jacebrowning/gdm-demo
153
          rev: example-tag
154
        sources_locked:
155
        - dir: gdm_2
156
          link: ''
157
          repo: https://github.com/jacebrowning/gdm-demo
158
          rev: (old revision)
159
        """)
160
161
        gdm.update(depth=1)
162
163
        assert strip("""
164
        location: deps
165
        sources:
166
        - dir: gdm_1
167
          link: ''
168
          repo: https://github.com/jacebrowning/gdm-demo
169
          rev: example-branch
170
        - dir: gdm_2
171
          link: ''
172
          repo: https://github.com/jacebrowning/gdm-demo
173
          rev: example-tag
174
        sources_locked:
175
        - dir: gdm_2
176
          link: ''
177
          repo: https://github.com/jacebrowning/gdm-demo
178
          rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04
179
        """) == config.__mapper__.text
180
181
    def it_should_not_lock_dependnecies_when_disabled(config):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
182
        config.__mapper__.text = strip("""
183
        location: deps
184
        sources:
185
        - dir: gdm_1
186
          link: ''
187
          repo: https://github.com/jacebrowning/gdm-demo
188
          rev: example-branch
189
        - dir: gdm_2
190
          link: ''
191
          repo: https://github.com/jacebrowning/gdm-demo
192
          rev: example-tag
193
        sources_locked:
194
        - dir: gdm_2
195
          link: ''
196
          repo: https://github.com/jacebrowning/gdm-demo
197
          rev: (old revision)
198
        """)
199
200
        gdm.update(depth=1, lock=False)
201
202
        assert strip("""
203
        location: deps
204
        sources:
205
        - dir: gdm_1
206
          link: ''
207
          repo: https://github.com/jacebrowning/gdm-demo
208
          rev: example-branch
209
        - dir: gdm_2
210
          link: ''
211
          repo: https://github.com/jacebrowning/gdm-demo
212
          rev: example-tag
213
        sources_locked:
214
        - dir: gdm_2
215
          link: ''
216
          repo: https://github.com/jacebrowning/gdm-demo
217
          rev: (old revision)
218
        """) == config.__mapper__.text
219
220
    def it_should_lock_all_when_enabled(config):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
221
        gdm.update(depth=1, lock=True)
222
223
        assert CONFIG + strip("""
224
        sources_locked:
225
        - dir: gdm_1
226
          link: ''
227
          repo: https://github.com/jacebrowning/gdm-demo
228
          rev: eb37743011a398b208dd9f9ef79a408c0fc10d48
229
        - dir: gdm_2
230
          link: ''
231
          repo: https://github.com/jacebrowning/gdm-demo
232
          rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04
233
        - dir: gdm_3
234
          link: ''
235
          repo: https://github.com/jacebrowning/gdm-demo
236
          rev: 9bf18e16b956041f0267c21baad555a23237b52e
237
        """) == config.__mapper__.text
238
239
240
def describe_lock():
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
241
242
    def it_should_record_all_versions_when_no_arguments(config):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
243
        assert gdm.update(depth=1, lock=False)
244
        assert gdm.lock()
245
246
        assert CONFIG + strip("""
247
        sources_locked:
248
        - dir: gdm_1
249
          link: ''
250
          repo: https://github.com/jacebrowning/gdm-demo
251
          rev: eb37743011a398b208dd9f9ef79a408c0fc10d48
252
        - dir: gdm_2
253
          link: ''
254
          repo: https://github.com/jacebrowning/gdm-demo
255
          rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04
256
        - dir: gdm_3
257
          link: ''
258
          repo: https://github.com/jacebrowning/gdm-demo
259
          rev: 9bf18e16b956041f0267c21baad555a23237b52e
260
        """) == config.__mapper__.text
261
262
    def it_should_record_specified_dependencies(config):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
263
        assert gdm.update(depth=1, lock=False)
264
        assert gdm.lock('gdm_1', 'gdm_3')
265
266
        assert CONFIG + strip("""
267
        sources_locked:
268
        - dir: gdm_1
269
          link: ''
270
          repo: https://github.com/jacebrowning/gdm-demo
271
          rev: eb37743011a398b208dd9f9ef79a408c0fc10d48
272
        - dir: gdm_3
273
          link: ''
274
          repo: https://github.com/jacebrowning/gdm-demo
275
          rev: 9bf18e16b956041f0267c21baad555a23237b52e
276
        """) == config.__mapper__.text
277
278
    def it_should_fail_on_invalid_repositories(config):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
279
        os.system("mkdir deps && touch deps/gdm_1")
280
281
        with pytest.raises(InvalidRepository):
282
            gdm.lock()
283
284
        assert "<unknown>" not in config.__mapper__.text
285