-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
test_conda.py
92 lines (66 loc) · 2.3 KB
/
test_conda.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
# -*- coding: utf-8 -*-
#
# Copyright © Spyder Project Contributors
# Licensed under the terms of the MIT License
#
"""Tests for conda.py"""
# Standard library imports
import os
import sys
import time
# Third party imports
import pytest
# Local imports
from spyder.utils.conda import (
add_quotes, find_conda, get_conda_activation_script, get_conda_env_path,
get_conda_root_prefix, get_list_conda_envs, get_list_conda_envs_cache
)
if os.name == 'nt':
TEST_PYEXEC = 'c:/miniconda/envs/foobar/python.exe'
else:
TEST_PYEXEC = '/miniconda/envs/foobar/bin/python'
def test_add_quotes():
output = add_quotes('/some path/with spaces')
assert output == '"/some path/with spaces"'
output = add_quotes('/some-path/with-no-spaces')
assert output == '/some-path/with-no-spaces'
def test_get_conda_activation_script():
output = get_conda_activation_script(TEST_PYEXEC)
if os.name == 'nt':
assert output == 'c:/miniconda/Scripts/activate'
else:
assert output == '/miniconda/bin/activate'
def test_get_conda_env_path():
output = get_conda_env_path(TEST_PYEXEC)
if os.name == 'nt':
assert output == 'c:/miniconda/envs/foobar'
else:
assert output == '/miniconda/envs/foobar'
def test_get_conda_root_prefix():
output = get_conda_root_prefix(TEST_PYEXEC)
if os.name == 'nt':
assert output == 'c:/miniconda'
else:
assert output == '/miniconda'
assert 'envs' not in get_conda_root_prefix(sys.executable)
@pytest.mark.skipif(not bool(os.environ.get('CI')),
reason="Only meant for CIs")
def test_find_conda():
assert find_conda()
@pytest.mark.skipif(not bool(os.environ.get('CI')),
reason="Only meant for CIs")
def test_get_list_conda_envs():
output = get_list_conda_envs()
expected_envs = ['base', 'test', 'jedi-test-env', 'spytest-ž']
expected_envs = ['conda: ' + env for env in expected_envs]
assert set(expected_envs) == set(output.keys())
@pytest.mark.skipif(not bool(os.environ.get('CI')),
reason="Only meant for CIs")
def test_get_list_conda_envs_cache():
time0 = time.time()
output = get_list_conda_envs_cache()
time1 = time.time()
assert output != {}
assert (time1 - time0) < 0.01
if __name__ == "__main__":
pytest.main()