forked from conda/conda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_cli.py
130 lines (103 loc) · 5.13 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
import json
import unittest
from conda._vendor.auxlib.ish import dals
import pytest
from conda.base.context import context
from conda.common.io import captured
from conda.gateways.disk.delete import rm_rf
from tests.helpers import capture_json_with_argv, run_inprocess_conda_command
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 tearDown(self):
rm_rf('tempfile.rc')
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)
if context.root_writable:
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 --get use_pip --json')
self.assertJsonSuccess(res)
@pytest.mark.integration
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_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'] == 'EnvironmentLocationNotFound'
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'] == 'EnvironmentLocationNotFound'
assert stderr == ''
assert rc > 0
@pytest.mark.integration
def test_search_0(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', 'fn', 'version')
for key in keys:
self.assertIn(key, res['conda'][0])
stdout, stderr, rc = run_inprocess_conda_command('conda search * --json')
assert stderr == ''
assert rc is None
@pytest.mark.integration
def test_search_1(self):
self.assertIsInstance(capture_json_with_argv('conda search ipython --json'), dict)
@pytest.mark.integration
def test_search_2(self):
from tests.test_create import make_temp_env
from tests.test_create import run_command
from tests.test_create import Commands
with make_temp_env() as prefix:
stdout, stderr = run_command(Commands.SEARCH, prefix, "nose", use_exception_handler=True)
result = stdout.replace("Loading channels: ...working... done", "")
assert "nose 1.3.4 py34_0 defaults" in result
@pytest.mark.integration
def test_search_3(self):
from tests.test_create import make_temp_env
from tests.test_create import run_command
from tests.test_create import Commands
with make_temp_env() as prefix:
stdout, stderr = run_command(Commands.SEARCH, prefix, "*/linux-64::nose==1.3.7[build=py36_1]", "--info", use_exception_handler=True)
result = stdout.replace("Loading channels: ...working... done", "")
assert "file name : nose-1.3.7-py36_1.tar.bz2" in result
assert "name : nose" in result
assert "url : https://repo.continuum.io/pkgs/free/linux-64/nose-1.3.7-py36_1.tar.bz2" in result
assert "md5 : f4f697f5ad4df9c8fe35357d269718a5" in result
@pytest.mark.integration
def test_search_4(self):
self.assertIsInstance(capture_json_with_argv('conda search --json --use-index-cache'), dict)
@pytest.mark.integration
def test_search_5(self):
self.assertIsInstance(capture_json_with_argv('conda search --platform win-32 --json'), dict)