11 import arvados.collection
14 from cwltool.pathmapper import MapperEnt
15 from .mock_discovery import get_rootDesc
17 from arvados_cwl.pathmapper import ArvPathMapper
19 def upload_mock(files, api, dry_run=False, num_retries=0, project=None, fnPattern="$(file %s/%s)", name=None):
20 pdh = "99999999999999999999999999999991+99"
22 c.keepref = "%s/%s" % (pdh, os.path.basename(c.fn))
23 c.fn = fnPattern % (pdh, os.path.basename(c.fn))
25 class TestPathmap(unittest.TestCase):
27 self.api = mock.MagicMock()
28 self.api._rootDesc = get_rootDesc()
30 def test_keepref(self):
31 """Test direct keep references."""
33 arvrunner = arvados_cwl.ArvCwlRunner(self.api)
35 p = ArvPathMapper(arvrunner, [{
37 "location": "keep:99999999999999999999999999999991+99/hw.py"
38 }], "", "/test/%s", "/test/%s/%s")
40 self.assertEqual({'keep:99999999999999999999999999999991+99/hw.py': MapperEnt(resolved='keep:99999999999999999999999999999991+99/hw.py', target='/test/99999999999999999999999999999991+99/hw.py', type='File', staged=True)},
43 @mock.patch("arvados.commands.run.uploadfiles")
44 def test_upload(self, upl):
45 """Test pathmapper uploading files."""
47 arvrunner = arvados_cwl.ArvCwlRunner(self.api)
49 upl.side_effect = upload_mock
51 p = ArvPathMapper(arvrunner, [{
53 "location": "tests/hw.py"
54 }], "", "/test/%s", "/test/%s/%s")
56 self.assertEqual({'tests/hw.py': MapperEnt(resolved='keep:99999999999999999999999999999991+99/hw.py', target='/test/99999999999999999999999999999991+99/hw.py', type='File', staged=True)},
59 @mock.patch("arvados.commands.run.uploadfiles")
60 def test_prev_uploaded(self, upl):
61 """Test pathmapper handling previously uploaded files."""
63 arvrunner = arvados_cwl.ArvCwlRunner(self.api)
64 arvrunner.add_uploaded('tests/hw.py', MapperEnt(resolved='keep:99999999999999999999999999999991+99/hw.py', target='', type='File', staged=True))
66 upl.side_effect = upload_mock
68 p = ArvPathMapper(arvrunner, [{
70 "location": "tests/hw.py"
71 }], "", "/test/%s", "/test/%s/%s")
73 self.assertEqual({'tests/hw.py': MapperEnt(resolved='keep:99999999999999999999999999999991+99/hw.py', target='/test/99999999999999999999999999999991+99/hw.py', type='File', staged=True)},
76 @mock.patch("arvados.commands.run.uploadfiles")
77 @mock.patch("arvados.commands.run.statfile")
78 def test_statfile(self, statfile, upl):
79 """Test pathmapper handling ArvFile references."""
80 arvrunner = arvados_cwl.ArvCwlRunner(self.api)
82 # An ArvFile object returned from arvados.commands.run.statfile means the file is located on a
83 # keep mount, so we can construct a direct reference directly without upload.
84 def statfile_mock(prefix, fn, fnPattern="$(file %s/%s)", dirPattern="$(dir %s/%s/)"):
85 st = arvados.commands.run.ArvFile("", fnPattern % ("99999999999999999999999999999991+99", "hw.py"))
88 upl.side_effect = upload_mock
89 statfile.side_effect = statfile_mock
91 p = ArvPathMapper(arvrunner, [{
93 "location": "tests/hw.py"
94 }], "", "/test/%s", "/test/%s/%s")
96 self.assertEqual({'tests/hw.py': MapperEnt(resolved='keep:99999999999999999999999999999991+99/hw.py', target='/test/99999999999999999999999999999991+99/hw.py', type='File', staged=True)},