Example #1
0
 def test_setup_logger_no_handlers_file(self):
     l = self.get_logger()
     l.handlers = []
     tempfile = mktemp(suffix='unittest', prefix='celery')
     l = self.setup_logger(logfile=tempfile, loglevel=0, root=False)
     self.assertIsInstance(get_handlers(l)[0],
                           logging.FileHandler)
Example #2
0
 def test_setup_logger_no_handlers_file(self):
     with restore_logging():
         l = self.get_logger()
         l.handlers = []
         tempfile = mktemp(suffix='unittest', prefix='celery')
         l = self.setup_logger(logfile=tempfile, loglevel=0, root=False)
         self.assertIsInstance(get_handlers(l)[0],
                               logging.FileHandler)
Example #3
0
 def test_setup_logger(self):
     logger = self.setup_logger(loglevel=logging.ERROR, logfile=None,
                                root=False, colorize=True)
     logger.handlers = []
     Logging._setup = False
     logger = self.setup_logger(loglevel=logging.ERROR, logfile=None,
                                root=False, colorize=None)
     self.assertIs(
         get_handlers(logger)[0].stream, sys.__stderr__,
         'setup_logger logs to stderr without logfile argument.',
     )
Example #4
0
 def test_setup_logger(self):
     with restore_logging():
         logger = self.setup_logger(loglevel=logging.ERROR, logfile=None,
                                    root=False, colorize=True)
         logger.handlers = []
         self.app.log.already_setup = False
         logger = self.setup_logger(loglevel=logging.ERROR, logfile=None,
                                    root=False, colorize=None)
         self.assertIs(
             get_handlers(logger)[0].stream, sys.__stderr__,
             'setup_logger logs to stderr without logfile argument.',
         )
Example #5
0
    def test_setup_logger_no_handlers_file(self, *args):
        tempfile = mktemp(suffix='unittest', prefix='celery')
        _open = ('builtins.open' if sys.version_info[0] == 3
                 else '__builtin__.open')
        with patch(_open) as osopen:
            with restore_logging():
                files = defaultdict(StringIO)

                def open_file(filename, *args, **kwargs):
                    f = files[filename]
                    f.fileno = Mock()
                    f.fileno.return_value = 99
                    return f

                osopen.side_effect = open_file
                l = self.get_logger()
                l.handlers = []
                l = self.setup_logger(
                    logfile=tempfile, loglevel=logging.INFO, root=False,
                )
                self.assertIsInstance(
                    get_handlers(l)[0], logging.FileHandler,
                )
                self.assertIn(tempfile, files)