diff --git a/lib/galaxy/jobs/__init__.py b/lib/galaxy/jobs/__init__.py index 9fca963bc96..73e3b4b6dc0 100644 --- a/lib/galaxy/jobs/__init__.py +++ b/lib/galaxy/jobs/__init__.py @@ -1298,11 +1298,10 @@ class JobWrapper( object ): dataset.set_peek( is_multi_byte=True ) else: dataset.set_peek() - try: - # set the name if provided by the tool - dataset.name = context['name'] - except: - pass + for context_key in ['name', 'info', 'dbkey']: + if context_key in context: + context_value = context[context_key] + setattr(dataset, context_key, context_value) else: dataset.blurb = "empty" if dataset.ext == 'auto': diff --git a/lib/galaxy/tools/parameters/output_collect.py b/lib/galaxy/tools/parameters/output_collect.py index 1fb52296c77..6dff4027022 100644 --- a/lib/galaxy/tools/parameters/output_collect.py +++ b/lib/galaxy/tools/parameters/output_collect.py @@ -314,6 +314,8 @@ def collect_primary_datasets( tool, output, job_working_directory, input_ext, in ) metadata_dict = new_primary_datasets_attributes.get( 'metadata', None ) if metadata_dict: + if "dbkey" in new_primary_datasets_attributes: + metadata_dict["dbkey"] = new_primary_datasets_attributes["dbkey"] primary_data.metadata.from_JSON_dict( json_dict=metadata_dict ) else: primary_data.set_meta() diff --git a/lib/galaxy/tools/parser/xml.py b/lib/galaxy/tools/parser/xml.py index 178cf6a3f46..47b990901c1 100644 --- a/lib/galaxy/tools/parser/xml.py +++ b/lib/galaxy/tools/parser/xml.py @@ -391,15 +391,7 @@ def __parse_output_elem( output_elem ): if name is None: raise Exception( "Test output does not have a 'name'" ) - file, attributes = __parse_test_attributes( output_elem, attrib ) - primary_datasets = {} - for primary_elem in ( output_elem.findall( "discovered_dataset" ) or [] ): - primary_attrib = dict( primary_elem.attrib ) - designation = primary_attrib.pop( 'designation', None ) - if designation is None: - raise Exception( "Test primary dataset does not have a 'designation'" ) - primary_datasets[ designation ] = __parse_test_attributes( primary_elem, primary_attrib ) - attributes[ "primary_datasets" ] = primary_datasets + file, attributes = __parse_test_attributes( output_elem, attrib, parse_discovered_datasets=True ) return name, file, attributes @@ -436,7 +428,7 @@ def __parse_element_tests( parent_element ): return element_tests -def __parse_test_attributes( output_elem, attrib, parse_elements=False ): +def __parse_test_attributes( output_elem, attrib, parse_elements=False, parse_discovered_datasets=False ): assert_list = __parse_assert_list( output_elem ) # Allow either file or value to specify a target file to compare result with @@ -466,8 +458,18 @@ def __parse_test_attributes( output_elem, attrib, parse_elements=False ): if parse_elements: element_tests = __parse_element_tests( output_elem ) + primary_datasets = {} + if parse_discovered_datasets: + for primary_elem in ( output_elem.findall( "discovered_dataset" ) or [] ): + primary_attrib = dict( primary_elem.attrib ) + designation = primary_attrib.pop( 'designation', None ) + if designation is None: + raise Exception( "Test primary dataset does not have a 'designation'" ) + primary_datasets[ designation ] = __parse_test_attributes( primary_elem, primary_attrib ) + has_checksum = md5sum or checksum - if not (assert_list or file or extra_files or metadata or has_checksum or element_tests): + has_nested_tests = extra_files or element_tests or primary_datasets + if not (assert_list or file or metadata or has_checksum or has_nested_tests): raise Exception( "Test output defines nothing to check (e.g. must have a 'file' check against, assertions to check, metadata or checksum tests, etc...)") attributes['assert_list'] = assert_list attributes['extra_files'] = extra_files @@ -475,6 +477,7 @@ def __parse_test_attributes( output_elem, attrib, parse_elements=False ): attributes['md5'] = md5sum attributes['checksum'] = checksum attributes['elements'] = element_tests + attributes['primary_datasets'] = primary_datasets return file, attributes diff --git a/lib/galaxy_ext/metadata/set_metadata.py b/lib/galaxy_ext/metadata/set_metadata.py index a540ff36df5..6f70a9d0f63 100644 --- a/lib/galaxy_ext/metadata/set_metadata.py +++ b/lib/galaxy_ext/metadata/set_metadata.py @@ -141,10 +141,11 @@ def set_metadata(): json.dump( ( False, str( e ) ), open( filename_results_code, 'wb+' ) ) # setting metadata has failed somehow for i, ( filename, file_dict ) in enumerate( new_job_metadata_dict.iteritems(), start=1 ): - new_dataset = galaxy.model.Dataset( id=-i, external_filename=os.path.join( tool_job_working_directory, file_dict[ 'filename' ] ) ) + new_dataset_filename = os.path.join( tool_job_working_directory, "working", file_dict[ 'filename' ] ) + new_dataset = galaxy.model.Dataset( id=-i, external_filename=new_dataset_filename ) extra_files = file_dict.get( 'extra_files', None ) if extra_files is not None: - new_dataset._extra_files_path = os.path.join( tool_job_working_directory, extra_files ) + new_dataset._extra_files_path = os.path.join( tool_job_working_directory, "working", extra_files ) new_dataset.state = new_dataset.states.OK new_dataset_instance = galaxy.model.HistoryDatasetAssociation( id=-i, dataset=new_dataset, extension=file_dict.get( 'ext', 'data' ) ) set_meta_with_tool_provided( new_dataset_instance, file_dict, set_meta_kwds, datatypes_registry ) diff --git a/test/base/interactor.py b/test/base/interactor.py index 69e32f1b1a0..04a115a5d59 100644 --- a/test/base/interactor.py +++ b/test/base/interactor.py @@ -7,6 +7,7 @@ from logging import getLogger from requests import get, post, delete, patch from six import StringIO +from six import text_type from galaxy import util from galaxy.tools.parser.interface import TestCollectionDef @@ -87,27 +88,45 @@ class GalaxyInteractorApi( object ): def verify_output_dataset( self, history_id, hda_id, outfile, attributes, shed_tool_id ): fetcher = self.__dataset_fetcher( history_id ) - self.twill_test_case.verify_hid( outfile, hda_id=hda_id, attributes=attributes, dataset_fetcher=fetcher, shed_tool_id=shed_tool_id ) + self.twill_test_case.verify_hid( + outfile, + hda_id=hda_id, + attributes=attributes, + dataset_fetcher=fetcher, + shed_tool_id=shed_tool_id + ) self._verify_metadata( history_id, hda_id, attributes ) def _verify_metadata( self, history_id, hid, attributes ): + """Check dataset metadata. + + ftype on output maps to `file_ext` on the hda's API description, `name`, `info`, + and `dbkey` all map to the API description directly. Other metadata attributes + are assumed to be datatype-specific and mapped with a prefix of `metadata_`. + """ metadata = attributes.get( 'metadata', {} ).copy() for key, value in metadata.copy().items(): - new_key = "metadata_%s" % key - metadata[ new_key ] = metadata[ key ] - del metadata[ key ] + if key not in ['name', 'info']: + new_key = "metadata_%s" % key + metadata[ new_key ] = metadata[ key ] + del metadata[ key ] + elif key == "info": + metadata[ "misc_info" ] = metadata[ "info" ] + del metadata[ "info" ] expected_file_type = attributes.get( 'ftype', None ) if expected_file_type: metadata[ "file_ext" ] = expected_file_type if metadata: + import time + time.sleep(5) dataset = self._get( "histories/%s/contents/%s" % ( history_id, hid ) ).json() for key, value in metadata.items(): try: dataset_value = dataset.get( key, None ) - if dataset_value != value: - msg = "Dataset metadata verification for [%s] failed, expected [%s] but found [%s]." - msg_params = ( key, value, dataset_value ) + if text_type(dataset_value) != text_type(value): + msg = "Dataset metadata verification for [%s] failed, expected [%s] but found [%s]. Dataset API value was [%s]." + msg_params = ( key, value, dataset_value, dataset ) msg = msg % msg_params raise Exception( msg ) except KeyError: diff --git a/test/functional/tools/samples_tool_conf.xml b/test/functional/tools/samples_tool_conf.xml index 67ee93e5112..ef44e49a456 100644 --- a/test/functional/tools/samples_tool_conf.xml +++ b/test/functional/tools/samples_tool_conf.xml @@ -15,6 +15,9 @@ + + + diff --git a/test/functional/tools/tool_provided_metadata_1.xml b/test/functional/tools/tool_provided_metadata_1.xml new file mode 100644 index 00000000000..02d971a85f4 --- /dev/null +++ b/test/functional/tools/tool_provided_metadata_1.xml @@ -0,0 +1,29 @@ + + + echo "This is a line of text." > $out1; + cp $c1 galaxy.json; + + + {"type": "dataset", "dataset_id": $out1.dataset.dataset.id, "name": "my dynamic name", "ext": "txt", "info": "my dynamic info", "dbkey": "cust1"} + + + + + + + + + + + + + + + + + + + + + diff --git a/test/functional/tools/tool_provided_metadata_2.xml b/test/functional/tools/tool_provided_metadata_2.xml new file mode 100644 index 00000000000..8879d0f62af --- /dev/null +++ b/test/functional/tools/tool_provided_metadata_2.xml @@ -0,0 +1,38 @@ + + + echo "1" > sample1.report.tsv; + echo "2" > sample2.report.tsv; + cp $c1 galaxy.json; + + + {"type": "new_primary_dataset", "filename": "sample1.report.tsv", "name": "cool name 1", "ext": "txt", "info": "cool 1 info", "dbkey": "hg19"} +{"type": "new_primary_dataset", "filename": "sample2.report.tsv", "name": "cool name 2", "ext": "txt", "info": "cool 2 info", "dbkey": "hg19"} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/functional/tools/tool_provided_metadata_3.xml b/test/functional/tools/tool_provided_metadata_3.xml new file mode 100644 index 00000000000..a9a64f6ee82 --- /dev/null +++ b/test/functional/tools/tool_provided_metadata_3.xml @@ -0,0 +1,43 @@ + + + echo "1" > sample1.report.tsv; + echo "2" > sample2.report.tsv; + cp $c1 galaxy.json; + + + {"type": "new_primary_dataset", "filename": "sample1.report.tsv", "name": "cool name 1", "ext": "txt", "info": "cool 1 info", "dbkey": "hg19", "metadata": {"data_lines": 10, "foo": "bar"}} +{"type": "new_primary_dataset", "filename": "sample2.report.tsv", "name": "cool name 2", "ext": "txt", "info": "cool 2 info", "dbkey": "hg19", "metadata": {"data_lines": 20, "foo": "bar"}} + + + + + + + + + + + + + + + + + + + + + + + + + + + + +