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__
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__
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
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
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
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())
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())
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
def _assertLog(self, logger, logmsg, loglevel=logging.ERROR): with wrap_logger(logger, loglevel=loglevel) as sio: logger.log(loglevel, logmsg) return sio.getvalue().strip()