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 = os.path.basename(c.fn)
22 c.keepref = "%s/%s" % (pdh, c.fn)
23 c.fn = fnPattern % (pdh, c.fn)
25 class TestPathmap(unittest.TestCase):
26 def test_keepref(self):
27 """Test direct keep references."""
29 arvrunner = arvados_cwl.ArvCwlRunner(mock.MagicMock())
31 p = ArvPathMapper(arvrunner, [{
33 "location": "keep:99999999999999999999999999999991+99/hw.py"
34 }], "", "/test/%s", "/test/%s/%s")
36 self.assertEqual({'keep:99999999999999999999999999999991+99/hw.py': MapperEnt(resolved='keep:99999999999999999999999999999991+99/hw.py', target='/test/99999999999999999999999999999991+99/hw.py', type='File')},
39 @mock.patch("arvados.commands.run.uploadfiles")
40 def test_upload(self, upl):
41 """Test pathmapper uploading files."""
43 arvrunner = arvados_cwl.ArvCwlRunner(mock.MagicMock())
45 upl.side_effect = upload_mock
47 p = ArvPathMapper(arvrunner, [{
49 "location": "tests/hw.py"
50 }], "", "/test/%s", "/test/%s/%s")
52 self.assertEqual({'tests/hw.py': MapperEnt(resolved='keep:99999999999999999999999999999991+99/hw.py', target='/test/99999999999999999999999999999991+99/hw.py', type='File')},
55 @mock.patch("arvados.commands.run.uploadfiles")
56 def test_prev_uploaded(self, upl):
57 """Test pathmapper handling previously uploaded files."""
59 arvrunner = arvados_cwl.ArvCwlRunner(mock.MagicMock())
60 arvrunner.add_uploaded('tests/hw.py', MapperEnt(resolved='keep:99999999999999999999999999999991+99/hw.py', target='', type='File'))
62 upl.side_effect = upload_mock
64 p = ArvPathMapper(arvrunner, [{
66 "location": "tests/hw.py"
67 }], "", "/test/%s", "/test/%s/%s")
69 self.assertEqual({'tests/hw.py': MapperEnt(resolved='keep:99999999999999999999999999999991+99/hw.py', target='/test/99999999999999999999999999999991+99/hw.py', type='File')},
72 @mock.patch("arvados.commands.run.uploadfiles")
73 @mock.patch("arvados.commands.run.statfile")
74 def test_statfile(self, statfile, upl):
75 """Test pathmapper handling ArvFile references."""
76 arvrunner = arvados_cwl.ArvCwlRunner(mock.MagicMock())
78 # An ArvFile object returned from arvados.commands.run.statfile means the file is located on a
79 # keep mount, so we can construct a direct reference directly without upload.
80 def statfile_mock(prefix, fn, fnPattern="$(file %s/%s)", dirPattern="$(dir %s/%s/)"):
81 st = arvados.commands.run.ArvFile("", fnPattern % ("99999999999999999999999999999991+99", "hw.py"))
82 st.keepref = "99999999999999999999999999999991+99/hw.py"
85 upl.side_effect = upload_mock
86 statfile.side_effect = statfile_mock
88 p = ArvPathMapper(arvrunner, [{
90 "location": "tests/hw.py"
91 }], "", "/test/%s", "/test/%s/%s")
93 self.assertEqual({'tests/hw.py': MapperEnt(resolved='keep:99999999999999999999999999999991+99/hw.py', target='/test/99999999999999999999999999999991+99/hw.py', type='File')},