From 994f2acdea83c9a24e1ed30aa7aae2d4ef1837fa Mon Sep 17 00:00:00 2001 From: Daniel Blankenberg Date: Tue, 9 Mar 2010 13:54:30 -0500 Subject: [PATCH] Allow uploading and use of composite files in toolbox tests. Along with setting each component of a composite datatype, metadata attributes (e.g. basename in Rgenetics datatypes) can be set. Example Tool: test cat ${i.extra_files_path}/${i.metadata.base_name}.fam > $out_file1 --- lib/galaxy/tools/__init__.py | 1 + lib/galaxy/tools/test.py | 4 +++- test/base/twilltestcase.py | 16 ++++++++++++---- test/functional/test_toolbox.py | 5 ++++- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/lib/galaxy/tools/__init__.py b/lib/galaxy/tools/__init__.py index 13a711034d6..d3a04e7c69a 100644 --- a/lib/galaxy/tools/__init__.py +++ b/lib/galaxy/tools/__init__.py @@ -523,6 +523,7 @@ class Tool: value = attrib['value'] else: value = None + attrib['children'] = list( param_elem.getchildren() ) test.add_param( attrib.pop( 'name' ), value, attrib ) for output_elem in test_elem.findall( "output" ): attrib = dict( output_elem.attrib ) diff --git a/lib/galaxy/tools/test.py b/lib/galaxy/tools/test.py index fb2fbe14919..082e5c03cd5 100644 --- a/lib/galaxy/tools/test.py +++ b/lib/galaxy/tools/test.py @@ -30,10 +30,12 @@ class ToolTestBuilder( object ): if isinstance( input_value, grouping.Conditional ) or isinstance( input_value, grouping.Repeat ): self.__expand_grouping_for_data_input(name, value, extra, input_name, input_value) elif isinstance( self.tool.inputs[name], parameters.DataToolParameter ) and ( value, extra ) not in self.required_files: - if value is None: + if value is None and len( [ child for child in extra.get( 'children', [] ) if child.tag == 'composite_data' ] ) == 0: assert self.tool.inputs[name].optional, '%s is not optional. You must provide a valid filename.' % name else: self.required_files.append( ( value, extra ) ) + if value is None and len( [ child for child in extra.get( 'children', [] ) if child.tag == 'composite_data' ] ) > 0: + value = extra.get( 'ftype' ) except Exception, e: log.debug( "Error in add_param for %s: %s" % ( name, e ) ) self.inputs.append( ( name, value, extra ) ) diff --git a/test/base/twilltestcase.py b/test/base/twilltestcase.py index f7873d0bedb..4c2b057a384 100644 --- a/test/base/twilltestcase.py +++ b/test/base/twilltestcase.py @@ -142,14 +142,22 @@ class TwillTestCase( unittest.TestCase ): filename = os.path.join( *path ) file(filename, 'wt').write(buffer.getvalue()) - def upload_file( self, filename, ftype='auto', dbkey='unspecified (?)' ): + def upload_file( self, filename, ftype='auto', dbkey='unspecified (?)', metadata = None, composite_data = None ): """Uploads a file""" - filename = self.get_filename(filename) self.visit_url( "%s/tool_runner?tool_id=upload1" % self.url ) try: - tc.fv("1","file_type", ftype) + self.refresh_form( "file_type", ftype ) #Refresh, to support composite files tc.fv("1","dbkey", dbkey) - tc.formfile("1","file_data", filename) + if metadata: + for elem in metadata: + tc.fv( "1", "files_metadata|%s" % elem.get( 'name' ), elem.get( 'value' ) ) + if composite_data: + for i, composite_file in enumerate( composite_data ): + filename = self.get_filename( composite_file.get( 'value' ) ) + tc.formfile( "1", "files_%i|file_data" % i, filename ) + else: + filename = self.get_filename( filename ) + tc.formfile( "1", "file_data", filename ) tc.submit("runtool_btn") self.home() except AssertionError, err: diff --git a/test/functional/test_toolbox.py b/test/functional/test_toolbox.py index 10dfe9f94b3..f07531568fc 100644 --- a/test/functional/test_toolbox.py +++ b/test/functional/test_toolbox.py @@ -32,7 +32,10 @@ class ToolTestCase( TwillTestCase ): raise AssertionError("ToolTestCase.do_it failed") # Upload any needed files for fname, extra in testdef.required_files: - self.upload_file( fname, ftype=extra.get( 'ftype', 'auto' ), dbkey=extra.get( 'dbkey', 'hg17' ) ) + children = extra.get( 'children', [] ) + metadata = [ child for child in children if child.tag == 'metadata' ] + composite_data = [ child for child in children if child.tag == 'composite_data' ] + self.upload_file( fname, ftype=extra.get( 'ftype', 'auto' ), dbkey=extra.get( 'dbkey', 'hg17' ), metadata = metadata, composite_data = composite_data ) print "Uploaded file: ", fname, ", ftype: ", extra.get( 'ftype', 'auto' ), ", extra: ", extra # We need to handle the case where we've uploaded a valid compressed file since the upload # tool will have uncompressed it on the fly.