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_*"])
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_*"] )
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)
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 )