Allow renaming of uploaded files in toolbox tests by including a <edit_attributes type="name" value="new dataset name" /> child tag. A rename directive is automatically assigned (no xml changes required) to uploaded composite datasets, so that they can be identified uniquely.

This commit is contained in:
Daniel Blankenberg
2010-03-10 11:28:50 -05:00
parent 02565373ec
commit becb50feaa
3 changed files with 44 additions and 6 deletions
+23
View File
@@ -510,6 +510,7 @@ class Tool:
store in `self.tests`.
"""
self.tests = []
composite_data_names_counter = 0 #composite datasets need a unique name: each test occurs in a fresh history, but we'll keep it unique per set of tests
for i, test_elem in enumerate( tests_elem.findall( 'test' ) ):
name = test_elem.get( 'name', 'Test-%d' % (i+1) )
maxseconds = int( test_elem.get( 'maxseconds', '120' ) )
@@ -524,6 +525,28 @@ class Tool:
else:
value = None
attrib['children'] = list( param_elem.getchildren() )
if attrib['children']:
#at this time, we can assume having children only occurs on DataToolParameter test items
#but this could change and would cause the below parsing to change based upon differences in children items
attrib['metadata'] = []
attrib['composite_data'] = []
attrib['edit_attributes'] = []
composite_data_name = None #composite datasets need to be renamed uniquely
for child in attrib['children']:
if child.tag == 'composite_data':
attrib['composite_data'].append( child )
if composite_data_name is None:
#generate a unique name; each test uses a fresh history
composite_data_name = '_COMPOSITE_RENAMED %i_' % ( composite_data_names_counter )
composite_data_names_counter += 1
elif child.tag == 'metadata':
attrib['metadata'].append( child )
elif child.tag == 'metadata':
attrib['metadata'].append( child )
elif child.tag == 'edit_attributes':
attrib['edit_attributes'].append( child )
if composite_data_name:
attrib['edit_attributes'].insert( 0, { 'type': 'name', 'value': composite_data_name } ) #composite datasets need implicit renaming; inserted at front of list so explicit declarations take precedence
test.add_param( attrib.pop( 'name' ), value, attrib )
for output_elem in test_elem.findall( "output" ):
attrib = dict( output_elem.attrib )
+7 -4
View File
@@ -30,12 +30,15 @@ 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 and len( [ child for child in extra.get( 'children', [] ) if child.tag == 'composite_data' ] ) == 0:
name_change = [ att for att in extra.get( 'edit_attributes', [] ) if att.get( 'type' ) == 'name' ]
if name_change:
name_change = name_change[-1].get( 'value' ) #only the last name change really matters
if value is None and not name_change:
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' )
self.required_files.append( ( value, extra ) ) #these files will be uploaded
if name_change:
value = name_change #change value for select to renamed uploaded file for e.g. composite dataset
except Exception, e:
log.debug( "Error in add_param for %s: %s" % ( name, e ) )
self.inputs.append( ( name, value, extra ) )
+14 -2
View File
@@ -33,10 +33,22 @@ class ToolTestCase( TwillTestCase ):
# Upload any needed files
for fname, extra in testdef.required_files:
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' ]
metadata = extra.get( 'metadata', [] )
composite_data = extra.get( '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
#Post upload attribute editing
edit_attributes = extra.get( 'edit_attributes', [] )
#currently only renaming is supported
for edit_att in edit_attributes:
if edit_att.get( 'type', None ) == 'name':
new_name = edit_att.get( 'value', None )
assert new_name, 'You must supply the new dataset name as the value tag of the edit_attributes tag'
hda_id = self.get_history_as_data_list()[-1].get( 'id' )
self.edit_hda_attribute_info( hda_id, new_name = new_name )
print "Renamed uploaded file to:", new_name
else:
raise Exception( 'edit_attributes type (%s) is unimplemented' % edit_att.get( 'type', None ) )
# 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.
all_inputs = {}