11 import arvados.collection
14 from cwltool.pathmapper import MapperEnt
16 from arvados_cwl.pathmapper import ArvPathMapper
18 def upload_mock(files, api, dry_run=False, num_retries=0, project=None, fnPattern="$(file %s/%s)", name=None):
19 pdh = "99999999999999999999999999999991+99"
21 c.fn = fnPattern % (pdh, os.path.basename(c.fn))
23 class TestPathmap(unittest.TestCase):
25 self.api = mock.MagicMock()
26 self.api._rootDesc = arvados.api('v1')._rootDesc
28 def test_keepref(self):
29 """Test direct keep references."""
31 arvrunner = arvados_cwl.ArvCwlRunner(self.api)
33 p = ArvPathMapper(arvrunner, [{
35 "location": "keep:99999999999999999999999999999991+99/hw.py"
36 }], "", "/test/%s", "/test/%s/%s")
38 self.assertEqual({'keep:99999999999999999999999999999991+99/hw.py': MapperEnt(resolved='keep:99999999999999999999999999999991+99/hw.py', target='/test/99999999999999999999999999999991+99/hw.py', type='File')},
41 @mock.patch("arvados.commands.run.uploadfiles")
42 def test_upload(self, upl):
43 """Test pathmapper uploading files."""
45 arvrunner = arvados_cwl.ArvCwlRunner(self.api)
47 upl.side_effect = upload_mock
49 p = ArvPathMapper(arvrunner, [{
51 "location": "tests/hw.py"
52 }], "", "/test/%s", "/test/%s/%s")
54 self.assertEqual({'tests/hw.py': MapperEnt(resolved='keep:99999999999999999999999999999991+99/hw.py', target='/test/99999999999999999999999999999991+99/hw.py', type='File')},
57 @mock.patch("arvados.commands.run.uploadfiles")
58 def test_prev_uploaded(self, upl):
59 """Test pathmapper handling previously uploaded files."""
61 arvrunner = arvados_cwl.ArvCwlRunner(self.api)
62 arvrunner.add_uploaded('tests/hw.py', MapperEnt(resolved='keep:99999999999999999999999999999991+99/hw.py', target='', type='File'))
64 upl.side_effect = upload_mock
66 p = ArvPathMapper(arvrunner, [{
68 "location": "tests/hw.py"
69 }], "", "/test/%s", "/test/%s/%s")
71 self.assertEqual({'tests/hw.py': MapperEnt(resolved='keep:99999999999999999999999999999991+99/hw.py', target='/test/99999999999999999999999999999991+99/hw.py', type='File')},
74 @mock.patch("arvados.commands.run.uploadfiles")
75 @mock.patch("arvados.commands.run.statfile")
76 def test_statfile(self, statfile, upl):
77 """Test pathmapper handling ArvFile references."""
78 arvrunner = arvados_cwl.ArvCwlRunner(self.api)
80 # An ArvFile object returned from arvados.commands.run.statfile means the file is located on a
81 # keep mount, so we can construct a direct reference directly without upload.
82 def statfile_mock(prefix, fn, fnPattern="$(file %s/%s)", dirPattern="$(dir %s/%s/)"):
83 st = arvados.commands.run.ArvFile("", fnPattern % ("99999999999999999999999999999991+99", "hw.py"))
86 upl.side_effect = upload_mock
87 statfile.side_effect = statfile_mock
89 p = ArvPathMapper(arvrunner, [{
91 "location": "tests/hw.py"
92 }], "", "/test/%s", "/test/%s/%s")
94 self.assertEqual({'tests/hw.py': MapperEnt(resolved='keep:99999999999999999999999999999991+99/hw.py', target='/test/99999999999999999999999999999991+99/hw.py', type='File')},