Repository: common-workflow-language/cwltool

Issue:
UnboundLocalError: local variable 'dockerimg' referenced before assignment
```
.virtualenv/bin/cwltool \
	--enable-ext \
	--outdir results \
	--cachedir cache \
	workflow.cwl \
	job.cwl
.virtualenv/bin/cwltool 1.0.20171017195544
Resolved 'workflow.cwl' to 'file:///home/gijs/prefactor-cwl/workflow.cwl'
[workflow workflow.cwl] start
[step createmap_cal] start
Unexpected exception
Traceback (most recent call last):
  File "/home/gijs/prefactor-cwl/.virtualenv/local/lib/python2.7/site-packages/cwltool/workflow.py", line 810, in job
    **kwargs):
  File "/home/gijs/prefactor-cwl/.virtualenv/local/lib/python2.7/site-packages/cwltool/draft2tool.py", line 268, in job
    if dockerimg:
UnboundLocalError: local variable 'dockerimg' referenced before assignment
[step createmap_cal] Cannot make job: local variable 'dockerimg' referenced before assignment
[workflow workflow.cwl] completed permanentFail
{
    "mapfile": null
}
Final process status is permanentFail
```

CWL files: https://github.com/gijzelaerr/prefactor-cwl/tree/9bd863af640a75a69342d7a2e890d60cfe15f002


Discussion:
Confirmed with this single line test:
```
cwltool --cachedir cache https://raw.githubusercontent.com/gijzelaerr/prefactor-cwl/9bd863af640a75a69342d7a2e890d60cfe15f002/workflow.cwl --ms $(mktemp -d)
```

Resolving patch:
diff --git a/cwltool/draft2tool.py b/cwltool/draft2tool.py
--- a/cwltool/draft2tool.py
+++ b/cwltool/draft2tool.py
@@ -264,6 +264,8 @@ def job(self,
                 dockerimg = docker_req.get("dockerImageId") or docker_req.get("dockerPull")
             elif kwargs.get("default_container", None) is not None and kwargs.get("use_container"):
                 dockerimg = kwargs.get("default_container")
+            else:
+                dockerimg = None
 
             if dockerimg:
                 cmdline = ["docker", "run", dockerimg] + cmdline


Test patch:
diff --git a/tests/test_examples.py b/tests/test_examples.py
--- a/tests/test_examples.py
+++ b/tests/test_examples.py
@@ -7,6 +7,8 @@
 
 from io import StringIO
 
+from cwltool.utils import onWindows
+
 try:
     reload
 except:
@@ -530,19 +532,20 @@ def test_print_dot(self):
         self.assertEquals(main(["--print-dot", get_data('tests/wf/revsort.cwl')]), 0)
 
 
-class TestJsConsole(unittest.TestCase):
+class TestCmdLine(unittest.TestCase):
     def get_main_stderr(self, new_args):
-        cwltool_base = path.join(path.dirname(path.abspath(__name__)), "cwltool")
-        
         process = subprocess.Popen([
-            sys.executable,
-            "-m",
-            "cwltool"
-        ] + new_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+                                       sys.executable,
+                                       "-m",
+                                       "cwltool"
+                                   ] + new_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
 
         stdout, stderr = process.communicate()
         return process.returncode, stderr.decode()
 
+
+class TestJsConsole(TestCmdLine):
+
     def test_js_console_cmd_line_tool(self):
         for test_file in ("js_output.cwl", "js_output_workflow.cwl"):
             error_code, output = self.get_main_stderr(["--js-console", "--no-container",
@@ -555,11 +558,24 @@ def test_js_console_cmd_line_tool(self):
 
     def test_no_js_console(self):
         for test_file in ("js_output.cwl", "js_output_workflow.cwl"):
-            error_code, output = self.get_main_stderr(["--no-container", 
+            error_code, output = self.get_main_stderr(["--no-container",
                 get_data("tests/wf/" + test_file)])
 
             self.assertNotIn("[log] Log message", output)
             self.assertNotIn("[err] Error message", output)
-            
+
+
+@pytest.mark.skipif(onWindows(),
+                    reason="Instance of cwltool is used, on Windows it invokes a default docker container"
+                           "which is not supported on AppVeyor")
+class TestCache(TestCmdLine):
+    def test_wf_without_container(self):
+        test_file = "hello-workflow.cwl"
+        error_code, output = self.get_main_stderr(["--cachedir", "cache",
+                                                       get_data("tests/wf/" + test_file), "--usermessage", "hello"])
+        self.assertIn("completed success", output)
+        self.assertEquals(error_code, 0)
+
+
 if __name__ == '__main__':
     unittest.main()