<s> from twisted . trial . unittest import TestCase <EOL> from twisted . python . failure import Failure <EOL> try : <EOL> import syslog as stdsyslog <EOL> except ImportError : <EOL> stdsyslog = None <EOL> else : <EOL> from twisted . python import syslog <EOL> class SyslogObserverTests ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> events = None <EOL> if stdsyslog is None : <EOL> skip = "<STR_LIT>" <EOL> def setUp ( self ) : <EOL> self . patch ( syslog . SyslogObserver , '<STR_LIT>' , self . openlog ) <EOL> self . patch ( syslog . SyslogObserver , '<STR_LIT>' , self . syslog ) <EOL> self . observer = syslog . SyslogObserver ( '<STR_LIT>' ) <EOL> def openlog ( self , prefix , options , facility ) : <EOL> self . logOpened = ( prefix , options , facility ) <EOL> self . events = [ ] <EOL> def syslog ( self , options , message ) : <EOL> self . events . append ( ( options , message ) ) <EOL> def test_emitWithoutMessage ( self ) : <EOL> """<STR_LIT>""" <EOL> self . observer . emit ( { '<STR_LIT:message>' : ( ) , '<STR_LIT>' : False , '<STR_LIT>' : '<STR_LIT:->' } ) <EOL> self . assertEqual ( self . events , [ ] ) <EOL> def test_emitCustomPriority ( self ) : <EOL> """<STR_LIT>""" <EOL> self . observer . emit ( { <EOL> '<STR_LIT:message>' : ( '<STR_LIT>' , ) , '<STR_LIT>' : False , '<STR_LIT>' : '<STR_LIT:->' , <EOL> '<STR_LIT>' : stdsyslog . LOG_DEBUG } ) <EOL> self . assertEqual ( <EOL> self . events , <EOL> [ ( stdsyslog . LOG_DEBUG , '<STR_LIT>' ) ] ) <EOL> def test_emitErrorPriority ( self ) : <EOL> """<STR_LIT>""" <EOL> self . observer . emit ( { <EOL> '<STR_LIT:message>' : ( '<STR_LIT>' , ) , '<STR_LIT>' : True , '<STR_LIT>' : '<STR_LIT:->' , <EOL> '<STR_LIT>' : Failure ( Exception ( "<STR_LIT:foo>" ) ) } ) <EOL> self . assertEqual ( <EOL> self . events , <EOL> [ ( stdsyslog . LOG_ALERT , '<STR_LIT>' ) ] ) <EOL> def test_emitCustomPriorityOverridesError ( self ) : <EOL> """<STR_LIT>""" <EOL> self . observer . emit ( { <EOL> '<STR_LIT:message>' : ( '<STR_LIT>' , ) , '<STR_LIT>' : True , '<STR_LIT>' : '<STR_LIT:->' , <EOL> '<STR_LIT>' : stdsyslog . LOG_NOTICE , <EOL> '<STR_LIT>' : Failure ( Exception ( "<STR_LIT:bar>" ) ) } ) <EOL> self . assertEqual ( <EOL> self . events , <EOL> [ ( stdsyslog . LOG_NOTICE , '<STR_LIT>' ) ] ) <EOL> def test_emitCustomFacility ( self ) : <EOL> """<STR_LIT>""" <EOL> self . observer . emit ( { <EOL> '<STR_LIT:message>' : ( '<STR_LIT>' , ) , '<STR_LIT>' : False , '<STR_LIT>' : '<STR_LIT:->' , <EOL> '<STR_LIT>' : stdsyslog . LOG_CRON } ) <EOL> self . assertEqual ( <EOL> self . events , <EOL> [ ( stdsyslog . LOG_INFO | stdsyslog . LOG_CRON , '<STR_LIT>' ) ] ) <EOL> def test_emitCustomSystem ( self ) : <EOL> """<STR_LIT>""" <EOL> self . observer . emit ( { '<STR_LIT:message>' : ( '<STR_LIT>' , ) , '<STR_LIT>' : False , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( <EOL> self . events , <EOL> [ ( stdsyslog . LOG_INFO , "<STR_LIT>" ) ] ) <EOL> def test_emitMessage ( self ) : <EOL> """<STR_LIT>""" <EOL> self . observer . emit ( { <EOL> '<STR_LIT:message>' : ( '<STR_LIT>' , ) , '<STR_LIT>' : False , <EOL> '<STR_LIT>' : '<STR_LIT:->' } ) <EOL> self . assertEqual ( <EOL> self . events , <EOL> [ ( stdsyslog . LOG_INFO , "<STR_LIT>" ) ] ) <EOL> def test_emitMultilineMessage ( self ) : <EOL> """<STR_LIT>""" <EOL> self . observer . emit ( { <EOL> '<STR_LIT:message>' : ( '<STR_LIT>' , ) , '<STR_LIT>' : False , <EOL> '<STR_LIT>' : '<STR_LIT:->' } ) <EOL> self . assertEqual ( <EOL> self . events , <EOL> [ ( stdsyslog . LOG_INFO , '<STR_LIT>' ) , <EOL> ( stdsyslog . LOG_INFO , '<STR_LIT>' ) ] ) <EOL> def test_emitStripsTrailingEmptyLines ( self ) : <EOL> """<STR_LIT>""" <EOL> self . observer . emit ( { <EOL> '<STR_LIT:message>' : ( '<STR_LIT>' , ) , '<STR_LIT>' : False , <EOL> '<STR_LIT>' : '<STR_LIT:->' } ) <EOL> self . assertEqual ( <EOL> self . events , <EOL> [ ( stdsyslog . LOG_INFO , '<STR_LIT>' ) , <EOL> ( stdsyslog . LOG_INFO , '<STR_LIT>' ) ] ) </s>
