root/galaxy-central/lib/galaxy/tools/test.py @ 2

リビジョン 2, 4.3 KB (コミッタ: hatakeyama, 14 年 前)

import galaxy-central

行番号 
1import new, sys
2import galaxy.util
3import parameters
4from parameters import basic
5from parameters import grouping
6from elementtree.ElementTree import XML
7import logging
8
9log = logging.getLogger( __name__ )
10
11class ToolTestBuilder( object ):
12    """
13    Encapsulates information about a tool test, and allows creation of a
14    dynamic TestCase class (the unittest framework is very class oriented,
15    doing dynamic tests in this was allows better integration)
16    """
17    def __init__( self, tool, name, maxseconds ):
18        self.tool = tool
19        self.name = name
20        self.maxseconds = maxseconds
21        self.required_files = []
22        self.inputs = []
23        self.outputs = []
24        self.error = False
25        self.exception = None
26    def add_param( self, name, value, extra ):
27        try:
28            if name not in self.tool.inputs:
29                for input_name, input_value in self.tool.inputs.items():
30                    if isinstance( input_value, grouping.Conditional ) or isinstance( input_value, grouping.Repeat ):
31                        self.__expand_grouping_for_data_input(name, value, extra, input_name, input_value)
32            elif isinstance( self.tool.inputs[name], parameters.DataToolParameter ) and ( value, extra ) not in self.required_files:
33                name_change = [ att for att in extra.get( 'edit_attributes', [] ) if att.get( 'type' ) == 'name' ]
34                if name_change:
35                    name_change = name_change[-1].get( 'value' ) #only the last name change really matters
36                if value is None and not name_change:
37                    assert self.tool.inputs[name].optional, '%s is not optional. You must provide a valid filename.' % name
38                else:
39                    self.required_files.append( ( value, extra ) ) #these files will be uploaded
40                    if name_change:
41                        value = name_change #change value for select to renamed uploaded file for e.g. composite dataset
42        except Exception, e:
43            log.debug( "Error in add_param for %s: %s" % ( name, e ) )
44        self.inputs.append( ( name, value, extra ) )
45    def add_output( self, name, file, extra ):
46        self.outputs.append( ( name, file, extra ) )
47    def __expand_grouping_for_data_input( self, name, value, extra, grouping_name, grouping_value ):
48        # Currently handles grouping.Conditional and grouping.Repeat
49        if isinstance( grouping_value, grouping.Conditional  ):
50            if name != grouping_value.test_param.name:
51                for case in grouping_value.cases:
52                    for case_input_name, case_input_value in case.inputs.items():
53                        if case_input_name == name and isinstance( case_input_value, basic.DataToolParameter ) and ( value, extra ) not in self.required_files:
54                            if value is None:
55                                assert case_input_value.optional, '%s is not optional. You must provide a valid filename.' % name
56                            else:
57                                self.required_files.append( ( value, extra ) )
58                            return True
59                        elif isinstance( case_input_value, grouping.Conditional ):
60                            self.__expand_grouping_for_data_input(name, value, extra, case_input_name, case_input_value)
61        elif isinstance( grouping_value, grouping.Repeat ):
62            # FIXME: grouping.Repeat can only handle 1 repeat param element since the param name
63            # is something like "input2" and the expanded page display is something like "queries_0|input2".
64            # The problem is that the only param name on the page is "input2", and adding more test input params
65            # with the same name ( "input2" ) is not yet supported in our test code ( the lat one added is the only
66            # one used ).
67            for input_name, input_value in grouping_value.inputs.items():
68                if input_name == name and isinstance( input_value, basic.DataToolParameter ) and ( value, extra ) not in self.required_files:
69                    if value is None:
70                        assert input_value.optional, '%s is not optional. You must provide a valid filename.' % name
71                    else:
72                        self.required_files.append( ( value, extra ) )
73                    return True
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。