1
|
|
|
# pylint: disable=no-self-use,unused-variable,expression-not-assigned |
2
|
|
|
|
3
|
|
|
from unittest.mock import Mock, patch |
4
|
|
|
import logging |
5
|
|
|
|
6
|
|
|
import pytest |
7
|
|
|
from expecter import expect |
|
|
|
|
8
|
|
|
|
9
|
|
|
from gitman import cli |
10
|
|
|
from gitman.common import _Config |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class TestMain: |
14
|
|
|
"""Unit tests for the top-level arguments.""" |
15
|
|
|
|
16
|
|
|
def test_main(self): |
17
|
|
|
"""Verify the top-level command can be run.""" |
18
|
|
|
mock_function = Mock(return_value=True) |
19
|
|
|
|
20
|
|
|
cli.main([], mock_function) |
21
|
|
|
|
22
|
|
|
mock_function.assert_called_once_with(root=None) |
23
|
|
|
|
24
|
|
|
def test_main_fail(self): |
25
|
|
|
"""Verify error in commands are detected.""" |
26
|
|
|
with pytest.raises(SystemExit): |
27
|
|
|
cli.main([], Mock(return_value=False)) |
28
|
|
|
|
29
|
|
|
def test_main_help(self): |
30
|
|
|
"""Verify the help text can be displayed.""" |
31
|
|
|
with pytest.raises(SystemExit): |
32
|
|
|
cli.main(['--help']) |
33
|
|
|
|
34
|
|
|
def test_main_none(self): |
35
|
|
|
"""Verify it's an error to specify no command.""" |
36
|
|
|
with pytest.raises(SystemExit): |
37
|
|
|
cli.main([]) |
38
|
|
|
|
39
|
|
|
def test_main_interrupt(self): |
40
|
|
|
"""Verify a command can be interrupted.""" |
41
|
|
|
with pytest.raises(SystemExit): |
42
|
|
|
cli.main([], Mock(side_effect=KeyboardInterrupt)) |
43
|
|
|
|
44
|
|
|
def test_main_error(self): |
45
|
|
|
"""Verify runtime errors are handled.""" |
46
|
|
|
with pytest.raises(SystemExit): |
47
|
|
|
cli.main([], Mock(side_effect=RuntimeError)) |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
class TestInstall: |
51
|
|
|
"""Unit tests for the `install` command.""" |
52
|
|
|
|
53
|
|
|
@patch('gitman.commands.install') |
54
|
|
|
def test_install(self, mock_install): |
55
|
|
|
"""Verify the 'install' command can be run.""" |
56
|
|
|
cli.main(['install']) |
57
|
|
|
|
58
|
|
|
mock_install.assert_called_once_with( |
59
|
|
|
root=None, depth=5, force=False, fetch=False, clean=False) |
60
|
|
|
|
61
|
|
|
@patch('gitman.commands.install') |
62
|
|
|
def test_install_root(self, mock_install): |
63
|
|
|
"""Verify the project's root can be specified.""" |
64
|
|
|
cli.main(['install', '--root', 'mock/path/to/root']) |
65
|
|
|
|
66
|
|
|
mock_install.assert_called_once_with( |
67
|
|
|
root='mock/path/to/root', depth=5, |
68
|
|
|
force=False, fetch=False, clean=False) |
69
|
|
|
|
70
|
|
|
@patch('gitman.commands.install') |
71
|
|
|
def test_install_force(self, mock_install): |
72
|
|
|
"""Verify dependencies can be force-installed.""" |
73
|
|
|
cli.main(['install', '--force']) |
74
|
|
|
|
75
|
|
|
mock_install.assert_called_once_with( |
76
|
|
|
root=None, depth=5, force=True, fetch=False, clean=False) |
77
|
|
|
|
78
|
|
|
@patch('gitman.commands.install') |
79
|
|
|
def test_install_fetch(self, mock_install): |
80
|
|
|
"""Verify fetching can be enabled.""" |
81
|
|
|
cli.main(['install', '--fetch']) |
82
|
|
|
|
83
|
|
|
mock_install.assert_called_once_with( |
84
|
|
|
root=None, depth=5, force=False, fetch=True, clean=False) |
85
|
|
|
|
86
|
|
|
@patch('gitman.commands.install') |
87
|
|
|
def test_install_clean(self, mock_install): |
88
|
|
|
"""Verify dependency cleaning can be enabled.""" |
89
|
|
|
cli.main(['install', '--clean']) |
90
|
|
|
|
91
|
|
|
mock_install.assert_called_once_with( |
92
|
|
|
root=None, depth=5, force=False, fetch=False, clean=True) |
93
|
|
|
|
94
|
|
|
@patch('gitman.commands.install') |
95
|
|
|
def test_install_specific_sources(self, mock_install): |
96
|
|
|
"""Verify individual dependencies can be installed.""" |
97
|
|
|
cli.main(['install', 'foo', 'bar']) |
98
|
|
|
|
99
|
|
|
mock_install.assert_called_once_with( |
100
|
|
|
'foo', 'bar', root=None, depth=5, |
101
|
|
|
force=False, fetch=False, clean=False) |
102
|
|
|
|
103
|
|
|
@patch('gitman.commands.install') |
104
|
|
|
def test_install_with_depth(self, mock_update): |
105
|
|
|
"""Verify the 'install' command can be limited by depth.""" |
106
|
|
|
cli.main(['install', '--depth', '10']) |
107
|
|
|
|
108
|
|
|
mock_update.assert_called_once_with( |
109
|
|
|
root=None, depth=10, force=False, fetch=False, clean=False) |
110
|
|
|
|
111
|
|
|
@patch('gitman.commands.install', Mock()) |
112
|
|
|
def test_install_with_depth_invalid(self): |
113
|
|
|
"""Verify depths below 1 are rejected.""" |
114
|
|
|
with pytest.raises(SystemExit): |
115
|
|
|
cli.main(['install', '--depth', '0']) |
116
|
|
|
with pytest.raises(SystemExit): |
117
|
|
|
cli.main(['install', '--depth', '-1']) |
118
|
|
|
|
119
|
|
|
|
120
|
|
|
class TestUpdate: |
121
|
|
|
"""Unit tests for the `update` command.""" |
122
|
|
|
|
123
|
|
|
@patch('gitman.commands.update') |
124
|
|
|
def test_update(self, mock_update): |
125
|
|
|
"""Verify the 'update' command can be run.""" |
126
|
|
|
cli.main(['update']) |
127
|
|
|
|
128
|
|
|
mock_update.assert_called_once_with( |
129
|
|
|
root=None, depth=5, |
130
|
|
|
force=False, clean=False, recurse=False, lock=None) |
131
|
|
|
|
132
|
|
|
@patch('gitman.commands.update') |
133
|
|
|
def test_update_recursive(self, mock_update): |
134
|
|
|
"""Verify the 'update' command can be run recursively.""" |
135
|
|
|
cli.main(['update', '--all']) |
136
|
|
|
|
137
|
|
|
mock_update.assert_called_once_with( |
138
|
|
|
root=None, depth=5, |
139
|
|
|
force=False, clean=False, recurse=True, lock=None) |
140
|
|
|
|
141
|
|
|
@patch('gitman.commands.update') |
142
|
|
|
def test_update_no_lock(self, mock_update): |
143
|
|
|
"""Verify the 'update' command can disable locking.""" |
144
|
|
|
cli.main(['update', '--no-lock']) |
145
|
|
|
|
146
|
|
|
mock_update.assert_called_once_with( |
147
|
|
|
root=None, depth=5, |
148
|
|
|
force=False, clean=False, recurse=False, lock=False) |
149
|
|
|
|
150
|
|
|
@patch('gitman.commands.update') |
151
|
|
|
def test_update_lock(self, mock_update): |
152
|
|
|
"""Verify the 'update' command can enable locking.""" |
153
|
|
|
cli.main(['update', '--lock']) |
154
|
|
|
|
155
|
|
|
mock_update.assert_called_once_with( |
156
|
|
|
root=None, depth=5, |
157
|
|
|
force=False, clean=False, recurse=False, lock=True) |
158
|
|
|
|
159
|
|
|
def test_update_lock_conflict(self): |
160
|
|
|
"""Verify the 'update' command cannot specify both locking options.""" |
161
|
|
|
with pytest.raises(SystemExit): |
162
|
|
|
cli.main(['update', '--lock', '--no-lock']) |
163
|
|
|
|
164
|
|
|
@patch('gitman.commands.update') |
165
|
|
|
def test_update_specific_sources(self, mock_install): |
166
|
|
|
"""Verify individual dependencies can be installed.""" |
167
|
|
|
cli.main(['update', 'foo', 'bar']) |
168
|
|
|
|
169
|
|
|
mock_install.assert_called_once_with( |
170
|
|
|
'foo', 'bar', root=None, depth=5, |
171
|
|
|
force=False, clean=False, recurse=False, lock=None) |
172
|
|
|
|
173
|
|
|
@patch('gitman.commands.update') |
174
|
|
|
def test_update_with_depth(self, mock_update): |
175
|
|
|
"""Verify the 'update' command can be limited by depth.""" |
176
|
|
|
cli.main(['update', '--depth', '10']) |
177
|
|
|
|
178
|
|
|
mock_update.assert_called_once_with( |
179
|
|
|
root=None, depth=10, |
180
|
|
|
force=False, clean=False, recurse=False, lock=None) |
181
|
|
|
|
182
|
|
|
|
183
|
|
|
class TestList: |
184
|
|
|
"""Unit tests for the `list` command.""" |
185
|
|
|
|
186
|
|
|
@patch('gitman.commands.display') |
187
|
|
|
def test_list(self, mock_display): |
188
|
|
|
"""Verify the 'list' command can be run.""" |
189
|
|
|
cli.main(['list']) |
190
|
|
|
|
191
|
|
|
mock_display.assert_called_once_with( |
192
|
|
|
root=None, depth=5, allow_dirty=True) |
193
|
|
|
|
194
|
|
|
@patch('gitman.commands.display') |
195
|
|
|
def test_list_root(self, mock_display): |
196
|
|
|
"""Verify the project's root can be specified.""" |
197
|
|
|
cli.main(['list', '--root', 'mock/path/to/root']) |
198
|
|
|
|
199
|
|
|
mock_display.assert_called_once_with( |
200
|
|
|
root='mock/path/to/root', depth=5, allow_dirty=True) |
201
|
|
|
|
202
|
|
|
@patch('gitman.commands.display') |
203
|
|
|
def test_list_no_dirty(self, mock_display): |
204
|
|
|
"""Verify the 'list' command can be set to fail when dirty.""" |
205
|
|
|
cli.main(['list', '--no-dirty']) |
206
|
|
|
|
207
|
|
|
mock_display.assert_called_once_with( |
208
|
|
|
root=None, depth=5, allow_dirty=False) |
209
|
|
|
|
210
|
|
|
@patch('gitman.commands.display') |
211
|
|
|
def test_update_with_depth(self, mock_update): |
212
|
|
|
"""Verify the 'list' command can be limited by depth.""" |
213
|
|
|
cli.main(['list', '--depth', '10']) |
214
|
|
|
|
215
|
|
|
mock_update.assert_called_once_with( |
216
|
|
|
root=None, depth=10, allow_dirty=True) |
217
|
|
|
|
218
|
|
|
|
219
|
|
|
def describe_lock(): |
220
|
|
|
|
221
|
|
|
@patch('gitman.commands.lock') |
222
|
|
|
def with_no_arguments(lock): |
223
|
|
|
cli.main(['lock']) |
224
|
|
|
lock.assert_called_once_with(root=None) |
225
|
|
|
|
226
|
|
|
@patch('gitman.commands.lock') |
227
|
|
|
def with_dependencies(lock): |
228
|
|
|
cli.main(['lock', 'foo', 'bar']) |
229
|
|
|
lock.assert_called_once_with('foo', 'bar', root=None) |
230
|
|
|
|
231
|
|
|
|
232
|
|
|
class TestUninstall: |
233
|
|
|
"""Unit tests for the `uninstall` command.""" |
234
|
|
|
|
235
|
|
|
@patch('gitman.commands.delete') |
236
|
|
|
def test_uninstall(self, mock_uninstall): |
237
|
|
|
"""Verify the 'uninstall' command can be run.""" |
238
|
|
|
cli.main(['uninstall']) |
239
|
|
|
|
240
|
|
|
mock_uninstall.assert_called_once_with( |
241
|
|
|
root=None, force=False) |
242
|
|
|
|
243
|
|
|
@patch('gitman.commands.delete') |
244
|
|
|
def test_uninstall_root(self, mock_uninstall): |
245
|
|
|
"""Verify the project's root can be specified.""" |
246
|
|
|
cli.main(['uninstall', '--root', 'mock/path/to/root']) |
247
|
|
|
|
248
|
|
|
mock_uninstall.assert_called_once_with( |
249
|
|
|
root='mock/path/to/root', force=False) |
250
|
|
|
|
251
|
|
|
@patch('gitman.commands.delete') |
252
|
|
|
def test_uninstall_force(self, mock_uninstall): |
253
|
|
|
"""Verify the 'uninstall' command can be forced.""" |
254
|
|
|
cli.main(['uninstall', '--force']) |
255
|
|
|
|
256
|
|
|
mock_uninstall.assert_called_once_with( |
257
|
|
|
root=None, force=True) |
258
|
|
|
|
259
|
|
|
|
260
|
|
|
def describe_show(): |
261
|
|
|
|
262
|
|
|
@patch('gitman.commands.show') |
263
|
|
|
def with_no_arguments(show): |
264
|
|
|
cli.main(['show']) |
265
|
|
|
show.assert_called_once_with(root=None) |
266
|
|
|
|
267
|
|
|
@patch('gitman.commands.show') |
268
|
|
|
def with_root(show): |
269
|
|
|
cli.main(['show', '--root', "mock/root"]) |
270
|
|
|
show.assert_called_once_with(root="mock/root") |
271
|
|
|
|
272
|
|
|
@patch('gitman.commands.show') |
273
|
|
|
def with_names(show): |
274
|
|
|
cli.main(['show', 'foo', 'bar']) |
275
|
|
|
show.assert_called_once_with('foo', 'bar', root=None) |
276
|
|
|
|
277
|
|
|
@patch('gitman.commands.show') |
278
|
|
|
def with_config(show): |
279
|
|
|
cli.main(['show', '--config']) |
280
|
|
|
show.assert_called_once_with('__config__', root=None) |
281
|
|
|
|
282
|
|
|
@patch('gitman.commands.show') |
283
|
|
|
def with_log(show): |
284
|
|
|
cli.main(['show', '--log']) |
285
|
|
|
show.assert_called_once_with('__log__', root=None) |
286
|
|
|
|
287
|
|
|
|
288
|
|
|
def describe_edit(): |
289
|
|
|
|
290
|
|
|
@patch('gitman.commands.edit') |
291
|
|
|
def with_no_arguments(edit): |
292
|
|
|
cli.main(['edit']) |
293
|
|
|
edit.assert_called_once_with(root=None) |
294
|
|
|
|
295
|
|
|
@patch('gitman.commands.edit') |
296
|
|
|
def with_root(edit): |
297
|
|
|
cli.main(['edit', '--root', "mock/root"]) |
298
|
|
|
edit.assert_called_once_with(root="mock/root") |
299
|
|
|
|
300
|
|
|
|
301
|
|
|
def describe_logging(): |
302
|
|
|
|
303
|
|
|
argument_verbosity = [ |
304
|
|
|
(None, 0), |
305
|
|
|
('-v', 1), |
306
|
|
|
('-vv', 2), |
307
|
|
|
('-vvv', 3), |
308
|
|
|
('-vvvv', 4), |
309
|
|
|
('-vvvvv', 4), |
310
|
|
|
('-q', -1), |
311
|
|
|
] |
312
|
|
|
|
313
|
|
|
@pytest.mark.parametrize("argument,verbosity", argument_verbosity) |
314
|
|
|
def at_each_level(argument, verbosity): |
315
|
|
|
|
316
|
|
|
def function(*args, **kwargs): |
317
|
|
|
logging.debug(args) |
318
|
|
|
logging.debug(kwargs) |
319
|
|
|
logging.warning("warning") |
320
|
|
|
logging.error("error") |
321
|
|
|
return True |
322
|
|
|
|
323
|
|
|
cli.main([argument] if argument else [], function) |
324
|
|
|
expect(_Config.verbosity) == verbosity |
325
|
|
|
|
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.
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.