Exemplo n.º 1
0
    def test5WildCard(self):
        """Test the wildcard capabilities of CfgItemList"""
        i = CfgItemList('MyItems')
        self.failUnless(i.name() == 'MyItems')

        ## test wildcard
        i.add("Klass#Foo")
        self.failUnless(i("Klass") == ["Klass#Foo"])

        # ignored as not allowing wildcarded items
        i.add("Klass#*")
        self.failUnless(i("Klass") == ["Klass#Foo"])

        # allowed as special cases for trigger
        i.clear()
        i.add("TrigKlass#HLTAutoKey*")
        self.failUnless(i("TrigKlass") == ["TrigKlass#HLTAutoKey*"])

        i.clear()
        i.add("TrigKlass#HLTAutoKey_*")
        self.failUnless(i("TrigKlass") == ["TrigKlass#HLTAutoKey_*"])

        i.clear()
        i.add("TrigKlass#HLTAutoKey_foo_*")
        self.failUnless(i("TrigKlass") == ["TrigKlass#HLTAutoKey_foo_*"])

        i.clear()
        i.add("TrigKlass#HLTAutoKey_foo_42_*")
        self.failUnless(i("TrigKlass") == ["TrigKlass#HLTAutoKey_foo_42_*"])
Exemplo n.º 2
0
    def test5WildCard( self ):
        """Test the wildcard capabilities of CfgItemList"""
        i = CfgItemList( 'MyItems' )
        self.failUnless( i.name() == 'MyItems' )
        
        ## test wildcard
        i.add( "Klass#Foo" )
        self.failUnless( i("Klass") == ["Klass#Foo"] )

        # ignored as not allowing wildcarded items
        i.add( "Klass#*" )
        self.failUnless( i("Klass") == ["Klass#Foo"] )

        # allowed as special cases for trigger
        i.clear()
        i.add( "TrigKlass#HLTAutoKey*" )
        self.failUnless( i("TrigKlass") == ["TrigKlass#HLTAutoKey*"] )
        
        i.clear()
        i.add( "TrigKlass#HLTAutoKey_*" )
        self.failUnless( i("TrigKlass") == ["TrigKlass#HLTAutoKey_*"] )
        
        i.clear()
        i.add( "TrigKlass#HLTAutoKey_foo_*" )
        self.failUnless( i("TrigKlass") == ["TrigKlass#HLTAutoKey_foo_*"] )
        
        i.clear()
        i.add( "TrigKlass#HLTAutoKey_foo_42_*" )
        self.failUnless( i("TrigKlass") == ["TrigKlass#HLTAutoKey_foo_42_*"] )
Exemplo n.º 3
0
    def test3Hierarchy( self ):
        """Test tree-like hierarchy structure of item lists"""
        i = CfgItemList( 'MyItems',
                         items = [ 'Klass1#klass1',
                                   'Klass2#klass2', ],
                         allowWildCard = False )
        ii = CfgItemList( 'MySubItems',
                          items = [ 'Klass3#klass3',
                                    'Klass4#klass4',
                                    'Klass5#klass5',
                                    'Klass6#klass6' ] )
        self.assertTrue( len(i())  == 2,
                         "Invalid output item list !!" )
        self.assertTrue( len(ii()) == 4,
                         "Invalid output item list !!" )

        i += ii
        self.assertTrue( len(i())  == 6,
                         "Invalid output item list !!" )

        self.assertTrue( hasattr(i, ii.name()),
                         'Invalid hierarchy structure !!' )
        oo = getattr(i, ii.name())
        self.assertTrue( oo == ii,
                         'Invalid hierarchy structure !!' )
        self.assertTrue( oo is ii,
                         'Invalid hierarchy structure !!' )
        self.assertTrue( len(oo()) == 4,
                         "Invalid output item list !!" )
        
        del ii
        ii = CfgItemList( 'MySubItems' )
        self.assertTrue( len(ii())  == 4,
                         "Invalid output item list !!" )

        del i,ii
        i  = CfgItemList( 'MyItems' )
        ii = CfgItemList( 'MySubItems' )
        self.assertTrue( len( i())  == 0, "Invalid output item list !!" )
        self.assertTrue( len(ii())  == 4, "Invalid output item list !!" )
        del oo,ii
        ii = CfgItemList( 'MySubItems' )
        self.assertTrue( len(ii())  == 0, "Invalid output item list !!" )
