diff --git a/cwltool/executors.py b/cwltool/executors.py index e5d676240..53c91fd1c 100644 --- a/cwltool/executors.py +++ b/cwltool/executors.py @@ -71,7 +71,8 @@ def execute(self, t, # type: Process if self.final_output and self.final_output[0] and finaloutdir: self.final_output[0] = relocateOutputs(self.final_output[0], finaloutdir, self.output_dirs, kwargs.get("move_outputs"), - kwargs["make_fs_access"]("")) + kwargs["make_fs_access"](""), + kwargs["compute_checksum"]) if kwargs.get("rm_tmpdir"): cleanIntermediate(self.output_dirs) diff --git a/cwltool/process.py b/cwltool/process.py index bf7a9edfe..37ef08921 100644 --- a/cwltool/process.py +++ b/cwltool/process.py @@ -256,8 +256,8 @@ def collectFilesAndDirs(obj, out): collectFilesAndDirs(l, out) -def relocateOutputs(outputObj, outdir, output_dirs, action, fs_access): - # type: (Union[Dict[Text, Any], List[Dict[Text, Any]]], Text, Set[Text], Text, StdFsAccess) -> Union[Dict[Text, Any], List[Dict[Text, Any]]] +def relocateOutputs(outputObj, outdir, output_dirs, action, fs_access, compute_checksum): + # type: (Union[Dict[Text, Any], List[Dict[Text, Any]]], Text, Set[Text], Text, StdFsAccess, bool) -> Union[Dict[Text, Any], List[Dict[Text, Any]]] adjustDirObjs(outputObj, functools.partial(get_listing, fs_access, recursive=True)) if action not in ("move", "copy"): @@ -299,8 +299,8 @@ def _check_adjust(f): return f visit_class(outputObj, ("File", "Directory"), _check_adjust) - - visit_class(outputObj, ("File",), functools.partial(compute_checksums, fs_access)) + if compute_checksum: + visit_class(outputObj, ("File",), functools.partial(compute_checksums, fs_access)) # If there are symlinks to intermediate output directories, we want to move # the real files into the final output location. If a file is linked more than once, diff --git a/tests/test_examples.py b/tests/test_examples.py index 36da186b8..480c8456d 100644 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -559,7 +559,7 @@ def test_print_dot(self): class TestCmdLine(unittest.TestCase): - def get_main_stderr(self, new_args): + def get_main_output(self, new_args): process = subprocess.Popen([ sys.executable, "-m", @@ -567,28 +567,28 @@ def get_main_stderr(self, new_args): ] + new_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = process.communicate() - return process.returncode, stderr.decode() + return process.returncode, stdout.decode(), 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", - get_data("tests/wf/" + test_file)]) + error_code, stdout, stderr = self.get_main_output(["--js-console", "--no-container", + get_data("tests/wf/" + test_file)]) - self.assertIn("[log] Log message", output) - self.assertIn("[err] Error message", output) + self.assertIn("[log] Log message", stderr) + self.assertIn("[err] Error message", stderr) - self.assertEquals(error_code, 0, output) + self.assertEquals(error_code, 0, stderr) 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", - get_data("tests/wf/" + test_file)]) + error_code, stdout, stderr = self.get_main_output(["--no-container", + get_data("tests/wf/" + test_file)]) - self.assertNotIn("[log] Log message", output) - self.assertNotIn("[err] Error message", output) + self.assertNotIn("[log] Log message", stderr) + self.assertNotIn("[err] Error message", stderr) @pytest.mark.skipif(onWindows(), @@ -597,11 +597,36 @@ def test_no_js_console(self): 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) + error_code, stdout, stderr = self.get_main_output(["--cachedir", "cache", + get_data("tests/wf/" + test_file), "--usermessage", "hello"]) + self.assertIn("completed success", stderr) self.assertEquals(error_code, 0) +@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 TestChecksum(TestCmdLine): + + def test_compute_checksum(self): + f = cwltool.factory.Factory(compute_checksum=True, use_container=False) + echo = f.make(get_data("tests/wf/cat-tool.cwl")) + output = echo(file1={ + "class": "File", + "location": get_data("tests/wf/whale.txt") + }, + reverse=False + ) + self.assertEquals(output['output']["checksum"], "sha1$327fc7aedf4f6b69a42a7c8b808dc5a7aff61376") + + def test_no_compute_checksum(self): + test_file = "tests/wf/wc-tool.cwl" + job_file = "tests/wf/wc-job.json" + error_code, stdout, stderr = self.get_main_output(["--no-compute-checksum", + get_data(test_file), get_data(job_file)]) + self.assertIn("completed success", stderr) + self.assertEquals(error_code, 0) + self.assertNotIn("checksum", stdout) + if __name__ == '__main__': unittest.main() diff --git a/tests/wf/cat-tool.cwl b/tests/wf/cat-tool.cwl new file mode 100644 index 000000000..3d92a5fc4 --- /dev/null +++ b/tests/wf/cat-tool.cwl @@ -0,0 +1,17 @@ +#!/usr/bin/env cwl-runner + +class: CommandLineTool +cwlVersion: v1.0 + +inputs: + file1: File + +outputs: + output: + type: File + outputBinding: { glob: output } + +baseCommand: [cat] + +stdin: $(inputs.file1.path) +stdout: output