Skip to content

Commit aa7bbf4

Browse files
committed
test(copy): improve _exclude_from tests
Refactors the _exclude_from tests to use assertEqual() with full expected recipe strings instead of multiple substring checks. This aligns the test style with other HPCCM copy primitive tests. Note: When `_exclude_from` is used, an empty %files section is still emitted after the rsync-based %setup block. This is intentional to preserve compatibility with the existing copy control flow. The extra section is harmless and may be removed in a future cleanup.
1 parent 26231b7 commit aa7bbf4

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

test/test_copy.py

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -260,33 +260,27 @@ def test_from_temp_staging(self):
260260
def test_exclude_from_single_singularity(self):
261261
"""rsync-based copy with _exclude_from (single source)"""
262262
c = copy(src='.', dest='/opt/app', _exclude_from='.apptainerignore')
263-
recipe = str(c)
264-
self.assertIn('%setup', recipe)
265-
self.assertIn('rsync -av', recipe)
266-
self.assertIn('--exclude-from=.apptainerignore', recipe)
267-
# Allow trailing %files section but ensure rsync setup comes first
268-
self.assertTrue(recipe.strip().startswith('%setup'),
269-
"Expected rsync setup section to appear first")
263+
self.assertEqual(str(c),
264+
r'''%setup
265+
mkdir -p ${SINGULARITY_ROOTFS}/opt/app
266+
rsync -av --exclude-from=.apptainerignore ./ ${SINGULARITY_ROOTFS}/opt/app/
267+
%files
268+
''')
270269

271270
@singularity
272271
def test_exclude_from_multiple_singularity(self):
273272
"""rsync-based copy with multiple _exclude_from files"""
274273
c = copy(src='data', dest='/opt/data',
275274
_exclude_from=['.ignore1', '.ignore2'])
276-
recipe = str(c)
277-
self.assertIn('%setup', recipe)
278-
self.assertIn('rsync -av', recipe)
279-
self.assertIn('--exclude-from=.ignore1', recipe)
280-
self.assertIn('--exclude-from=.ignore2', recipe)
281-
# Ensure setup section appears before %files
282-
self.assertTrue(recipe.strip().startswith('%setup'),
283-
"Expected rsync setup section to appear first")
275+
self.assertEqual(str(c),
276+
r'''%setup
277+
mkdir -p ${SINGULARITY_ROOTFS}/opt/data
278+
rsync -av --exclude-from=.ignore1 --exclude-from=.ignore2 data/ ${SINGULARITY_ROOTFS}/opt/data/
279+
%files
280+
''')
284281

285282
@docker
286283
def test_exclude_from_docker_ignored(self):
287284
"""_exclude_from ignored in Docker context"""
288285
c = copy(src='.', dest='/opt/app', _exclude_from='.apptainerignore')
289-
recipe = str(c)
290-
self.assertIn('COPY', recipe)
291-
self.assertNotIn('rsync', recipe)
292-
self.assertNotIn('%setup', recipe)
286+
self.assertEqual(str(c), 'COPY . /opt/app')

0 commit comments

Comments
 (0)