Exemplo n.º 4
0
    def test3Hierarchy( self ):
        """Test tree-like hierarchy structure of item lists"""
        i = CfgItemList( 'MyItems',
                         items = [ 'Klass1#klass1',
                                   'Klass2#klass2', ],
                         allowWildCard = False )
        ii = CfgItemList( 'MySubItems',
                          items = [ 'Klass3#klass3',
                                    'Klass4#klass4',
                                    'Klass5#klass5',
                                    'Klass6#klass6' ] )
        self.failUnless( len(i())  == 2,
                         "Invalid output item list !!" )
        self.failUnless( len(ii()) == 4,
                         "Invalid output item list !!" )

        i += ii
        self.failUnless( len(i())  == 6,
                         "Invalid output item list !!" )

        self.failUnless( hasattr(i, ii.name()),
                         'Invalid hierarchy structure !!' )
        oo = getattr(i, ii.name())
        self.failUnless( oo == ii,
                         'Invalid hierarchy structure !!' )
        self.failUnless( oo is ii,
                         'Invalid hierarchy structure !!' )
        self.failUnless( len(oo()) == 4,
                         "Invalid output item list !!" )
        
        del ii
        ii = CfgItemList( 'MySubItems' )
        self.failUnless( len(ii())  == 4,
                         "Invalid output item list !!" )

        del i,ii
        i  = CfgItemList( 'MyItems' )
        ii = CfgItemList( 'MySubItems' )
        self.failUnless( len( i())  == 0, "Invalid output item list !!" )
        self.failUnless( len(ii())  == 4, "Invalid output item list !!" )
        del oo,ii
        ii = CfgItemList( 'MySubItems' )
        self.failUnless( len(ii())  == 0, "Invalid output item list !!" )
Exemplo n.º 5
0
    def test4Methods(self):
        """Test various methods of CfgItemList"""
        i = CfgItemList('MyItems')
        self.failUnless(i.name() == 'MyItems')

        i.add({'Klass': ['key1', 'key2']})
        self.failUnless(i() == ['Klass#key1', 'Klass#key2'])

        i.add({'Klass': ['key1', 'key3']})
        self.failUnless(i() == ['Klass#key1', 'Klass#key2', 'Klass#key3'])

        props = i.getProperties()
        self.failUnless(props.has_key('Klass'))
        self.failUnless(len(props['Klass']) == len(['key1', 'key2', 'key3']))
        self.failUnless('key1' in props['Klass'])
        self.failUnless('key2' in props['Klass'])
        self.failUnless('key3' in props['Klass'])

        self.failUnless(len(i.allChildren()) == 0)

        self.failUnless(i.has_item('Klass#key1'))
        self.failUnless(i.has_item('Klass#key*'))
        self.failUnless(not i.has_item('Klass#Key1'))
        self.failUnless(not i.has_item('Klass#Key*'))

        i.clear()
        self.failUnless(len(i()) == 0)

        i.add({'Klass': ['key1', 'key2']})
        self.failUnless(len(i()) == 2)
        i.remove('Klass')
        self.failUnless(len(i()) == 2)
        i.remove('Klass#key1')
        self.failUnless(len(i()) == 2)
        i.removeAll()
        self.failUnless(len(i()) == 2)

        i.removeItem('Klass')
        self.failUnless(len(i()) == 2)
        i.removeItem('Klass#key1')
        self.failUnless(len(i()) == 1)

        _keys = ['key1', 'key2', 'key3']
        i.add({'Klass': _keys})
        self.failUnless(len(i()) == 3)
        i.removeAllItems('Klass#key2')
        self.failUnless(len(i()) == 2)

        ## test we don't modify input dict
        d = {'Klassy': ['key1', 'key2', 'key3']}
        orig_d = d.copy()
        i.add(d)
        self.failUnless(d == orig_d)

        d = {'Klassy': 'key4'}
        orig_d = d.copy()
        i.add(d)
        self.failUnless(d == orig_d)

        ## test extraction of the item list of a given Container type
        _keys = ["Klassy#%s" % k for k in 'key1', 'key2', 'key3', 'key4']
        self.failUnless(i("Klassy") == _keys)
        self.failUnless(i.list("Klassy") == _keys)
        self.failUnless(i(key="Klassy") == _keys)
        self.failUnless(i.list(key="Klassy") == _keys)

        ## test dict()
        _keys = ['key1', 'key2', 'key3', 'key4']
        self.failUnless(i.dict()['Klass'] == ['key1', 'key3'])
        self.failUnless(i.dict()['Klassy'] == _keys)
        _dict = {
            'Klass': ['key1', 'key3'],
            'Klassy': ['key1', 'key2', 'key3', 'key4']
        }
        self.failUnless(i.dict() == _dict)
