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):
24 def test_keepref(self):
25 """Test direct keep references."""
27 arvrunner = arvados_cwl.ArvCwlRunner(mock.MagicMock())
29 p = ArvPathMapper(arvrunner, [{
31 "location": "keep:99999999999999999999999999999991+99/hw.py"
32 }], "", "/test/%s", "/test/%s/%s")
34 self.assertEqual({'keep:99999999999999999999999999999991+99/hw.py': MapperEnt(resolved='keep:99999999999999999999999999999991+99/hw.py', target='/test/99999999999999999999999999999991+99/hw.py', type='File')},
37 @mock.patch("arvados.commands.run.uploadfiles")
38 def test_upload(self, upl):
39 """Test pathmapper uploading files."""
41 arvrunner = arvados_cwl.ArvCwlRunner(mock.MagicMock())
43 upl.side_effect = upload_mock
45 p = ArvPathMapper(arvrunner, [{
47 "location": "tests/hw.py"
48 }], "", "/test/%s", "/test/%s/%s")
50 self.assertEqual({'tests/hw.py': MapperEnt(resolved='keep:99999999999999999999999999999991+99/hw.py', target='/test/99999999999999999999999999999991+99/hw.py', type='File')},
53 @mock.patch("arvados.commands.run.uploadfiles")
54 def test_prev_uploaded(self, upl):
55 """Test pathmapper handling previously uploaded files."""
57 arvrunner = arvados_cwl.ArvCwlRunner(mock.MagicMock())
58 arvrunner.add_uploaded('tests/hw.py', MapperEnt(resolved='keep:99999999999999999999999999999991+99/hw.py', target='', type='File'))
60 upl.side_effect = upload_mock
62 p = ArvPathMapper(arvrunner, [{
64 "location": "tests/hw.py"
65 }], "", "/test/%s", "/test/%s/%s")
67 self.assertEqual({'tests/hw.py': MapperEnt(resolved='keep:99999999999999999999999999999991+99/hw.py', target='/test/99999999999999999999999999999991+99/hw.py', type='File')},
70 @mock.patch("arvados.commands.run.uploadfiles")
71 @mock.patch("arvados.commands.run.statfile")
72 def test_statfile(self, statfile, upl):
73 """Test pathmapper handling ArvFile references."""
74 arvrunner = arvados_cwl.ArvCwlRunner(mock.MagicMock())
76 # An ArvFile object returned from arvados.commands.run.statfile means the file is located on a
77 # keep mount, so we can construct a direct reference directly without upload.
78 def statfile_mock(prefix, fn, fnPattern="$(file %s/%s)", dirPattern="$(dir %s/%s/)"):
79 st = arvados.commands.run.ArvFile("", fnPattern % ("99999999999999999999999999999991+99", "hw.py"))
82 upl.side_effect = upload_mock
83 statfile.side_effect = statfile_mock
85 p = ArvPathMapper(arvrunner, [{
87 "location": "tests/hw.py"
88 }], "", "/test/%s", "/test/%s/%s")
90 self.assertEqual({'tests/hw.py': MapperEnt(resolved='keep:99999999999999999999999999999991+99/hw.py', target='/test/99999999999999999999999999999991+99/hw.py', type='File')},