forked from conda/conda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_cli.py
263 lines (217 loc) · 10.9 KB
/
test_cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
import json
import unittest
import pytest
from conda.cli.common import arg2spec, spec_from_line
from conda.common.io import captured
from conda.compat import text_type
from conda.exceptions import CondaValueError
from tests.helpers import capture_json_with_argv, assert_in, run_inprocess_conda_command
class TestArg2Spec(unittest.TestCase):
def test_simple(self):
self.assertEqual(arg2spec('python'), 'python')
self.assertEqual(arg2spec('python=2.6'), 'python 2.6*')
self.assertEqual(arg2spec('python=2.6*'), 'python 2.6*')
self.assertEqual(arg2spec('ipython=0.13.2'), 'ipython 0.13.2*')
self.assertEqual(arg2spec('ipython=0.13.0'), 'ipython 0.13.0*')
self.assertEqual(arg2spec('foo=1.3.0=3'), 'foo 1.3.0 3')
def test_pip_style(self):
self.assertEqual(arg2spec('foo>=1.3'), 'foo >=1.3')
self.assertEqual(arg2spec('zope.int>=1.3,<3.0'), 'zope.int >=1.3,<3.0')
self.assertEqual(arg2spec('numpy >=1.9'), 'numpy >=1.9')
def test_invalid(self):
self.assertRaises(CondaValueError, arg2spec, '!xyz 1.3')
class TestSpecFromLine(unittest.TestCase):
def test_invalid(self):
self.assertEqual(spec_from_line('='), None)
self.assertEqual(spec_from_line('foo 1.0'), None)
def test_comment(self):
self.assertEqual(spec_from_line('foo # comment'), 'foo')
self.assertEqual(spec_from_line('foo ## comment'), 'foo')
def test_conda_style(self):
self.assertEqual(spec_from_line('foo'), 'foo')
self.assertEqual(spec_from_line('foo=1.0'), 'foo 1.0')
self.assertEqual(spec_from_line('foo=1.0*'), 'foo 1.0*')
self.assertEqual(spec_from_line('foo=1.0|1.2'), 'foo 1.0|1.2')
self.assertEqual(spec_from_line('foo=1.0=2'), 'foo 1.0 2')
def test_pip_style(self):
self.assertEqual(spec_from_line('foo>=1.0'), 'foo >=1.0')
self.assertEqual(spec_from_line('foo >=1.0'), 'foo >=1.0')
self.assertEqual(spec_from_line('FOO-Bar >=1.0'), 'foo-bar >=1.0')
self.assertEqual(spec_from_line('foo >= 1.0'), 'foo >=1.0')
self.assertEqual(spec_from_line('foo > 1.0'), 'foo >1.0')
self.assertEqual(spec_from_line('foo != 1.0'), 'foo !=1.0')
self.assertEqual(spec_from_line('foo <1.0'), 'foo <1.0')
self.assertEqual(spec_from_line('foo >=1.0 , < 2.0'), 'foo >=1.0,<2.0')
class TestJson(unittest.TestCase):
def assertJsonSuccess(self, res):
self.assertIsInstance(res, dict)
self.assertIn('success', res)
def assertJsonError(self, res):
self.assertIsInstance(res, dict)
self.assertIn('error', res)
# def test_clean(self):
# res = capture_json_with_argv('conda', 'clean', '--index-cache', '--lock',
# '--packages', '--tarballs', '--json')
# self.assertJsonSuccess(res)
def test_config(self):
res = capture_json_with_argv('conda config --get --json')
self.assertJsonSuccess(res)
res = capture_json_with_argv('conda config --get channels --json')
self.assertJsonSuccess(res)
res = capture_json_with_argv('conda config --get channels --system --json')
self.assertJsonSuccess(res)
res = capture_json_with_argv('conda config --get channels --file tempfile.rc --json')
self.assertJsonSuccess(res)
res = capture_json_with_argv('conda config --get channels --file tempfile.rc --file tempfile.rc --json')
self.assertJsonSuccess(res)
# res = capture_json_with_argv('conda', 'config', '--add', 'channels',
# 'binstar', '--json')
# self.assertIsInstance(res, dict)
#
# res = capture_json_with_argv('conda', 'config', '--add', 'channels',
# 'binstar', '--force', '--json')
# self.assertJsonSuccess(res)
#
# res = capture_json_with_argv('conda', 'config', '--remove', 'channels',
# 'binstar', '--json')
# self.assertJsonError(res)
#
# res = capture_json_with_argv('conda', 'config', '--remove', 'channels',
# 'binstar', '--force', '--json')
# self.assertJsonSuccess(res)
#
# res = capture_json_with_argv('conda', 'config', '--remove', 'channels',
# 'nonexistent', '--force', '--json')
# self.assertJsonError(res)
#
# res = capture_json_with_argv('conda', 'config', '--remove', 'envs_dirs',
# 'binstar', '--json')
# self.assertJsonError(res)
#
# res = capture_json_with_argv('conda', 'config', '--set', 'use_pip',
# 'yes', '--json')
# self.assertJsonSuccess(res)
res = capture_json_with_argv('conda config --get use_pip --json')
self.assertJsonSuccess(res)
# self.assertTrue(res['get']['use_pip'])
# res = capture_json_with_argv('conda', 'config', '--remove-key', 'use_pip',
# '--json')
# self.assertJsonError(res)
#
# res = capture_json_with_argv('conda', 'config', '--remove-key', 'use_pip',
# '--force', '--json')
# self.assertJsonSuccess(res)q
#
# res = capture_json_with_argv('conda', 'config', '--remove-key', 'use_pip',
# '--force', '--json')
# self.assertJsonError(res)
@pytest.mark.slow
def test_info(self):
res = capture_json_with_argv('conda info --json')
keys = ('channels', 'conda_version', 'default_prefix', 'envs',
'envs_dirs', 'pkgs_dirs', 'platform',
'python_version', 'rc_path', 'root_prefix', 'root_writable')
self.assertIsInstance(res, dict)
for key in keys:
assert key in res
res = capture_json_with_argv('conda info conda --json')
self.assertIsInstance(res, dict)
self.assertIn('conda', res)
self.assertIsInstance(res['conda'], list)
# def test_install(self):
# res = capture_json_with_argv('conda', 'install', 'pip', '--json', '--quiet')
# self.assertJsonSuccess(res)
#
# res = capture_json_with_argv('conda', 'update', 'pip', '--json', '--quiet')
# self.assertJsonSuccess(res)
#
# res = capture_json_with_argv('conda', 'remove', 'pip', '--json', '--quiet')
# self.assertJsonSuccess(res)
#
# res = capture_json_with_argv('conda', 'remove', 'pip', '--json', '--quiet')
# self.assertJsonError(res)
#
# res = capture_json_with_argv('conda', 'update', 'pip', '--json', '--quiet')
# self.assertJsonError(res)
#
# res = capture_json_with_argv('conda', 'install', 'pip=1.5.5', '--json', '--quiet')
# self.assertJsonSuccess(res)
#
# res = capture_json_with_argv('conda', 'install', '=', '--json', '--quiet')
# self.assertJsonError(res)
#
# res = capture_json_with_argv('conda', 'remove', '-n', 'testing',
# '--all', '--json', '--quiet')
# self.assertJsonSuccess(res)
#
# res = capture_json_with_argv('conda', 'remove', '-n', 'testing',
# '--all', '--json', '--quiet')
# self.assertJsonSuccess(res)
#
# res = capture_json_with_argv('conda', 'remove', '-n', 'testing2',
# '--all', '--json', '--quiet')
# self.assertJsonSuccess(res)
#
# res = capture_json_with_argv('conda', 'create', '-n', 'testing',
# 'python', '--json', '--quiet')
# self.assertJsonSuccess(res)
#
# res = capture_json_with_argv('conda', 'install', '-n', 'testing',
# 'python', '--json', '--quiet')
# self.assertJsonSuccess(res)
#
# res = capture_json_with_argv('conda', 'install', '--dry-run',
# 'python', '--json', '--quiet')
# self.assertJsonSuccess(res)
#
# res = capture_json_with_argv('conda', 'create', '--clone', 'testing',
# '-n', 'testing2', '--json', '--quiet')
# self.assertJsonSuccess(res)
def test_list(self):
res = capture_json_with_argv('conda list --json')
self.assertIsInstance(res, list)
res = capture_json_with_argv('conda list -r --json')
self.assertTrue(isinstance(res, list) or
(isinstance(res, dict) and 'error' in res))
res = capture_json_with_argv('conda list ipython --json')
self.assertIsInstance(res, list)
stdout, stderr, rc = run_inprocess_conda_command('conda list --name nonexistent --json')
assert json.loads(stdout.strip())['exception_name'] == 'CondaEnvironmentNotFoundError'
assert stderr == ''
assert rc > 0
stdout, stderr, rc = run_inprocess_conda_command('conda list --name nonexistent --revisions --json')
assert json.loads(stdout.strip())['exception_name'] == 'CondaEnvironmentNotFoundError'
assert stderr == ''
assert rc > 0
@pytest.mark.timeout(300)
def test_search(self):
with captured():
res = capture_json_with_argv('conda search --json')
self.assertIsInstance(res, dict)
self.assertIsInstance(res['conda'], list)
self.assertIsInstance(res['conda'][0], dict)
keys = ('build', 'channel', 'extracted', 'features', 'fn',
'installed', 'version')
for key in keys:
self.assertIn(key, res['conda'][0])
stdout, stderr, rc = run_inprocess_conda_command('conda search * --json')
assert json.loads(stdout.strip())['exception_name'] == 'CommandArgumentError'
assert stderr == ''
assert rc > 0
res = capture_json_with_argv('conda search --canonical --json')
self.assertIsInstance(res, list)
self.assertIsInstance(res[0], text_type)
def test_search_1(self):
self.assertIsInstance(capture_json_with_argv('conda search ipython --json'), dict)
def test_search_2(self):
self.assertIsInstance(capture_json_with_argv('conda search --unknown --json'), dict)
def test_search_3(self):
self.assertIsInstance(capture_json_with_argv('conda search --json --use-index-cache'), dict)
def test_search_4(self):
self.assertIsInstance(capture_json_with_argv('conda search --json --outdated'), dict)
def test_search_5(self):
self.assertIsInstance(capture_json_with_argv('conda search -c https://conda.anaconda.org/conda --json nose'), dict)
def test_search_6(self):
self.assertIsInstance(capture_json_with_argv('conda search -c https://conda.anaconda.org/conda --override-channel --json nose'), dict)
def test_search_7(self):
self.assertIsInstance(capture_json_with_argv('conda search --platform win-32 --json'), dict)