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
|
import os
import pytest
from delivery_merge import conda, merge
from ruamel.yaml import YAML
CHANNELS = ['http://ssb.stsci.edu/astroconda',
'defaults',
'http://ssb.stsci.edu/astroconda-dev']
BASE_SPEC = """# This file may be used to create an environment using:
# $ conda create --name <env> --file <this file>
# platform: linux-64
@EXPLICIT
https://repo.anaconda.com/pkgs/main/linux-64/ca-certificates-2019.1.23-0.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/libgcc-ng-8.2.0-hdf63c60_1.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/libstdcxx-ng-8.2.0-hdf63c60_1.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/libffi-3.2.1-hd88cf55_4.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/ncurses-6.1-he6710b0_1.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/openssl-1.1.1b-h7b6447c_1.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/xz-5.2.4-h14c3975_4.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/zlib-1.2.11-h7b6447c_3.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/libedit-3.1.20181209-hc058e9b_0.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/readline-7.0-h7b6447c_5.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/tk-8.6.8-hbc83047_0.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/sqlite-3.28.0-h7b6447c_0.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/python-3.7.3-h0371630_0.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/certifi-2019.3.9-py37_0.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/setuptools-41.0.1-py37_0.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/wheel-0.33.1-py37_0.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/pip-19.1-py37_0.tar.bz2
"""
BASE_YML = """name: simple_env
channels:
- this
- order
- i
- want
dependencies:
- some_package=1.2.3
"""
CHANNELS_YML = ['i', 'want', 'this', 'order']
COMMENTS_DELIM = [';', '#']
COMMENTS = """; comment
; comment ; comment
;comment;comment
;comment#comment
data ; comment
data ; comment
data; comment
data;comment
# comment
# comment # comment
#comment#comment
#comment;comment
data # comment
data # comment
data# comment
data#comment
"""
DMFILE = """
; Example
python # dmfile
setuptools
relic # tiny package providing its own test suite
"""
DMFILE_INVALID = f"""
{DMFILE}
invalid package specification
"""
class TestMerge:
def setup_class(self):
self.env_name = 'delivery_env'
self.input_file_base_spec = 'base_spec.txt'
self.version = '4.5.12'
self.input_file = 'sample.dm'
self.input_file_invalid = 'sample_invalid.dm'
self.input_file_empty = 'sample_empty.dm'
self.yaml = YAML()
open(self.input_file, 'w+').write(DMFILE)
open(self.input_file_invalid, 'w+').write(DMFILE_INVALID)
open(self.input_file_empty, 'w+').write("")
open(self.input_file_base_spec, 'w+').write(BASE_SPEC)
self.prefix = conda.conda_installer(self.version)
conda.conda_init_path(self.prefix)
conda.conda('create', '-q', '-y',
'-n', self.env_name,
'--file', self.input_file_base_spec)
def teardown_class(self):
pass
@pytest.mark.parametrize('comments', [x for x in COMMENTS.splitlines()])
def test_comment_find(self, comments):
index = merge.comment_find(comments)
assert comments[index] in COMMENTS_DELIM
def test_dmfile(self):
data = merge.dmfile(self.input_file)
assert COMMENTS_DELIM not in [x['fullspec'] for x in data]
assert all([x['name'] for x in data])
def test_dmfile_raises_InvalidPackageSpec(self):
with pytest.raises(merge.InvalidPackageSpec):
merge.dmfile(self.input_file_invalid)
def test_dmfile_raises_EmptyPackageSpec(self):
with pytest.raises(merge.EmptyPackageSpec):
merge.dmfile(self.input_file_empty)
def test_env_combine(self):
merge.env_combine(self.input_file, self.env_name, CHANNELS)
input_data = merge.dmfile(self.input_file)
output_data = conda.conda(f'list -n {self.env_name}')
output_data.check_returncode()
installed = [x.split()[0]
for x in output_data.stdout.decode().splitlines()
if not x.startswith('#')]
requested = [x['name'] for x in input_data]
for req in requested:
assert req in installed
def test_testable_packages(self):
merge.env_combine(self.input_file, self.env_name, CHANNELS)
result = list(merge.testable_packages(self.input_file, self.prefix))
assert result
for data in result:
assert isinstance(data, dict)
assert [isinstance(x, str) for x in data.values()]
def test_integration_test(self):
merge.env_combine(self.input_file, self.env_name, CHANNELS)
input_data = list(merge.testable_packages(self.input_file,
self.prefix))
assert input_data
output_dir = 'test_results'
for pkg in input_data:
result = merge.integration_test(pkg, self.env_name, output_dir)
assert os.path.exists(result)
contents = open(result).read()
assert contents.startswith('<?xml') and contents.endswith('</testsuite>')
def test_force_xunit2_no_config(self):
merge.force_xunit2()
assert os.path.exists('pytest.ini')
assert 'junit_family = xunit2' in open('pytest.ini').read()
os.remove('pytest.ini')
def test_force_xunit2_no_setup(self):
open('pytest.ini', 'w+').write('')
merge.force_xunit2()
assert not os.path.exists('setup.cfg')
assert os.path.exists('pytest.ini')
assert 'junit_family = xunit2' in open('pytest.ini').read()
os.remove('pytest.ini')
def test_force_xunit2_no_pytest(self):
open('setup.cfg', 'w+').write('')
merge.force_xunit2()
assert not os.path.exists('pytest.ini')
assert os.path.exists('setup.cfg')
assert 'junit_family = xunit2' in open('setup.cfg').read()
os.remove('setup.cfg')
def test_force_yaml_channels(self):
filename = 'channels.yml'
open(filename, 'w+').write(BASE_YML)
assert self.yaml.load(open(filename))['channels']
merge.force_yaml_channels('channels.yml', CHANNELS_YML)
assert self.yaml.load(open(filename))['channels'] == CHANNELS_YML
|