<s> from openid import message <EOL> from logging . handlers import BufferingHandler <EOL> import logging <EOL> class TestHandler ( BufferingHandler ) : <EOL> def __init__ ( self , messages ) : <EOL> BufferingHandler . __init__ ( self , <NUM_LIT:0> ) <EOL> self . messages = messages <EOL> def shouldFlush ( self ) : <EOL> return False <EOL> def emit ( self , record ) : <EOL> self . messages . append ( record . __dict__ ) <EOL> class OpenIDTestMixin ( object ) : <EOL> def failUnlessOpenIDValueEquals ( self , msg , key , expected , ns = None ) : <EOL> if ns is None : <EOL> ns = message . OPENID_NS <EOL> actual = msg . getArg ( ns , key ) <EOL> error_format = '<STR_LIT>' <EOL> error_message = error_format % ( key , expected , actual ) <EOL> self . assertEqual ( expected , actual , error_message ) <EOL> def failIfOpenIDKeyExists ( self , msg , key , ns = None ) : <EOL> if ns is None : <EOL> ns = message . OPENID_NS <EOL> actual = msg . getArg ( ns , key ) <EOL> error_message = '<STR_LIT>' % ( key , actual ) <EOL> self . assertFalse ( actual is not None , error_message ) <EOL> class CatchLogs ( object ) : <EOL> def setUp ( self ) : <EOL> self . messages = [ ] <EOL> root_logger = logging . getLogger ( ) <EOL> self . old_log_level = root_logger . getEffectiveLevel ( ) <EOL> root_logger . setLevel ( logging . DEBUG ) <EOL> self . handler = TestHandler ( self . messages ) <EOL> formatter = logging . Formatter ( "<STR_LIT>" ) <EOL> self . handler . setFormatter ( formatter ) <EOL> root_logger . addHandler ( self . handler ) <EOL> def tearDown ( self ) : <EOL> root_logger = logging . getLogger ( ) <EOL> root_logger . removeHandler ( self . handler ) <EOL> root_logger . setLevel ( self . old_log_level ) <EOL> def failUnlessLogMatches ( self , * prefixes ) : <EOL> """<STR_LIT>""" <EOL> messages = [ r [ '<STR_LIT>' ] for r in self . messages ] <EOL> assert len ( prefixes ) == len ( messages ) , "<STR_LIT>" % ( prefixes , <EOL> messages ) <EOL> for prefix , message in zip ( prefixes , messages ) : <EOL> assert message . startswith ( prefix ) , "<STR_LIT>" % ( prefixes , <EOL> messages ) <EOL> def failUnlessLogEmpty ( self ) : <EOL> self . failUnlessLogMatches ( ) </s>
