def test_formatting_userdict():
 class mydict(object, ):
  def __getitem__(self, key):
   if (key == 'abc'):
    return 42
   elif (key == 'bar'):
    return 23
   raise KeyError, key
 AreEqual(('%(abc)s %(bar)s' % mydict()), '42 23')
 class mydict(dict, ):
  def __missing__(self, key):
   return 'ok'
 a = mydict()
 AreEqual(('%(anykey)s' % a), 'ok')

def test_formatting_userdict ( ) : class mydict ( object , ) : def __getitem__ ( self , key ) : if ( key == 'abc' ) : return 42 elif ( key == 'bar' ) : return 23 raise KeyError , key AreEqual ( ( '%(abc)s %(bar)s' % mydict ( ) ) , '42 23' ) class mydict ( dict , ) : def __missing__ ( self , key ) : return 'ok' a = mydict ( ) AreEqual ( ( '%(anykey)s' % a ) , 'ok' )
verify user mapping object works with string formatting .