Completed
Pull Request — develop (#112)
by Jace
06:16
created

tests.describe_list()   A

Complexity

Conditions 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 2
dl 0
loc 16
rs 9.4285

1 Method

Rating   Name   Duplication   Size   Complexity  
A tests.it_updates_the_log() 0 14 1
1
# pylint: disable=redefined-outer-name,unused-argument,unused-variable,singleton-comparison,expression-not-assigned
0 ignored issues
show
introduced by
Bad option value 'singleton-comparison'
Loading history...
2
3
import os
4
import shutil
5
from contextlib import suppress
6
import logging
7
8
import pytest
9
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...
10
from freezegun import freeze_time
0 ignored issues
show
Configuration introduced by
The import freezegun 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...
11
12
import gitman
13
from gitman.models import Config
14
from gitman.exceptions import InvalidRepository
15
16
from .utilities import strip
17
18
19
CONFIG = """
20
location: deps
21
sources:
22
- dir: gitman_1
23
  link: ''
24
  repo: https://github.com/jacebrowning/gitman-demo
25
  rev: example-branch
26
- dir: gitman_2
27
  link: ''
28
  repo: https://github.com/jacebrowning/gitman-demo
29
  rev: example-tag
30
- dir: gitman_3
31
  link: ''
32
  repo: https://github.com/jacebrowning/gitman-demo
33
  rev: 9bf18e16b956041f0267c21baad555a23237b52e
34
""".lstrip()
35
36
log = logging.getLogger(__name__)
37
38
39
@pytest.fixture
40
def config(root="/tmp/gitman-shared"):
41
    with suppress(FileNotFoundError):
42
        shutil.rmtree(root)
43
    with suppress(FileExistsError):
44
        os.makedirs(root)
45
    os.chdir(root)
46
    log.info("Temporary directory: %s", root)
47
48
    os.system("touch .git")
49
    config = Config(root=root)
50
    config.__mapper__.text = CONFIG  # pylint: disable=no-member
51
52
    log.debug("File listing: %s", os.listdir(root))
53
54
    return config
55
56
57
def describe_install():
58
59
    def it_should_create_missing_directories(config):
60
        expect(os.path.isdir(config.location)) == False
61
62
        expect(gitman.install('gitman_1', depth=1)) == True
63
64
        expect(os.listdir(config.location)) == ['gitman_1']
65
66
    def it_should_not_modify_config(config):
67
        expect(gitman.install('gitman_1', depth=1)) == True
68
69
        expect(config.__mapper__.text) == CONFIG
70
71
    def it_should_merge_sources(config):
72
        config.__mapper__.text = strip("""
73
        location: deps
74
        sources:
75
        - dir: gitman_1
76
          link: ''
77
          repo: https://github.com/jacebrowning/gitman-demo
78
          rev: example-branch
79
        sources_locked:
80
        - dir: gitman_2
81
          link: ''
82
          repo: https://github.com/jacebrowning/gitman-demo
83
          rev: example-branch
84
        - dir: gitman_3
85
          link: ''
86
          repo: https://github.com/jacebrowning/gitman-demo
87
          rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04
88
        """)
89
90
        expect(gitman.install(depth=1)) == True
91
92
        expect(len(os.listdir(config.location))) == 3
93
94
    def it_can_handle_missing_locked_sources(config):
95
        config.__mapper__.text = strip("""
96
        location: deps
97
        sources:
98
        - dir: gitman_1
99
          link: ''
100
          repo: https://github.com/jacebrowning/gitman-demo
101
          rev: example-branch
102
        sources_locked:
103
        - dir: gitman_2
104
          link: ''
105
          repo: https://github.com/jacebrowning/gitman-demo
106
          rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04
107
        """)
108
109
        expect(gitman.install('gitman_1', depth=1)) == True
110
111
        expect(os.listdir(config.location)) == ['gitman_1']
112
113
    def describe_links():
114
115
        @pytest.fixture
116
        def config_with_link(config):
117
            config.__mapper__.text = strip("""
118
            location: deps
119
            sources:
120
            - dir: gitman_1
121
              link: my_link
122
              repo: https://github.com/jacebrowning/gitman-demo
123
              rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04
124
            """)
125
126
            return config
127
128
        def it_should_create(config_with_link):
129
            expect(gitman.install(depth=1)) == True
130
131
            expect(os.listdir()).contains('my_link')
132
133
        def it_should_not_overwrite(config_with_link):
134
            os.system("touch my_link")
135
136
            with pytest.raises(RuntimeError):
137
                gitman.install(depth=1)
138
139
        def it_should_overwrite_with_force(config_with_link):
140
            os.system("touch my_link")
141
142
            expect(gitman.install(depth=1, force=True)) == True
143
144
145
def describe_uninstall():
146
147
    def it_should_delete_dependencies_when_they_exist(config):
148
        gitman.install('gitman_1', depth=1)
149
        expect(os.path.isdir(config.location)) == True
150
151
        expect(gitman.uninstall()) == True
152
153
        expect(os.path.exists(config.location)) == False
154
155
    def it_should_not_fail_when_no_dependnecies_exist(config):
156
        expect(os.path.isdir(config.location)) == False
157
158
        expect(gitman.uninstall()) == True
159
160
161
def describe_update():
162
163
    def it_should_not_modify_config(config):
164
        gitman.update('gitman_1', depth=1)
165
166
        expect(config.__mapper__.text) == CONFIG
167
168
    def it_should_lock_previously_locked_dependnecies(config):
169
        config.__mapper__.text = strip("""
170
        location: deps
171
        sources:
172
        - dir: gitman_1
173
          link: ''
174
          repo: https://github.com/jacebrowning/gitman-demo
175
          rev: example-branch
176
        - dir: gitman_2
177
          link: ''
178
          repo: https://github.com/jacebrowning/gitman-demo
179
          rev: example-tag
180
        sources_locked:
181
        - dir: gitman_2
182
          link: ''
183
          repo: https://github.com/jacebrowning/gitman-demo
184
          rev: (old revision)
185
        """)
186
187
        gitman.update(depth=1)
188
189
        expect(config.__mapper__.text) == strip("""
190
        location: deps
191
        sources:
192
        - dir: gitman_1
193
          link: ''
194
          repo: https://github.com/jacebrowning/gitman-demo
195
          rev: example-branch
196
        - dir: gitman_2
197
          link: ''
198
          repo: https://github.com/jacebrowning/gitman-demo
199
          rev: example-tag
200
        sources_locked:
201
        - dir: gitman_2
202
          link: ''
203
          repo: https://github.com/jacebrowning/gitman-demo
204
          rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04
205
        """)
206
207
    def it_should_not_lock_dependnecies_when_disabled(config):
208
        config.__mapper__.text = strip("""
209
        location: deps
210
        sources:
211
        - dir: gitman_1
212
          link: ''
213
          repo: https://github.com/jacebrowning/gitman-demo
214
          rev: example-branch
215
        - dir: gitman_2
216
          link: ''
217
          repo: https://github.com/jacebrowning/gitman-demo
218
          rev: example-tag
219
        sources_locked:
220
        - dir: gitman_2
221
          link: ''
222
          repo: https://github.com/jacebrowning/gitman-demo
223
          rev: (old revision)
224
        """)
225
226
        gitman.update(depth=1, lock=False)
227
228
        expect(config.__mapper__.text) == strip("""
229
        location: deps
230
        sources:
231
        - dir: gitman_1
232
          link: ''
233
          repo: https://github.com/jacebrowning/gitman-demo
234
          rev: example-branch
235
        - dir: gitman_2
236
          link: ''
237
          repo: https://github.com/jacebrowning/gitman-demo
238
          rev: example-tag
239
        sources_locked:
240
        - dir: gitman_2
241
          link: ''
242
          repo: https://github.com/jacebrowning/gitman-demo
243
          rev: (old revision)
244
        """)
245
246
    def it_should_lock_all_when_enabled(config):
247
        gitman.update(depth=1, lock=True)
248
249
        expect(config.__mapper__.text) == CONFIG + strip("""
250
        sources_locked:
251
        - dir: gitman_1
252
          link: ''
253
          repo: https://github.com/jacebrowning/gitman-demo
254
          rev: eb37743011a398b208dd9f9ef79a408c0fc10d48
255
        - dir: gitman_2
256
          link: ''
257
          repo: https://github.com/jacebrowning/gitman-demo
258
          rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04
259
        - dir: gitman_3
260
          link: ''
261
          repo: https://github.com/jacebrowning/gitman-demo
262
          rev: 9bf18e16b956041f0267c21baad555a23237b52e
263
        """)
264
265
266
def describe_list():
267
268
    @freeze_time("2012-01-14 12:00:01")
269
    def it_updates_the_log(config):
270
        gitman.install()
271
        gitman.list()
272
        expect(open(config.log_path).read()) == strip("""
273
        2012-01-14 12:00:01
274
        /private/tmp/gitman-shared/deps/gitman_1: https://github.com/jacebrowning/gitman-demo @ eb37743011a398b208dd9f9ef79a408c0fc10d48
275
        /private/tmp/gitman-shared/deps/gitman_1/gdm_sources/gdm_3: https://github.com/jacebrowning/gdm-demo @ ddbe17ef173538d1fda29bd99a14bab3c5d86e78
276
        /private/tmp/gitman-shared/deps/gitman_1/gdm_sources/gdm_3/gdm_sources/gdm_3: https://github.com/jacebrowning/gdm-demo @ fb693447579235391a45ca170959b5583c5042d8
277
        /private/tmp/gitman-shared/deps/gitman_1/gdm_sources/gdm_3/gdm_sources/gdm_4: https://github.com/jacebrowning/gdm-demo @ 63ddfd82d308ddae72d31b61cb8942c898fa05b5
278
        /private/tmp/gitman-shared/deps/gitman_1/gdm_sources/gdm_4: https://github.com/jacebrowning/gdm-demo @ 63ddfd82d308ddae72d31b61cb8942c898fa05b5
279
        /private/tmp/gitman-shared/deps/gitman_2: https://github.com/jacebrowning/gitman-demo @ 7bd138fe7359561a8c2ff9d195dff238794ccc04
280
        /private/tmp/gitman-shared/deps/gitman_3: https://github.com/jacebrowning/gitman-demo @ 9bf18e16b956041f0267c21baad555a23237b52e
281
        """, end='\n\n')
282
283
284
def describe_lock():
285
286
    def it_should_record_all_versions_when_no_arguments(config):
287
        expect(gitman.update(depth=1, lock=False)) == True
288
        expect(gitman.lock()) == True
289
290
        expect(config.__mapper__.text) == CONFIG + strip("""
291
        sources_locked:
292
        - dir: gitman_1
293
          link: ''
294
          repo: https://github.com/jacebrowning/gitman-demo
295
          rev: eb37743011a398b208dd9f9ef79a408c0fc10d48
296
        - dir: gitman_2
297
          link: ''
298
          repo: https://github.com/jacebrowning/gitman-demo
299
          rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04
300
        - dir: gitman_3
301
          link: ''
302
          repo: https://github.com/jacebrowning/gitman-demo
303
          rev: 9bf18e16b956041f0267c21baad555a23237b52e
304
        """) == config.__mapper__.text
305
306
    def it_should_record_specified_dependencies(config):
307
        expect(gitman.update(depth=1, lock=False)) == True
308
        expect(gitman.lock('gitman_1', 'gitman_3')) == True
309
310
        expect(config.__mapper__.text) == CONFIG + strip("""
311
        sources_locked:
312
        - dir: gitman_1
313
          link: ''
314
          repo: https://github.com/jacebrowning/gitman-demo
315
          rev: eb37743011a398b208dd9f9ef79a408c0fc10d48
316
        - dir: gitman_3
317
          link: ''
318
          repo: https://github.com/jacebrowning/gitman-demo
319
          rev: 9bf18e16b956041f0267c21baad555a23237b52e
320
        """) == config.__mapper__.text
321
322
    def it_should_fail_on_invalid_repositories(config):
323
        os.system("mkdir deps && touch deps/gitman_1")
324
325
        with pytest.raises(InvalidRepository):
326
            gitman.lock()
327
328
        expect(config.__mapper__.text).does_not_contain("<unknown>")
329