Skip to content

Commit 250e64c

Browse files
authored
Merge pull request #209 from yarikoptic/bf-run-stop-on-error
BF: by default stop containers-run on error, to not proceed to save
2 parents 1f74e02 + 0609cd3 commit 250e64c

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

changelog.d/pr-209.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### 🐛 Bug Fixes
2+
3+
- BF: by default stop containers-run on error, to not proceed to save. [PR #209](https://github.com/datalad/datalad-container/pull/209) (by [@yarikoptic](https://github.com/yarikoptic))

datalad_container/containers_run.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ class ContainersRun(Interface):
6666

6767
_params_ = _run_params
6868

69+
# Analogous to 'run' command - stop on first error
70+
on_failure = 'stop'
71+
6972
@staticmethod
7073
@datasetmethod(name='containers_run')
7174
@eval_results

datalad_container/tests/test_run.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
StdOutCapture,
1515
WitlessRunner,
1616
)
17+
from datalad.support.exceptions import IncompleteResultsError
1718
from datalad.support.network import get_local_file_url
1819
from datalad.tests.utils_pytest import (
1920
assert_false,
2021
assert_in,
2122
assert_not_in_results,
2223
assert_raises,
24+
assert_repo_status,
2325
assert_result_count,
2426
ok_,
2527
ok_clean_git,
@@ -34,6 +36,7 @@
3436
on_windows,
3537
)
3638

39+
import pytest
3740
from datalad_container.tests.utils import add_pyscript_image
3841

3942
testimg_url = 'shub://datalad/datalad-container:testhelper'
@@ -154,6 +157,40 @@ def assert_no_change(res, path):
154157
assert_no_change(res, super_ds.path)
155158

156159

160+
@with_tempfile
161+
@with_tree(tree={'some_container.img': "doesn't matter"})
162+
def test_non0_exit(path=None, local_file=None):
163+
ds = Dataset(path).create()
164+
165+
# plug in a proper singularity image
166+
ds.containers_add(
167+
'mycontainer',
168+
url=get_local_file_url(op.join(local_file, 'some_container.img')),
169+
image='righthere',
170+
call_fmt="sh -c '{cmd}'"
171+
)
172+
ds.save() # record the effect in super-dataset
173+
ok_clean_git(path)
174+
175+
# now we can run stuff in the container
176+
# and because there is just one, we don't even have to name the container
177+
ds.containers_run(['touch okfile'])
178+
assert_repo_status(path)
179+
180+
# Test that regular 'run' behaves as expected -- it does not proceed to save upon error
181+
with pytest.raises(IncompleteResultsError):
182+
ds.run(['sh', '-c', 'touch nokfile && exit 1'])
183+
assert_repo_status(path, untracked=['nokfile'])
184+
(ds.pathobj / "nokfile").unlink() # remove for the next test
185+
assert_repo_status(path)
186+
187+
# Now test with containers-run which should behave similarly -- not save in case of error
188+
with pytest.raises(IncompleteResultsError):
189+
ds.containers_run(['touch nokfile && exit 1'])
190+
# check - must have created the file but not saved anything since failed to run!
191+
assert_repo_status(path, untracked=['nokfile'])
192+
193+
157194
@with_tempfile
158195
@with_tree(tree={'some_container.img': "doesn't matter"})
159196
def test_custom_call_fmt(path=None, local_file=None):

0 commit comments

Comments
 (0)