コード例 #1
0
ファイル: test_log.py プロジェクト: bmihelac/celery
 def test_redirect_stdouts(self):
     logger = self.setup_logger(loglevel=logging.ERROR, logfile=None, root=False)
     try:
         with wrap_logger(logger) as sio:
             log.redirect_stdouts_to_logger(logger, loglevel=logging.ERROR)
             logger.error("foo")
             self.assertIn("foo", sio.getvalue())
     finally:
         sys.stdout, sys.stderr = sys.__stdout__, sys.__stderr__
コード例 #2
0
ファイル: test_log.py プロジェクト: yarelyc/oh-mainline
 def test_redirect_stdouts(self):
     logger = self.setup_logger(loglevel=logging.ERROR, logfile=None,
                                root=False)
     try:
         with wrap_logger(logger) as sio:
             redirect_stdouts_to_logger(logger, loglevel=logging.ERROR)
             logger.error("foo")
             self.assertIn("foo", sio.getvalue())
     finally:
         sys.stdout, sys.stderr = sys.__stdout__, sys.__stderr__
コード例 #3
0
ファイル: test_worker_job.py プロジェクト: psnj/celery
    def test_process_cleanup_fails(self):
        backend = mytask.backend
        mytask.backend = Mock()
        mytask.backend.process_cleanup = Mock(side_effect=KeyError())
        try:

            logger = mytask.app.log.get_default_logger()
            with wrap_logger(logger) as sio:
                tid = uuid()
                ret = jail(tid, mytask.name, [2], {})
                self.assertEqual(ret, 4)
                mytask.backend.store_result.assert_called_with(tid, 4, states.SUCCESS)
                logs = sio.getvalue().strip()
                self.assertIn("Process cleanup failed", logs)
        finally:
            mytask.backend = backend
コード例 #4
0
    def test_process_cleanup_fails(self):
        backend = mytask.backend
        mytask.backend = Mock()
        mytask.backend.process_cleanup = Mock(side_effect=KeyError())
        try:

            logger = mytask.app.log.get_default_logger()
            with wrap_logger(logger) as sio:
                tid = uuid()
                ret = jail(tid, mytask.name, [2], {})
                self.assertEqual(ret, 4)
                mytask.backend.mark_as_done.assert_called_with(tid, 4)
                logs = sio.getvalue().strip()
                self.assertIn("Process cleanup failed", logs)
        finally:
            mytask.backend = backend
コード例 #5
0
    def test_process_cleanup_fails(self):
        backend = mytask.backend
        mytask.backend = Mock()
        mytask.backend.process_cleanup = Mock(side_effect=KeyError())
        try:

            logger = mytask.app.log.get_default_logger()
            with wrap_logger(logger) as sio:
                uuid = gen_unique_id()
                ret = jail(uuid, mytask.name, [2], {})
                self.assertEqual(ret, 4)
                mytask.backend.mark_as_done.assert_called_with(uuid, 4)
                logs = sio.getvalue().strip()
                self.assertIn("Process cleanup failed", logs)
        finally:
            mytask.backend = backend
コード例 #6
0
ファイル: test_log.py プロジェクト: bmihelac/celery
    def test_logging_proxy(self):
        logger = self.setup_logger(loglevel=logging.ERROR, logfile=None, root=False)

        with wrap_logger(logger) as sio:
            p = LoggingProxy(logger, loglevel=logging.ERROR)
            p.close()
            p.write("foo")
            self.assertNotIn("foo", sio.getvalue())
            p.closed = False
            p.write("foo")
            self.assertIn("foo", sio.getvalue())
            lines = ["baz", "xuzzy"]
            p.writelines(lines)
            for line in lines:
                self.assertIn(line, sio.getvalue())
            p.flush()
            p.close()
            self.assertFalse(p.isatty())
            self.assertIsNone(p.fileno())
コード例 #7
0
    def test_logging_proxy(self):
        logger = self.setup_logger(loglevel=logging.ERROR, logfile=None,
                                   root=False)

        with wrap_logger(logger) as sio:
            p = LoggingProxy(logger, loglevel=logging.ERROR)
            p.close()
            p.write('foo')
            self.assertNotIn('foo', sio.getvalue())
            p.closed = False
            p.write('foo')
            self.assertIn('foo', sio.getvalue())
            lines = ['baz', 'xuzzy']
            p.writelines(lines)
            for line in lines:
                self.assertIn(line, sio.getvalue())
            p.flush()
            p.close()
            self.assertFalse(p.isatty())
コード例 #8
0
    def test_process_cleanup_fails(self):
        backend = mytask.backend
        mytask.backend = Mock()
        mytask.backend.process_cleanup = Mock(side_effect=KeyError())
        try:

            def with_wrap_logger(sio):
                uuid = gen_unique_id()
                ret = jail(uuid, mytask.name, [2], {})
                self.assertEqual(ret, 4)
                mytask.backend.mark_as_done.assert_called_with(uuid, 4)
                logs = sio.getvalue().strip()
                self.assertIn("Process cleanup failed", logs)
                return 1234

            logger = mytask.app.log.get_default_logger()
            self.assertEqual(execute_context(
                    wrap_logger(logger), with_wrap_logger), 1234)

        finally:
            mytask.backend = backend
コード例 #9
0
ファイル: test_log.py プロジェクト: bmihelac/celery
    def _assertLog(self, logger, logmsg, loglevel=logging.ERROR):

        with wrap_logger(logger, loglevel=loglevel) as sio:
            logger.log(loglevel, logmsg)
            return sio.getvalue().strip()
コード例 #10
0
    def _assertLog(self, logger, logmsg, loglevel=logging.ERROR):

        with wrap_logger(logger, loglevel=loglevel) as sio:
            logger.log(loglevel, logmsg)
            return sio.getvalue().strip()