Exemplo n.º 6
0
    def test4Methods( self ):
        """Test various methods of CfgItemList"""
        i = CfgItemList( 'MyItems' )
        self.failUnless( i.name() == 'MyItems' )

        i.add( { 'Klass' : ['key1', 'key2'] } )
        self.failUnless( i() == [ 'Klass#key1', 'Klass#key2' ] )

        i.add( { 'Klass' : ['key1', 'key3' ] } )
        self.failUnless( i() == [ 'Klass#key1', 'Klass#key2', 'Klass#key3' ] )

        props = i.getProperties()
        self.failUnless( props.has_key( 'Klass' ) )
        self.failUnless( len(props['Klass']) == len(['key1','key2','key3']) )
        self.failUnless( 'key1' in props['Klass'] )
        self.failUnless( 'key2' in props['Klass'] )
        self.failUnless( 'key3' in props['Klass'] )

        self.failUnless( len(i.allChildren()) == 0 )

        self.failUnless(     i.has_item( 'Klass#key1' ) )
        self.failUnless(     i.has_item( 'Klass#key*' ) )
        self.failUnless( not i.has_item( 'Klass#Key1' ) )
        self.failUnless( not i.has_item( 'Klass#Key*' ) )

        i.clear()
        self.failUnless( len(i()) == 0 )
        
        i.add( { 'Klass' : ['key1', 'key2'] } )
        self.failUnless( len(i()) == 2 )
        i.remove( 'Klass' )
        self.failUnless( len(i()) == 2 )
        i.remove( 'Klass#key1' )
        self.failUnless( len(i()) == 2 )
        i.removeAll()
        self.failUnless( len(i()) == 2 )

        i.removeItem( 'Klass' )
        self.failUnless( len(i()) == 2 )
        i.removeItem( 'Klass#key1' )
        self.failUnless( len(i()) == 1 )

        _keys = ['key1', 'key2', 'key3']
        i.add( { 'Klass' : _keys } )
        self.failUnless( len(i()) == 3 )
        i.removeAllItems( 'Klass#key2' )
        self.failUnless( len(i()) == 2 )

        ## test we don't modify input dict
        d = {  'Klassy' : ['key1', 'key2', 'key3'] }
        orig_d = d.copy()
        i.add( d )
        self.failUnless( d == orig_d )

        d = {  'Klassy' : 'key4' }
        orig_d = d.copy()
        i.add( d )
        self.failUnless( d == orig_d )

        ## test extraction of the item list of a given Container type
        _keys = [ "Klassy#%s" % k for k in 'key1', 'key2', 'key3', 'key4' ]
        self.failUnless(      i(       "Klassy" ) == _keys )
        self.failUnless( i.list(       "Klassy" ) == _keys )
        self.failUnless(      i( key = "Klassy" ) == _keys )
        self.failUnless( i.list( key = "Klassy" ) == _keys )

        ## test dict()
        _keys = [ 'key1', 'key2', 'key3', 'key4' ]
        self.failUnless( i.dict()['Klass' ] == ['key1', 'key3'] )
        self.failUnless( i.dict()['Klassy'] == _keys )
        _dict = { 'Klass' : ['key1', 'key3'],
                  'Klassy': ['key1', 'key2', 'key3', 'key4']}
        self.failUnless( i.dict() == _dict )