-
Notifications
You must be signed in to change notification settings - Fork 87
/
test_copy.py
244 lines (203 loc) · 7.9 KB
/
test_copy.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
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# pylint: disable=invalid-name, too-few-public-methods
"""Test cases for the copy module"""
from __future__ import unicode_literals
from __future__ import print_function
import logging # pylint: disable=unused-import
import unittest
from helpers import bash, docker, invalid_ctype, singularity, singularity26, singularity32
from hpccm.primitives.copy import copy
class Test_copy(unittest.TestCase):
def setUp(self):
"""Disable logging output messages"""
logging.disable(logging.ERROR)
@docker
def test_empty(self):
"""No source or destination specified"""
c = copy()
self.assertEqual(str(c), '')
@invalid_ctype
def test_invalid_ctype(self):
"""Invalid container type specified"""
c = copy(src='a', dest='b')
with self.assertRaises(RuntimeError):
str(c)
@docker
def test_single_docker(self):
"""Single source file specified"""
c = copy(src='a', dest='b')
self.assertEqual(str(c), 'COPY a b')
@singularity
def test_single_singularity(self):
"""Single source file specified"""
c = copy(src='a', dest='b')
self.assertEqual(str(c), '%files\n a b')
@bash
def test_single_bash(self):
"""Single source file specified"""
c = copy(src='a', dest='b')
self.assertEqual(str(c), '')
@docker
def test_multiple_docker(self):
"""Multiple source files specified"""
c = copy(src=['a1', 'a2', 'a3'], dest='b')
self.assertEqual(str(c), 'COPY a1 \\\n a2 \\\n a3 \\\n b/')
@singularity
def test_multiple_singularity(self):
"""Multiple source files specified"""
c = copy(src=['a1', 'a2', 'a3'], dest='b')
self.assertEqual(str(c), '%files\n a1 b\n a2 b\n a3 b')
@docker
def test_files_docker(self):
"""Pairs of files specified"""
c = copy(files={'a1': 'b1', 'a2': 'b2', 'a3': 'b3'})
self.assertEqual(str(c), 'COPY a1 b1\nCOPY a2 b2\nCOPY a3 b3')
@singularity
def test_files_singularity(self):
"""Pairs of files specified"""
c = copy(files={'a1': 'b1', 'a2': 'b2', 'a3': 'b3'})
self.assertEqual(str(c), '%files\n a1 b1\n a2 b2\n a3 b3')
@docker
def test_from_docker(self):
"""Docker --from syntax"""
c = copy(src='a', dest='b', _from='dev')
self.assertEqual(str(c), 'COPY --from=dev a b')
@singularity26
def test_from_singularity26(self):
"""Singularity from syntax"""
c = copy(src='a', dest='b', _from='dev')
self.assertEqual(str(c), '%files\n a b')
@singularity32
def test_from_singularity32(self):
"""Singularity from syntax"""
c = copy(src='a', dest='b', _from='dev')
self.assertEqual(str(c), '%files from dev\n a b')
@singularity
def test_appfiles_multiple_singularity(self):
"""Multiple app-specific source files specified"""
c = copy(src=['a1', 'a2', 'a3'], dest='b', _app='foo')
self.assertEqual(str(c),
'%appfiles foo\n a1 b\n a2 b\n a3 b')
@singularity
def test_appfiles_files_singularity(self):
"""Pairs of app-specific files specified"""
c = copy(files={'a1': 'b1', 'a2': 'b2', 'a3': 'b3'}, _app='foo')
self.assertEqual(str(c),
'%appfiles foo\n a1 b1\n a2 b2\n a3 b3')
@docker
def test_appfiles_docker(self):
"""app-parameter is ignored in Docker"""
c = copy(src=['a1', 'a2', 'a3'], dest='b', _app='foo')
self.assertEqual(str(c), 'COPY a1 \\\n a2 \\\n a3 \\\n b/')
@singularity
def test_post_file_singularity(self):
"""Move file during post"""
c = copy(src='a', dest='/opt/a', _post=True)
self.assertEqual(str(c),
'%files\n a /\n%post\n mv /a /opt/a')
c = copy(src='a', dest='/opt/', _post=True)
self.assertEqual(str(c),
'%files\n a /\n%post\n mv /a /opt/')
@singularity
def test_post_multiple_singularity(self):
"""move file during post"""
c = copy(src=['a', 'b'], dest='/opt', _post=True)
self.assertEqual(str(c),
'%files\n a /\n b /\n%post\n mv /a /opt/a\n mv /b /opt/b')
@singularity
def test_mkdir_file_singularity(self):
"""mkdir folder with setup, single file"""
c = copy(src='a', dest='/opt/foo/a', _mkdir=True)
self.assertEqual(str(c),
'%setup\n mkdir -p ${SINGULARITY_ROOTFS}/opt/foo\n%files\n a /opt/foo/a')
@singularity
def test_mkdir_files_singularity(self):
"""mkdir folder with setup, multiple files"""
c = copy(src=['a', 'b'], dest='/opt/foo', _mkdir=True)
self.assertEqual(str(c),
'%setup\n mkdir -p ${SINGULARITY_ROOTFS}/opt/foo\n%files\n a /opt/foo\n b /opt/foo')
@docker
def test_merge_file_docker(self):
"""merge primitives"""
c = []
c.append(copy(src='a', dest='A'))
c.append(copy(src='b', dest='B'))
merged = c[0].merge(c)
self.assertEqual(str(merged), 'COPY a A\nCOPY b B')
@singularity
def test_merge_file_singularity(self):
"""merge primitives"""
c = []
c.append(copy(src='a', dest='A'))
c.append(copy(src='b', dest='B'))
merged = c[0].merge(c)
self.assertEqual(str(merged), '%files\n a A\n b B')
@docker
def test_merge_multiple_docker(self):
"""merge primitives"""
c = []
c.append(copy(src=['a1', 'a2'], dest='A'))
c.append(copy(src='b', dest='B'))
merged = c[0].merge(c)
self.assertEqual(str(merged), 'COPY a1 A\nCOPY a2 A\nCOPY b B')
@singularity
def test_merge_multiple_singularity(self):
"""merge primitives"""
c = []
c.append(copy(src=['a1', 'a2'], dest='A'))
c.append(copy(src='b', dest='B'))
merged = c[0].merge(c)
self.assertEqual(str(merged), '%files\n a1 A\n a2 A\n b B')
@docker
def test_merge_mixed_docker(self):
"""merge primitives"""
c = []
c.append(copy(src='foo', dest='bar'))
c.append(copy(src=['1', '2', '3'], dest='/infinity'))
c.append(copy(files={'a': '/A', 'b': '/B'}))
merged = c[0].merge(c)
self.assertEqual(str(merged),
r'''COPY 1 /infinity
COPY 2 /infinity
COPY 3 /infinity
COPY a /A
COPY b /B
COPY foo bar''')
@singularity
def test_merge_mixed_singularity(self):
"""merge primitives"""
c = []
c.append(copy(src='foo', dest='bar'))
c.append(copy(src=['1', '2', '3'], dest='/infinity'))
c.append(copy(files={'a': '/A', 'b': '/B'}))
merged = c[0].merge(c)
self.assertEqual(str(merged),
r'''%files
1 /infinity
2 /infinity
3 /infinity
a /A
b /B
foo bar''')
@docker
def test_chown_docker(self):
"""Docker --chown syntax"""
c = copy(_chown='alice:alice', src='foo', dest='bar')
self.assertEqual(str(c), 'COPY --chown=alice:alice foo bar')
@singularity
def test_chown_singularity(self):
"""Docker --chown syntax"""
c = copy(_chown='alice:alice', src='foo', dest='bar')
self.assertEqual(str(c), '%files\n foo bar')