|
14 | 14 | StdOutCapture,
|
15 | 15 | WitlessRunner,
|
16 | 16 | )
|
| 17 | +from datalad.support.exceptions import IncompleteResultsError |
17 | 18 | from datalad.support.network import get_local_file_url
|
18 | 19 | from datalad.tests.utils_pytest import (
|
19 | 20 | assert_false,
|
20 | 21 | assert_in,
|
21 | 22 | assert_not_in_results,
|
22 | 23 | assert_raises,
|
| 24 | + assert_repo_status, |
23 | 25 | assert_result_count,
|
24 | 26 | ok_,
|
25 | 27 | ok_clean_git,
|
|
34 | 36 | on_windows,
|
35 | 37 | )
|
36 | 38 |
|
| 39 | +import pytest |
37 | 40 | from datalad_container.tests.utils import add_pyscript_image
|
38 | 41 |
|
39 | 42 | testimg_url = 'shub://datalad/datalad-container:testhelper'
|
@@ -154,6 +157,40 @@ def assert_no_change(res, path):
|
154 | 157 | assert_no_change(res, super_ds.path)
|
155 | 158 |
|
156 | 159 |
|
| 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 | + |
157 | 194 | @with_tempfile
|
158 | 195 | @with_tree(tree={'some_container.img': "doesn't matter"})
|
159 | 196 | def test_custom_call_fmt(path=None, local_file=None):
|
|
0 commit comments