<s> from twisted . trial import unittest <EOL> from twisted . python import log as twisted_log <EOL> from twisted . internet import defer <EOL> import comet . log as log <EOL> from comet . testutils import DummyLogObserver <EOL> DUMMY_MESSAGE = "<STR_LIT>" <EOL> class test_comet_logging ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . observer = DummyLogObserver ( ) <EOL> twisted_log . addObserver ( self . observer ) <EOL> def tearDown ( self ) : <EOL> twisted_log . removeObserver ( self . observer ) <EOL> def _check_log_full ( self , cb ) : <EOL> self . assertTrue ( self . observer . messages ) <EOL> def _check_log_empty ( self , cb ) : <EOL> self . assertFalse ( self . observer . messages ) <EOL> def test_log_debug_level_debug ( self ) : <EOL> log . LEVEL = log . Levels . DEBUG <EOL> self . assertFalse ( self . observer . messages ) <EOL> d = log . debug ( DUMMY_MESSAGE ) <EOL> self . assertIsInstance ( d , defer . Deferred ) <EOL> return d . addCallback ( self . _check_log_full ) <EOL> def test_log_debug_level_info ( self ) : <EOL> log . LEVEL = log . Levels . INFO <EOL> self . assertFalse ( self . observer . messages ) <EOL> d = log . debug ( DUMMY_MESSAGE ) <EOL> self . assertIsInstance ( d , defer . Deferred ) <EOL> return d . addCallback ( self . _check_log_empty ) <EOL> def test_log_debug_level_warning ( self ) : <EOL> log . LEVEL = log . Levels . WARNING <EOL> self . assertFalse ( self . observer . messages ) <EOL> d = log . debug ( DUMMY_MESSAGE ) <EOL> self . assertIsInstance ( d , defer . Deferred ) <EOL> return d . addCallback ( self . _check_log_empty ) <EOL> def test_log_info_level_debug ( self ) : <EOL> log . LEVEL = log . Levels . DEBUG <EOL> self . assertFalse ( self . observer . messages ) <EOL> d = log . info ( DUMMY_MESSAGE ) <EOL> self . assertIsInstance ( d , defer . Deferred ) <EOL> return d . addCallback ( self . _check_log_full ) <EOL> def test_log_info_level_info ( self ) : <EOL> log . LEVEL = log . Levels . INFO <EOL> self . assertFalse ( self . observer . messages ) <EOL> d = log . info ( DUMMY_MESSAGE ) <EOL> self . assertIsInstance ( d , defer . Deferred ) <EOL> return d . addCallback ( self . _check_log_full ) <EOL> def test_log_info_level_warning ( self ) : <EOL> log . LEVEL = log . Levels . WARNING <EOL> self . assertFalse ( self . observer . messages ) <EOL> d = log . info ( DUMMY_MESSAGE ) <EOL> self . assertIsInstance ( d , defer . Deferred ) <EOL> return d . addCallback ( self . _check_log_empty ) <EOL> def test_log_warning_level_debug ( self ) : <EOL> log . LEVEL = log . Levels . DEBUG <EOL> self . assertFalse ( self . observer . messages ) <EOL> d = log . warn ( DUMMY_MESSAGE ) <EOL> self . assertTrue ( self . observer . messages ) <EOL> return d . addCallback ( self . _check_log_full ) <EOL> def test_log_warning_level_info ( self ) : <EOL> log . LEVEL = log . Levels . INFO <EOL> self . assertFalse ( self . observer . messages ) <EOL> d = log . warn ( DUMMY_MESSAGE ) <EOL> self . assertTrue ( self . observer . messages ) <EOL> return d . addCallback ( self . _check_log_full ) <EOL> def test_log_warning_level_warning ( self ) : <EOL> log . LEVEL = log . Levels . WARNING <EOL> self . assertFalse ( self . observer . messages ) <EOL> d = log . warn ( DUMMY_MESSAGE ) <EOL> self . assertTrue ( self . observer . messages ) <EOL> return d . addCallback ( self . _check_log_full ) <EOL> def test_default_level ( self ) : <EOL> self . assertEqual ( log . DEFAULT_LEVEL , log . Levels . INFO ) </s>
