def do_it( self, testdef ): """ Run through a tool test case. """ shed_tool_id = self.shed_tool_id self._handle_test_def_errors( testdef ) galaxy_interactor = self._galaxy_interactor( testdef ) test_history = galaxy_interactor.new_history() # history where inputs will be put, if any stage_data_in_history( galaxy_interactor, testdef.test_data(), test_history, shed_tool_id ) galaxy_interactor.run_tool( testdef, test_history ) # test_history will have inputs only, outputs are placed in the specialized data manager history # FIXME: Move history determination and switching into the interactor data_manager_history = None for assoc in reversed( test_history.user.data_manager_histories ): if not assoc.history.deleted: data_manager_history = assoc.history break self.switch_history( id=self.security.encode_id( data_manager_history.id ) ) data_list = self.get_history_as_data_list() # end self.assertTrue( data_list ) self._verify_outputs( testdef, data_manager_history, shed_tool_id, data_list, galaxy_interactor ) self.switch_history( id=self.security.encode_id( test_history.id ) ) galaxy_interactor.delete_history( test_history )
def do_it( self, testdef ): """ Run through a tool test case. """ shed_tool_id = self.shed_tool_id self._handle_test_def_errors( testdef ) galaxy_interactor = self._galaxy_interactor( testdef ) test_history = galaxy_interactor.new_history() stage_data_in_history( galaxy_interactor, testdef.test_data(), test_history, shed_tool_id ) # Once data is ready, run the tool and check the outputs - record API # input, job info, tool run exception, as well as exceptions related to # job output checking and register they with the test plugin so it can # record structured information. tool_inputs = None job_stdio = None job_output_exceptions = None tool_execution_exception = None try: try: tool_response = galaxy_interactor.run_tool( testdef, test_history ) data_list, jobs, tool_inputs = tool_response.outputs, tool_response.jobs, tool_response.inputs data_collection_list = tool_response.output_collections except RunToolException as e: tool_inputs = e.inputs tool_execution_exception = e raise e except Exception as e: tool_execution_exception = e raise e self.assertTrue( data_list or data_collection_list ) try: job_stdio = self._verify_outputs( testdef, test_history, jobs, shed_tool_id, data_list, data_collection_list, galaxy_interactor ) except JobOutputsError as e: job_stdio = e.job_stdio job_output_exceptions = e.output_exceptions raise e except Exception as e: job_output_exceptions = [e] raise e finally: job_data = {} if tool_inputs is not None: job_data["inputs"] = tool_inputs if job_stdio is not None: job_data["job"] = job_stdio if job_output_exceptions: job_data["output_problems"] = map(str, job_output_exceptions) if tool_execution_exception: job_data["execution_problem"] = str(tool_execution_exception) register_job_data(job_data) galaxy_interactor.delete_history( test_history )
def test_workflow( self, workflow_test_file=None ): maxseconds = 120 workflow_test_file = workflow_test_file or WorkflowTestCase.workflow_test_file assert workflow_test_file workflow_test = parse_test_file( workflow_test_file ) galaxy_interactor = GalaxyWorkflowInteractor( self ) # Calling workflow https://github.com/jmchilton/blend4j/blob/master/src/test/java/com/github/jmchilton/blend4j/galaxy/WorkflowsTest.java # Import workflow workflow_id, step_id_map, output_defs = self.__import_workflow( galaxy_interactor, workflow_test.workflow ) # Stage data and history for workflow test_history = galaxy_interactor.new_history() stage_data_in_history( galaxy_interactor, workflow_test.test_data(), test_history ) # Build workflow parameters uploads = galaxy_interactor.uploads ds_map = {} for step_index, input_dataset_label in workflow_test.input_datasets(): # Upload is {"src": "hda", "id": hid} try: upload = uploads[ workflow_test.upload_name( input_dataset_label ) ] except KeyError: raise AssertionError( "Failed to find upload with label %s in uploaded datasets %s" % ( input_dataset_label, uploads ) ) ds_map[ step_id_map[ step_index ] ] = upload payload = { "history": "hist_id=%s" % test_history, "ds_map": dumps( ds_map ), "workflow_id": workflow_id, } run_response = galaxy_interactor.run_workflow( payload ).json() outputs = run_response[ 'outputs' ] if not len( outputs ) == len( output_defs ): msg_template = "Number of outputs [%d] created by workflow execution does not equal expected number from input file [%d]." msg = msg_template % ( len( outputs ), len( output_defs ) ) raise AssertionError( msg ) galaxy_interactor.wait_for_ids( test_history, outputs ) for expected_output_def in workflow_test.outputs: # Get the correct hid name, outfile, attributes = expected_output_def output_testdef = bunch.Bunch( name=name, outfile=outfile, attributes=attributes ) output_data = outputs[ int( name ) ] try: galaxy_interactor.verify_output( test_history, output_data, output_testdef=output_testdef, shed_tool_id=None, maxseconds=maxseconds ) except Exception: for stream in ['stdout', 'stderr']: stream_output = galaxy_interactor.get_job_stream( test_history, output_data, stream=stream ) print >>sys.stderr, self._format_stream( stream_output, stream=stream, format=True ) raise
def do_it( self, testdef ): """ Run through a tool test case. """ shed_tool_id = self.shed_tool_id self._handle_test_def_errors( testdef ) galaxy_interactor = self._galaxy_interactor( testdef ) test_history = galaxy_interactor.new_history() stage_data_in_history( galaxy_interactor, testdef.test_data(), test_history, shed_tool_id ) data_list = galaxy_interactor.run_tool( testdef, test_history ) self.assertTrue( data_list ) self._verify_outputs( testdef, test_history, shed_tool_id, data_list, galaxy_interactor ) galaxy_interactor.delete_history( test_history )
def do_it(self, testdef): """ Run through a tool test case. """ shed_tool_id = self.shed_tool_id self._handle_test_def_errors(testdef) galaxy_interactor = self._galaxy_interactor(testdef) test_history = galaxy_interactor.new_history() stage_data_in_history(galaxy_interactor, testdef.test_data(), test_history, shed_tool_id) data_list = galaxy_interactor.run_tool(testdef, test_history) self.assertTrue(data_list) self._verify_outputs(testdef, test_history, shed_tool_id, data_list, galaxy_interactor) galaxy_interactor.delete_history(test_history)
def do_it(self, testdef): """ Run through a tool test case. """ shed_tool_id = self.shed_tool_id self._handle_test_def_errors(testdef) galaxy_interactor = self._galaxy_interactor(testdef) test_history = galaxy_interactor.new_history( ) # history where inputs will be put, if any stage_data_in_history(galaxy_interactor, testdef.test_data(), test_history, shed_tool_id) galaxy_interactor.run_tool( testdef, test_history ) # test_history will have inputs only, outputs are placed in the specialized data manager history # FIXME: Move history determination and switching into the interactor data_manager_history = None for assoc in reversed(test_history.user.data_manager_histories): if not assoc.history.deleted: data_manager_history = assoc.history break self.switch_history( id=self.security.encode_id(data_manager_history.id)) data_list = self.get_history_as_data_list() # end self.assertTrue(data_list) self._verify_outputs(testdef, data_manager_history, shed_tool_id, data_list, galaxy_interactor) self.switch_history(id=self.security.encode_id(test_history.id)) galaxy_interactor.delete_history(test_history)
def do_it(self, testdef, resource_parameters={}): """ Run through a tool test case. """ shed_tool_id = self.shed_tool_id self._handle_test_def_errors(testdef) galaxy_interactor = self._galaxy_interactor(testdef) test_history = galaxy_interactor.new_history() stage_data_in_history(galaxy_interactor, testdef.test_data(), test_history, shed_tool_id) # Once data is ready, run the tool and check the outputs - record API # input, job info, tool run exception, as well as exceptions related to # job output checking and register they with the test plugin so it can # record structured information. tool_inputs = None job_stdio = None job_output_exceptions = None tool_execution_exception = None expected_failure_occurred = False try: try: tool_response = galaxy_interactor.run_tool( testdef, test_history, resource_parameters=resource_parameters) data_list, jobs, tool_inputs = tool_response.outputs, tool_response.jobs, tool_response.inputs data_collection_list = tool_response.output_collections except RunToolException as e: tool_inputs = e.inputs tool_execution_exception = e if not testdef.expect_failure: raise e else: expected_failure_occurred = True except Exception as e: tool_execution_exception = e raise e if not expected_failure_occurred: self.assertTrue(data_list or data_collection_list) try: job_stdio = self._verify_outputs(testdef, test_history, jobs, shed_tool_id, data_list, data_collection_list, galaxy_interactor) except JobOutputsError as e: job_stdio = e.job_stdio job_output_exceptions = e.output_exceptions raise e except Exception as e: job_output_exceptions = [e] raise e finally: job_data = {} if tool_inputs is not None: job_data["inputs"] = tool_inputs if job_stdio is not None: job_data["job"] = job_stdio if job_output_exceptions: job_data["output_problems"] = [ str(_) for _ in job_output_exceptions ] if tool_execution_exception: job_data["execution_problem"] = str(tool_execution_exception) register_job_data(job_data) galaxy_interactor.delete_history(test_history)