Change statfile in run.py to be able to raise OSError, and change the mock in test_pa...
authorJiayong Li <jiayong@math.mit.edu>
Fri, 26 May 2017 01:36:51 +0000 (21:36 -0400)
committerJiayong Li <jiayong@math.mit.edu>
Fri, 26 May 2017 01:36:51 +0000 (21:36 -0400)
sdk/cwl/tests/test_pathmapper.py
sdk/python/arvados/commands/run.py

index 3e7918a24a68fcb538dbf9307fea063303af9d02..7ba96497d8537101cc8ca38369c46a81d2cfab1e 100644 (file)
@@ -47,7 +47,7 @@ class TestPathmap(unittest.TestCase):
 
         arvrunner = arvados_cwl.ArvCwlRunner(self.api)
 
-        def statfile_mock(prefix, fn, fnPattern="$(file %s/%s)", dirPattern="$(dir %s/%s/)"):
+        def statfile_mock(prefix, fn, fnPattern="$(file %s/%s)", dirPattern="$(dir %s/%s/)", raiseOSError=False):
             st = arvados.commands.run.UploadFile("", "tests/hw.py")
             return st
 
@@ -87,7 +87,7 @@ class TestPathmap(unittest.TestCase):
 
         # An ArvFile object returned from arvados.commands.run.statfile means the file is located on a
         # keep mount, so we can construct a direct reference directly without upload.
-        def statfile_mock(prefix, fn, fnPattern="$(file %s/%s)", dirPattern="$(dir %s/%s/)"):
+        def statfile_mock(prefix, fn, fnPattern="$(file %s/%s)", dirPattern="$(dir %s/%s/)", raiseOSError=False):
             st = arvados.commands.run.ArvFile("", fnPattern % ("99999999999999999999999999999991+99", "hw.py"))
             return st
 
index 216b512085dc1f82dc54b6f1aa2f3802f45e21c9..6e02005d8facc79e15ba73be7526da7dd8eaad99 100644 (file)
@@ -108,7 +108,7 @@ def determine_project(root, current_user):
 # ArvFile() (file already exists in a collection), UploadFile() (file needs to
 # be uploaded to a collection), or simply returns prefix+fn (which yields the
 # original parameter string).
-def statfile(prefix, fn, fnPattern="$(file %s/%s)", dirPattern="$(dir %s/%s/)"):
+def statfile(prefix, fn, fnPattern="$(file %s/%s)", dirPattern="$(dir %s/%s/)", raiseOSError=False):
     absfn = os.path.abspath(fn)
     try:
         st = os.stat(absfn)
@@ -125,7 +125,7 @@ def statfile(prefix, fn, fnPattern="$(file %s/%s)", dirPattern="$(dir %s/%s/)"):
             # trim leading '/' for path prefix test later
             return UploadFile(prefix, absfn[1:])
     except OSError as e:
-        if e.errno == errno.ENOENT:
+        if e.errno == errno.ENOENT and not raiseOSError:
             pass
         else:
             raise