Ejemplo n.º 1
0
 def test_setup_logger(self):
     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_logger_handlers(logger)[0].stream,
         sys.__stderr__,
         "setup_logger logs to stderr without logfile argument.",
     )
Ejemplo n.º 2
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 mock.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_logger_handlers(l)[0], logging.FileHandler)
                self.assertIn(tempfile, files)