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 @mock.patch("arvados.commands.run.statfile")
45 def test_upload(self, statfile, upl):
46 """Test pathmapper uploading files."""
48 arvrunner = arvados_cwl.ArvCwlRunner(self.api)
50 def statfile_mock(prefix, fn, fnPattern="$(file %s/%s)", dirPattern="$(dir %s/%s/)"):
51 st = arvados.commands.run.UploadFile("", "tests/hw.py")
54 upl.side_effect = upload_mock
55 statfile.side_effect = statfile_mock
57 p = ArvPathMapper(arvrunner, [{
59 "location": "file:tests/hw.py"
60 }], "", "/test/%s", "/test/%s/%s")
62 self.assertEqual({'file:tests/hw.py': MapperEnt(resolved='keep:99999999999999999999999999999991+99/hw.py', target='/test/99999999999999999999999999999991+99/hw.py', type='File', staged=True)},
65 @mock.patch("arvados.commands.run.uploadfiles")
66 def test_prev_uploaded(self, upl):
67 """Test pathmapper handling previously uploaded files."""
69 arvrunner = arvados_cwl.ArvCwlRunner(self.api)
70 arvrunner.add_uploaded('file:tests/hw.py', MapperEnt(resolved='keep:99999999999999999999999999999991+99/hw.py', target='', type='File', staged=True))
72 upl.side_effect = upload_mock
74 p = ArvPathMapper(arvrunner, [{
76 "location": "file:tests/hw.py"
77 }], "", "/test/%s", "/test/%s/%s")
79 self.assertEqual({'file:tests/hw.py': MapperEnt(resolved='keep:99999999999999999999999999999991+99/hw.py', target='/test/99999999999999999999999999999991+99/hw.py', type='File', staged=True)},
82 @mock.patch("arvados.commands.run.uploadfiles")
83 @mock.patch("arvados.commands.run.statfile")
84 def test_statfile(self, statfile, upl):
85 """Test pathmapper handling ArvFile references."""
86 arvrunner = arvados_cwl.ArvCwlRunner(self.api)
88 # An ArvFile object returned from arvados.commands.run.statfile means the file is located on a
89 # keep mount, so we can construct a direct reference directly without upload.
90 def statfile_mock(prefix, fn, fnPattern="$(file %s/%s)", dirPattern="$(dir %s/%s/)"):
91 st = arvados.commands.run.ArvFile("", fnPattern % ("99999999999999999999999999999991+99", "hw.py"))
94 upl.side_effect = upload_mock
95 statfile.side_effect = statfile_mock
97 p = ArvPathMapper(arvrunner, [{
99 "location": "file:tests/hw.py"
100 }], "", "/test/%s", "/test/%s/%s")
102 self.assertEqual({'file:tests/hw.py': MapperEnt(resolved='keep:99999999999999999999999999999991+99/hw.py', target='/test/99999999999999999999999999999991+99/hw.py', type='File', staged=True)},