forked from conda/conda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_config.py
669 lines (581 loc) · 25 KB
/
test_config.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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
# (c) 2012-2014 Continuum Analytics, Inc. / http://continuum.io
# All Rights Reserved
#
# conda is distributed under the terms of the BSD 3-clause license.
# Consult LICENSE.txt or http://opensource.org/licenses/BSD-3-Clause.
import os
import pytest
import unittest
from contextlib import contextmanager
from datetime import datetime
from os.path import join, dirname
from tempfile import mkstemp, NamedTemporaryFile
from conda import config
from conda.base.constants import DEFAULT_CHANNEL_ALIAS
from conda.base.context import (reset_context, pkgs_dir_from_envs_dir, context)
from conda.common.yaml import yaml_load
from conda.utils import backoff_unlink
from tests.helpers import run_conda_command
# use condarc from source tree to run these tests against
# # unset 'default_channels' so get_default_channels has predictable behavior
# try:
# del config.sys_rc['default_channels']
# except KeyError:
# pass
# unset CIO_TEST. This is a Continuum-internal variable that draws packages from an internal server instead of
# repo.continuum.io
try:
del os.environ['CIO_TEST']
except KeyError:
pass
# # Remove msys2 from defaults just for testing purposes
# if len(config.defaults_) > 2:
# config.defaults_ = config.defaults_[:2]
# class BinstarTester(object):
# def __init__(self, domain='https://mybinstar.com', token='01234abcde'):
# self.domain = domain
# self.token = token
class TestConfig(unittest.TestCase):
# These tests are mostly to ensure API stability
# def setUp(self):
# # Load the test condarc file
# self.rc, config.rc = config.rc, testrc
# config.load_condarc()
# config.binstar_client = BinstarTester()
# config.init_binstar()
#
# def tearDown(self):
# # Restore original condarc
# config.rc = self.rc
# config.load_condarc()
def test_globals(self):
self.assertTrue(config.root_dir)
self.assertTrue(config.pkgs_dirs)
self.assertTrue(config.envs_dirs)
self.assertTrue(config.default_prefix)
self.assertTrue(config.platform)
self.assertTrue(config.subdir)
self.assertTrue(config.arch_name)
self.assertTrue(config.bits in (32, 64))
def test_pkgs_dir_from_envs_dir(self):
root_dir = context.root_dir
root_pkgs = join(root_dir, 'pkgs')
for pi, po in [
(join(root_dir, 'envs'), root_pkgs),
('/usr/local/foo/envs' if context.platform != 'win' else 'C:\envs',
'/usr/local/foo/envs/.pkgs' if context.platform != 'win' else 'C:\envs\.pkgs'),
]:
self.assertEqual(pkgs_dir_from_envs_dir(pi), po)
# def test_proxy_settings(self):
# self.assertEqual(config.get_proxy_servers(),
# {'http': 'http://user:[email protected]:8080',
# 'https': 'https://user:[email protected]:8080'})
# @pytest.mark.xfail(datetime.now() < datetime(2016, 8, 1),
# reason="refactor to work with Channel entity")
def test_normalize_urls(self):
context = reset_context([join(dirname(__file__), 'condarc')])
current_platform = context.subdir
assert DEFAULT_CHANNEL_ALIAS == 'https://conda.anaconda.org/'
assert context.channel_alias == 'https://your.repo/'
# assert binstar.channel_prefix(False) == 'https://your.repo/'
# assert binstar.binstar_domain == 'https://mybinstar.com/'
# assert binstar.binstar_domain_tok == 'https://mybinstar.com/t/01234abcde/'
assert context.channels == ("binstar_username", "http://some.custom/channel", "defaults")
channel_urls = [
'defaults',
'system',
'https://conda.anaconda.org/username',
'file:///Users/username/repo',
'https://mybinstar.com/t/5768wxyz/test2',
'https://mybinstar.com/test',
'https://conda.anaconda.org/t/abcdefgh/username',
'username'
]
platform = 'osx-64'
# normurls = config.normalize_urls(channel_urls, platform)
# assert normurls == [
# # defaults
# 'https://repo.continuum.io/pkgs/free/osx-64/',
# 'https://repo.continuum.io/pkgs/free/noarch/',
# 'https://repo.continuum.io/pkgs/pro/osx-64/',
# 'https://repo.continuum.io/pkgs/pro/noarch/',
# # system (condarc)
# 'https://your.repo/binstar_username/osx-64/',
# 'https://your.repo/binstar_username/noarch/',
# 'http://some.custom/channel/osx-64/',
# 'http://some.custom/channel/noarch/',
# # defaults is repeated in condarc; that's OK
# 'https://repo.continuum.io/pkgs/free/osx-64/',
# 'https://repo.continuum.io/pkgs/free/noarch/',
# 'https://repo.continuum.io/pkgs/pro/osx-64/',
# 'https://repo.continuum.io/pkgs/pro/noarch/',
# # conda.anaconda.org is not our default binstar clinet
# 'https://conda.anaconda.org/username/osx-64/',
# 'https://conda.anaconda.org/username/noarch/',
# 'file:///Users/username/repo/osx-64/',
# 'file:///Users/username/repo/noarch/',
# # mybinstar.com is not channel_alias, but we still add tokens
# 'https://mybinstar.com/t/5768wxyz/test2/osx-64/',
# 'https://mybinstar.com/t/5768wxyz/test2/noarch/',
# # token already supplied, do not change/remove it
# 'https://mybinstar.com/t/01234abcde/test/osx-64/',
# 'https://mybinstar.com/t/01234abcde/test/noarch/',
# # we do not remove tokens from conda.anaconda.org
# 'https://conda.anaconda.org/t/abcdefgh/username/osx-64/',
# 'https://conda.anaconda.org/t/abcdefgh/username/noarch/',
# # short channel; add channel_alias
# 'https://your.repo/username/osx-64/',
# 'https://your.repo/username/noarch/']
#
# priurls = config.prioritize_channels(normurls)
# assert dict(priurls) == {
# # defaults appears twice, keep higher priority
# 'https://repo.continuum.io/pkgs/free/noarch/': ('defaults', 1),
# 'https://repo.continuum.io/pkgs/free/osx-64/': ('defaults', 1),
# 'https://repo.continuum.io/pkgs/pro/noarch/': ('defaults', 1),
# 'https://repo.continuum.io/pkgs/pro/osx-64/': ('defaults', 1),
# 'https://your.repo/binstar_username/noarch/': ('binstar_username', 2),
# 'https://your.repo/binstar_username/osx-64/': ('binstar_username', 2),
# 'http://some.custom/channel/noarch/': ('http://some.custom/channel', 3),
# 'http://some.custom/channel/osx-64/': ('http://some.custom/channel', 3),
# 'https://conda.anaconda.org/t/abcdefgh/username/noarch/': ('https://conda.anaconda.org/username', 4),
# 'https://conda.anaconda.org/t/abcdefgh/username/osx-64/': ('https://conda.anaconda.org/username', 4),
# 'file:///Users/username/repo/noarch/': ('file:///Users/username/repo', 5),
# 'file:///Users/username/repo/osx-64/': ('file:///Users/username/repo', 5),
# # the tokenized version came first, but we still give it the same priority
# 'https://conda.anaconda.org/username/noarch/': ('https://conda.anaconda.org/username', 4),
# 'https://conda.anaconda.org/username/osx-64/': ('https://conda.anaconda.org/username', 4),
# 'https://mybinstar.com/t/5768wxyz/test2/noarch/': ('https://mybinstar.com/test2', 6),
# 'https://mybinstar.com/t/5768wxyz/test2/osx-64/': ('https://mybinstar.com/test2', 6),
# 'https://mybinstar.com/t/01234abcde/test/noarch/': ('https://mybinstar.com/test', 7),
# 'https://mybinstar.com/t/01234abcde/test/osx-64/': ('https://mybinstar.com/test', 7),
# 'https://your.repo/username/noarch/': ('username', 8),
# 'https://your.repo/username/osx-64/': ('username', 8)
# }
#
# # Delete the channel alias so now the short channels point to binstar
# del config.rc['channel_alias']
# config.rc['offline'] = False
# config.load_condarc()
# config.binstar_client = BinstarTester()
# normurls = config.normalize_urls(channel_urls, platform)
# # all your.repo references should be changed to mybinstar.com
# assert normurls == [
# 'https://repo.continuum.io/pkgs/free/osx-64/',
# 'https://repo.continuum.io/pkgs/free/noarch/',
# 'https://repo.continuum.io/pkgs/pro/osx-64/',
# 'https://repo.continuum.io/pkgs/pro/noarch/',
# 'https://mybinstar.com/t/01234abcde/binstar_username/osx-64/',
# 'https://mybinstar.com/t/01234abcde/binstar_username/noarch/',
# 'http://some.custom/channel/osx-64/',
# 'http://some.custom/channel/noarch/',
# 'https://repo.continuum.io/pkgs/free/osx-64/',
# 'https://repo.continuum.io/pkgs/free/noarch/',
# 'https://repo.continuum.io/pkgs/pro/osx-64/',
# 'https://repo.continuum.io/pkgs/pro/noarch/',
# 'https://conda.anaconda.org/username/osx-64/',
# 'https://conda.anaconda.org/username/noarch/',
# 'file:///Users/username/repo/osx-64/',
# 'file:///Users/username/repo/noarch/',
# 'https://mybinstar.com/t/5768wxyz/test2/osx-64/',
# 'https://mybinstar.com/t/5768wxyz/test2/noarch/',
# 'https://mybinstar.com/t/01234abcde/test/osx-64/',
# 'https://mybinstar.com/t/01234abcde/test/noarch/',
# 'https://conda.anaconda.org/t/abcdefgh/username/osx-64/',
# 'https://conda.anaconda.org/t/abcdefgh/username/noarch/',
# 'https://mybinstar.com/t/01234abcde/username/osx-64/',
# 'https://mybinstar.com/t/01234abcde/username/noarch/'
# ]
#
# # Delete the anaconda token
# config.load_condarc()
# config.binstar_client = BinstarTester(token=None)
# normurls = config.normalize_urls(channel_urls, platform)
# # tokens should not be added (but supplied tokens are kept)
# assert normurls == [
# 'https://repo.continuum.io/pkgs/free/osx-64/',
# 'https://repo.continuum.io/pkgs/free/noarch/',
# 'https://repo.continuum.io/pkgs/pro/osx-64/',
# 'https://repo.continuum.io/pkgs/pro/noarch/',
# 'https://mybinstar.com/binstar_username/osx-64/',
# 'https://mybinstar.com/binstar_username/noarch/',
# 'http://some.custom/channel/osx-64/',
# 'http://some.custom/channel/noarch/',
# 'https://repo.continuum.io/pkgs/free/osx-64/',
# 'https://repo.continuum.io/pkgs/free/noarch/',
# 'https://repo.continuum.io/pkgs/pro/osx-64/',
# 'https://repo.continuum.io/pkgs/pro/noarch/',
# 'https://conda.anaconda.org/username/osx-64/',
# 'https://conda.anaconda.org/username/noarch/',
# 'file:///Users/username/repo/osx-64/',
# 'file:///Users/username/repo/noarch/',
# 'https://mybinstar.com/t/5768wxyz/test2/osx-64/',
# 'https://mybinstar.com/t/5768wxyz/test2/noarch/',
# 'https://mybinstar.com/test/osx-64/',
# 'https://mybinstar.com/test/noarch/',
# 'https://conda.anaconda.org/t/abcdefgh/username/osx-64/',
# 'https://conda.anaconda.org/t/abcdefgh/username/noarch/',
# 'https://mybinstar.com/username/osx-64/',
# 'https://mybinstar.com/username/noarch/'
# ]
#
# # Turn off add_anaconda_token
# config.rc['add_binstar_token'] = False
# config.load_condarc()
# config.binstar_client = BinstarTester()
# normurls2 = config.normalize_urls(channel_urls, platform)
# # tokens should not be added (but supplied tokens are kept)
# assert normurls == normurls2
#
# # Disable binstar client altogether
# config.load_condarc()
# config.binstar_client = ()
# normurls = config.normalize_urls(channel_urls, platform)
# # should drop back to conda.anaconda.org
# assert normurls == [
# 'https://repo.continuum.io/pkgs/free/osx-64/',
# 'https://repo.continuum.io/pkgs/free/noarch/',
# 'https://repo.continuum.io/pkgs/pro/osx-64/',
# 'https://repo.continuum.io/pkgs/pro/noarch/',
# 'https://conda.anaconda.org/binstar_username/osx-64/',
# 'https://conda.anaconda.org/binstar_username/noarch/',
# 'http://some.custom/channel/osx-64/',
# 'http://some.custom/channel/noarch/',
# 'https://repo.continuum.io/pkgs/free/osx-64/',
# 'https://repo.continuum.io/pkgs/free/noarch/',
# 'https://repo.continuum.io/pkgs/pro/osx-64/',
# 'https://repo.continuum.io/pkgs/pro/noarch/',
# 'https://conda.anaconda.org/username/osx-64/',
# 'https://conda.anaconda.org/username/noarch/',
# 'file:///Users/username/repo/osx-64/',
# 'file:///Users/username/repo/noarch/',
# 'https://mybinstar.com/t/5768wxyz/test2/osx-64/',
# 'https://mybinstar.com/t/5768wxyz/test2/noarch/',
# 'https://mybinstar.com/test/osx-64/',
# 'https://mybinstar.com/test/noarch/',
# 'https://conda.anaconda.org/t/abcdefgh/username/osx-64/',
# 'https://conda.anaconda.org/t/abcdefgh/username/noarch/',
# 'https://conda.anaconda.org/username/osx-64/',
# 'https://conda.anaconda.org/username/noarch/'
# ]
@contextmanager
def make_temp_condarc(value=None):
try:
tempfile = NamedTemporaryFile(suffix='.yml', delete=False)
tempfile.close()
temp_path = tempfile.name
if value:
with open(temp_path, 'w') as f:
f.write(value)
reset_context([temp_path])
yield temp_path
finally:
backoff_unlink(temp_path)
def _read_test_condarc(rc):
with open(rc) as f:
return f.read()
# Tests for the conda config command
# FIXME This shoiuld be multiple individual tests
@pytest.mark.slow
def test_config_command_basics():
# Test that creating the file adds the defaults channel
with make_temp_condarc() as rc:
stdout, stderr = run_conda_command('config', '--file', rc, '--add',
'channels', 'test')
assert stdout == stderr == ''
assert _read_test_condarc(rc) == """\
channels:
- defaults
- test
"""
print(_read_test_condarc(rc))
print(_read_test_condarc(rc))
print(_read_test_condarc(rc))
with make_temp_condarc() as rc:
# When defaults is explicitly given, it should not be added
stdout, stderr = run_conda_command('config', '--file', rc, '--add',
'channels', 'test', '--add', 'channels', 'defaults')
assert stdout == ''
assert stderr == "Warning: 'defaults' already in 'channels' list, moving to the bottom"
assert _read_test_condarc(rc) == """\
channels:
- test
- defaults
"""
# Duplicate keys should not be added twice
with make_temp_condarc() as rc:
stdout, stderr = run_conda_command('config', '--file', rc, '--add',
'channels', 'test')
assert stdout == stderr == ''
stdout, stderr = run_conda_command('config', '--file', rc, '--add',
'channels', 'test')
assert stdout == ''
assert stderr == "Warning: 'test' already in 'channels' list, moving to the bottom"
assert _read_test_condarc(rc) == """\
channels:
- defaults
- test
"""
# Test append
with make_temp_condarc() as rc:
stdout, stderr = run_conda_command('config', '--file', rc, '--add',
'channels', 'test')
assert stdout == stderr == ''
stdout, stderr = run_conda_command('config', '--file', rc, '--append',
'channels', 'test')
assert stdout == ''
assert stderr == "Warning: 'test' already in 'channels' list, moving to the bottom"
assert _read_test_condarc(rc) == """\
channels:
- defaults
- test
"""
# Test duoble remove of defaults
with make_temp_condarc() as rc:
stdout, stderr = run_conda_command('config', '--file', rc, '--remove',
'channels', 'defaults')
assert stdout == stderr == ''
stdout, stderr = run_conda_command('config', '--file', rc, '--remove',
'channels', 'defaults')
assert stdout == ''
assert stderr == "CondaKeyError: Error with key 'channels': 'defaults' is not in the 'channels'\
key of the config file"
# Test creating a new file with --set
with make_temp_condarc() as rc:
stdout, stderr = run_conda_command('config', '--file', rc,
'--set', 'always_yes', 'true')
assert stdout == stderr == ''
assert _read_test_condarc(rc) == """\
always_yes: true
"""
# FIXME Break into multiple tests
@pytest.mark.slow
def test_config_command_get():
# Test --get
condarc = """\
channels:
- test
- defaults
create_default_packages:
- ipython
- numpy
changeps1: false
always_yes: true
invalid_key: true
channel_alias: http://alpha.conda.anaconda.org
"""
with make_temp_condarc(condarc) as rc:
stdout, stderr = run_conda_command('config', '--file', rc, '--get')
assert stdout == """\
--set always_yes True
--set changeps1 False
--set channel_alias http://alpha.conda.anaconda.org
--add channels 'test' # highest priority
--add channels 'defaults' # lowest priority
--add create_default_packages 'ipython'
--add create_default_packages 'numpy'\
"""
assert stderr == "unknown key invalid_key"
stdout, stderr = run_conda_command('config', '--file', rc,
'--get', 'channels')
assert stdout == """\
--add channels 'test' # highest priority
--add channels 'defaults' # lowest priority\
"""
assert stderr == ""
stdout, stderr = run_conda_command('config', '--file', rc,
'--get', 'changeps1')
assert stdout == """\
--set changeps1 False\
"""
assert stderr == ""
stdout, stderr = run_conda_command('config', '--file', rc,
'--get', 'changeps1', 'channels')
assert stdout == """\
--set changeps1 False
--add channels 'test' # highest priority
--add channels 'defaults' # lowest priority\
"""
assert stderr == ""
stdout, stderr = run_conda_command('config', '--file', rc,
'--get', 'allow_softlinks')
assert stdout == ""
assert stderr == ""
stdout, stderr = run_conda_command('config', '--file', rc,
'--get', 'track_features')
assert stdout == ""
assert stderr == ""
stdout, stderr = run_conda_command('config', '--file', rc, '--get', 'invalid_key')
assert stdout == ""
assert "invalid choice: 'invalid_key'" in stderr
stdout, stderr = run_conda_command('config', '--file', rc,
'--get', 'not_valid_key')
assert stdout == ""
assert "invalid choice: 'not_valid_key'" in stderr
# FIXME Break into multiple tests
@pytest.mark.slow
def test_config_command_parser():
# Now test the YAML "parser"
# Channels is normal content.
# create_default_packages has extra spaces in list items
condarc = """\
channels:
- test
- defaults
create_default_packages :
- ipython
- numpy
changeps1: false
# Here is a comment
always_yes: true
"""
# First verify that this itself is valid YAML
assert yaml_load(condarc) == {'channels': ['test', 'defaults'],
'create_default_packages': ['ipython', 'numpy'], 'changeps1':
False, 'always_yes': True}
with make_temp_condarc(condarc) as rc:
stdout, stderr = run_conda_command('config', '--file', rc, '--get')
print(stdout)
assert stdout == """\
--set always_yes True
--set changeps1 False
--add channels 'test' # highest priority
--add channels 'defaults' # lowest priority
--add create_default_packages 'ipython'
--add create_default_packages 'numpy'\
"""
with open(rc, 'r') as fh:
print(fh.read())
stdout, stderr = run_conda_command('config', '--file', rc, '--prepend', 'channels', 'mychannel')
assert stdout == stderr == ''
with open(rc, 'r') as fh:
print(fh.read())
assert _read_test_condarc(rc) == """\
channels:
- mychannel
- test
- defaults
create_default_packages:
- ipython
- numpy
changeps1: false
# Here is a comment
always_yes: true
"""
stdout, stderr = run_conda_command('config', '--file', rc,
'--set', 'changeps1', 'true')
assert stdout == stderr == ''
assert _read_test_condarc(rc) == """\
channels:
- mychannel
- test
- defaults
create_default_packages:
- ipython
- numpy
changeps1: true
# Here is a comment
always_yes: true
"""
# Test adding a new list key. We couldn't test this above because it
# doesn't work yet with odd whitespace
condarc = """\
channels:
- test
- defaults
always_yes: true
"""
with make_temp_condarc(condarc) as rc:
stdout, stderr = run_conda_command('config', '--file', rc, '--add',
'disallow', 'perl')
assert stdout == stderr == ''
assert _read_test_condarc(rc) == condarc + """\
disallow:
- perl
"""
# FIXME Break into multiple tests
@pytest.mark.slow
def test_config_command_remove_force():
# Finally, test --remove, --remove-key
with make_temp_condarc() as rc:
run_conda_command('config', '--file', rc, '--add',
'channels', 'test')
run_conda_command('config', '--file', rc, '--set',
'always_yes', 'true')
stdout, stderr = run_conda_command('config', '--file', rc,
'--remove', 'channels', 'test')
assert stdout == stderr == ''
assert yaml_load(_read_test_condarc(rc)) == {'channels': ['defaults'],
'always_yes': True}
stdout, stderr = run_conda_command('config', '--file', rc,
'--remove', 'channels', 'test', '--force')
assert stdout == ''
assert stderr == """\
CondaKeyError: Error with key 'channels': 'test' is not in the 'channels' key of the config file"""
stdout, stderr = run_conda_command('config', '--file', rc,
'--remove', 'disallow', 'python', '--force')
assert stdout == ''
assert stderr == """\
CondaKeyError: Error with key 'disallow': key 'disallow' is not in the config file"""
stdout, stderr = run_conda_command('config', '--file', rc,
'--remove-key', 'always_yes', '--force')
assert stdout == stderr == ''
assert yaml_load(_read_test_condarc(rc)) == {'channels': ['defaults']}
stdout, stderr = run_conda_command('config', '--file', rc,
'--remove-key', 'always_yes', '--force')
assert stdout == ''
assert stderr == """\
CondaKeyError: Error with key 'always_yes': key 'always_yes' is not in the config file"""
# FIXME Break into multiple tests
@pytest.mark.slow
def test_config_command_bad_args():
with make_temp_condarc() as rc:
stdout, stderr = run_conda_command('config', '--file', rc, '--add',
'notarealkey', 'test')
assert stdout == ''
stdout, stderr = run_conda_command('config', '--file', rc, '--set',
'notarealkey', 'true')
assert stdout == ''
# def test_invalid_rc():
# # Some tests for unexpected input in the condarc, like keys that are the
# # wrong type
# condarc = """\
# channels:
# """
#
# with make_temp_condarc(condarc) as rc:
# stdout, stderr = run_conda_command('config', '--file', rc,
# '--add', 'channels', 'test')
# assert stdout == ''
# assert stderr == """\
# CondaError: Parse error: key 'channels' should be a list, not NoneType."""
# assert _read_test_condarc(rc) == condarc
def test_config_set():
# Test the config set command
# Make sure it accepts only boolean values for boolean keys and any value for string keys
with make_temp_condarc() as rc:
stdout, stderr = run_conda_command('config', '--file', rc,
'--set', 'always_yes', 'yes')
assert stdout == ''
assert stderr == ''
stdout, stderr = run_conda_command('config', '--file', rc,
'--set', 'always_yes', 'no')
assert stdout == ''
assert stderr == ''
def test_set_rc_string():
# Test setting string keys in .condarc
# We specifically test ssl_verify since it can be either a boolean or a string
with make_temp_condarc() as rc:
assert context.ssl_verify is True
stdout, stderr = run_conda_command('config', '--file', rc,
'--set', 'ssl_verify', 'no')
assert stdout == ''
assert stderr == ''
reset_context([rc])
assert context.ssl_verify is False
stdout, stderr = run_conda_command('config', '--file', rc,
'--set', 'ssl_verify', 'test_string.crt')
assert stdout == ''
assert stderr == ''
reset_context([rc])
assert context.ssl_verify == 'test_string.crt'