X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/1d77dec0f7bc1cca34d52288bd39ecd0a79be250..0eb72b526bf8bbb011551ecf019f604e17a534f1:/sdk/cwl/tests/test_pathmapper.py diff --git a/sdk/cwl/tests/test_pathmapper.py b/sdk/cwl/tests/test_pathmapper.py index 3e7918a24a..9649b83872 100644 --- a/sdk/cwl/tests/test_pathmapper.py +++ b/sdk/cwl/tests/test_pathmapper.py @@ -1,3 +1,7 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: Apache-2.0 + import functools import mock import sys @@ -47,7 +51,7 @@ class TestPathmap(unittest.TestCase): arvrunner = arvados_cwl.ArvCwlRunner(self.api) - def statfile_mock(prefix, fn, fnPattern="$(file %s/%s)", dirPattern="$(dir %s/%s/)"): + def statfile_mock(prefix, fn, fnPattern="$(file %s/%s)", dirPattern="$(dir %s/%s/)", raiseOSError=False): st = arvados.commands.run.UploadFile("", "tests/hw.py") return st @@ -87,7 +91,7 @@ class TestPathmap(unittest.TestCase): # An ArvFile object returned from arvados.commands.run.statfile means the file is located on a # keep mount, so we can construct a direct reference directly without upload. - def statfile_mock(prefix, fn, fnPattern="$(file %s/%s)", dirPattern="$(dir %s/%s/)"): + def statfile_mock(prefix, fn, fnPattern="$(file %s/%s)", dirPattern="$(dir %s/%s/)", raiseOSError=False): st = arvados.commands.run.ArvFile("", fnPattern % ("99999999999999999999999999999991+99", "hw.py")) return st @@ -101,3 +105,16 @@ class TestPathmap(unittest.TestCase): self.assertEqual({'file:tests/hw.py': MapperEnt(resolved='keep:99999999999999999999999999999991+99/hw.py', target='/test/99999999999999999999999999999991+99/hw.py', type='File', staged=True)}, p._pathmap) + + @mock.patch("os.stat") + def test_missing_file(self, stat): + """Test pathmapper handling missing references.""" + arvrunner = arvados_cwl.ArvCwlRunner(self.api) + + stat.side_effect = OSError(2, "No such file or directory") + + with self.assertRaises(OSError): + p = ArvPathMapper(arvrunner, [{ + "class": "File", + "location": "file:tests/hw.py" + }], "", "/test/%s", "/test/%s/%s")