def execute(self) -> Tuple[UUID, Dict, Optional[Exception]]: """ :return: Run ID, dict with new files, exception if there is any """ run_id = uuid4() runtime_context = RuntimeContext() runtime_context.outdir = self.file_manager.ROOT_DIRECTORY runtime_context.basedir = self.file_manager.ROOT_DIRECTORY runtime_context.default_stdin = subprocess.DEVNULL runtime_context.default_stdout = subprocess.DEVNULL runtime_context.default_stderr = subprocess.DEVNULL os.chdir(self.file_manager.ROOT_DIRECTORY) factory = Factory(runtime_context=runtime_context) executable = factory.make(self._workflow_path) data = {} for data_file in self._data_paths: with open(data_file) as f: new_data = yaml.load(f, Loader=yaml.Loader) data = {**new_data, **data} try: result: Dict = executable(**data) return run_id, result, None except Exception as e: traceback.print_exc(file=sys.stderr) return run_id, {}, e
def test_replace_default_stdout_stderr(): import sys # break stdout & stderr original_stdout = sys.stdout original_stderr = sys.stderr sys.stdout = '' sys.stderr = '' runtime_context = RuntimeContext() runtime_context.default_stdout = subprocess.DEVNULL runtime_context.default_stderr = subprocess.DEVNULL factory = get_windows_safe_factory(runtime_context=runtime_context) echo = factory.make(get_data("tests/echo.cwl")) assert echo(inp="foo") == {"out": "foo\n"} sys.stdout = original_stdout sys.stderr = original_stderr
def test_repo2cwl(self): output_dir = tempfile.mkdtemp() print(f'output directory:\t{output_dir}') repo2cwl = pkg_resources.load_entry_point('ipython2cwl', 'console_scripts', 'jupyter-repo2cwl') self.assertEqual(0, repo2cwl(['-o', output_dir, self.repo_like_dir])) self.assertListEqual( ['example1.cwl'], [f for f in os.listdir(output_dir) if not f.startswith('.')]) with open(os.path.join(output_dir, 'example1.cwl')) as f: print('workflow file') print(20 * '=') print(f.read()) print(20 * '=') runtime_context = RuntimeContext() runtime_context.outdir = output_dir runtime_context.basedir = output_dir runtime_context.default_stdout = DEVNULL runtime_context.default_stderr = DEVNULL fac = cwltool.factory.Factory(runtime_context=runtime_context) example1_tool = fac.make(os.path.join(output_dir, 'example1.cwl')) result = example1_tool(datafilename={ 'class': 'File', 'location': os.path.join(self.repo_like_dir, 'data.yaml') }, messages=["hello", "test", "!!!"]) with open(result['results_filename']['location'][7:]) as f: new_data = yaml.safe_load(f) self.assertDictEqual({ 'entry1': 2, 'entry2': 'foo', 'entry3': 'bar' }, new_data) with open(result['messages_outputs']['location'][7:]) as f: message = f.read() self.assertEqual("hello test !!!", message) shutil.rmtree(output_dir)
def test_replace_default_stdout_stderr() -> None: """Test our ability to replace the default stdout/err.""" import sys # break stdout & stderr original_stdout = sys.stdout original_stderr = sys.stderr sys.stdout = "" # type: ignore sys.stderr = "" # type: ignore runtime_context = RuntimeContext() runtime_context.default_stdout = subprocess.DEVNULL # type: ignore runtime_context.default_stderr = subprocess.DEVNULL # type: ignore factory = get_windows_safe_factory(runtime_context=runtime_context) echo = factory.make(get_data("tests/echo.cwl")) assert echo(inp="foo") == {"out": "foo\n"} sys.stdout = original_stdout sys.stderr = original_stderr