def test_get_past_results_from_kernel(self): from cwlkernel.CWLKernel import CWLKernel kernel = CWLKernel() # cancel send_response kernel.send_response = lambda *args, **kwargs: None with open(os.sep.join([self.data_directory, 'tar_job.yml'])) as f: data = f.read() tar_directory = kernel._cwl_executor.file_manager.ROOT_DIRECTORY with open(os.path.join(tar_directory, 'hello.txt'), 'w') as temp_hello_world_file: temp_hello_world_file.write("hello world") tar_full_name = os.path.join(tar_directory, 'tarfile.tar') print('create tar file:', tar_full_name) with tarfile.open(tar_full_name, 'w') as tar: tar.add(temp_hello_world_file.name) data = data.format(tar_directory=tar_directory) result = kernel.do_execute(data, False) self.assertEqual('ok', result['status'], f'execution returned an error') with open(os.sep.join([self.cwl_directory, 'extract_tar.cwl'])) as f: workflow_str = f.read().format(example_out=temp_hello_world_file.name[1:]) result = kernel.do_execute(workflow_str, False) self.assertEqual('ok', result['status'], f'execution returned an error') full_path, basename = [(f, os.path.basename(f)) for f in kernel.get_past_results()][0] self.assertTrue(full_path.startswith(kernel._results_manager.ROOT_DIRECTORY), 'output is in a wrong directory') self.assertTrue(basename, 'hello.txt')
def test_get_past_results_without_input(self): from cwlkernel.CWLKernel import CWLKernel kernel = CWLKernel() # cancel send_response kernel.send_response = lambda *args, **kwargs: None with open(os.sep.join([self.cwl_directory, 'touched.cwl'])) as f: workflow_str = f.read() self.assertDictEqual( {'status': 'ok', 'execution_count': 0, 'payload': [], 'user_expressions': {}}, kernel.do_execute(workflow_str) ) self.assertEqual(0, len(kernel.get_past_results())) self.assertDictEqual( {'status': 'ok', 'execution_count': 0, 'payload': [], 'user_expressions': {}}, kernel.do_execute('% execute touch') ) full_path, basename = [(f, os.path.basename(f)) for f in kernel.get_past_results()][0] self.assertTrue(full_path.startswith(kernel._results_manager.ROOT_DIRECTORY), 'output is in a wrong directory') self.assertTrue(basename, 'touchedfile.txt')
def test_get_past_results_without_input(self): from cwlkernel.CWLKernel import CWLKernel kernel = CWLKernel() # cancel send_response kernel.send_response = lambda *args, **kwargs: None with open(os.sep.join([self.cwl_directory, 'touched.cwl'])) as f: workflow_str = f.read() result = kernel.do_execute(workflow_str, False) full_path, basename = [(f, os.path.basename(f)) for f in kernel.get_past_results()][0] self.assertTrue(full_path.startswith(kernel._results_manager.ROOT_DIRECTORY), 'output is in a wrong directory') self.assertTrue(basename, 'touchedfile.txt')