本文整理汇总了Python中ubuntuone.devtools.handlers.MementoHandler.close方法的典型用法代码示例。如果您正苦于以下问题:Python MementoHandler.close方法的具体用法?Python MementoHandler.close怎么用?Python MementoHandler.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ubuntuone.devtools.handlers.MementoHandler
的用法示例。
在下文中一共展示了MementoHandler.close方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MultiFilterTest
# 需要导入模块: from ubuntuone.devtools.handlers import MementoHandler [as 别名]
# 或者: from ubuntuone.devtools.handlers.MementoHandler import close [as 别名]
class MultiFilterTest(unittest.TestCase):
"""Tests for logger.MultiFilter"""
@defer.inlineCallbacks
def setUp(self):
"""Setup the logger and the handler"""
yield super(MultiFilterTest, self).setUp()
self.handler = MementoHandler()
self.logger = logging.getLogger(self.__class__.__name__)
self.logger.addHandler(self.handler)
self.logger.setLevel(logging.DEBUG)
@defer.inlineCallbacks
def tearDown(self):
"""close the handler and restore the logger (Logger's are global)"""
yield super(MultiFilterTest, self).tearDown()
self.handler.close()
self.logger.removeHandler(self.handler)
self.logger.setLevel(logging.DEBUG)
def test_no_filters(self):
"""Tests filtering without any filter in self.filters."""
self.handler.addFilter(MultiFilter())
self.logger.debug('this msg should be logged')
self.assertEqual(1, len(self.handler.records))
def test_single_filter(self):
"""Tests filtering with one filter."""
self.handler.addFilter(MultiFilter([self.__class__.__name__]))
self.logger.debug('this msg should be logged')
self.assertEqual(1, len(self.handler.records))
other_logger = logging.getLogger("NO_LOG."+self.__class__.__name__)
other_logger.debug('this msg shouldn\'t be logged')
self.assertEqual(1, len(self.handler.records))
def test_multiple_filters(self):
"""Tests filtering with more than one filter."""
self.handler.addFilter(
MultiFilter([self.__class__.__name__,
self.__class__.__name__ + ".child"]))
no_logger = logging.getLogger("NO_LOG."+self.__class__.__name__)
yes_logger = logging.getLogger(self.__class__.__name__ + '.child')
self.logger.debug('this msg should be logged')
self.assertEqual(1, len(self.handler.records))
no_logger.debug('this msg shouldn\'t be logged')
self.assertEqual(1, len(self.handler.records))
yes_logger.debug('this msg from a child logger should be logged')
self.assertEqual(2, len(self.handler.records))
示例2: DebugCaptureTest
# 需要导入模块: from ubuntuone.devtools.handlers import MementoHandler [as 别名]
# 或者: from ubuntuone.devtools.handlers.MementoHandler import close [as 别名]
class DebugCaptureTest(unittest.TestCase):
"""Tests for DebugCapture context manager."""
@defer.inlineCallbacks
def setUp(self):
"""Setup the logger and the handler"""
yield super(DebugCaptureTest, self).setUp()
self.handler = MementoHandler()
self.logger = logging.getLogger(self.__class__.__name__)
self.logger.addHandler(self.handler)
self.logger.setLevel(logging.DEBUG)
@defer.inlineCallbacks
def tearDown(self):
"""close the handler and restore the logger (Logger's are global)"""
yield super(DebugCaptureTest, self).tearDown()
self.handler.close()
self.logger.removeHandler(self.handler)
self.logger.setLevel(logging.DEBUG)
def test_capture_in_debug_or_lower(self):
"""Test simple capture with the logger in DEBUG level"""
self.logger.debug('a message')
self.assertEquals(1, len(self.handler.records))
self.handler.records = []
self.logger.setLevel(TRACE)
with DebugCapture(self.logger) as dc:
self.logger.debug('a message that should never reach the handler')
self.assertEquals(0, len(dc.records))
messages = [r.getMessage() for r in self.handler.records]
self.assertEquals(1, len(self.handler.records), messages)
self.handler.records = []
with DebugCapture(self.logger) as dc:
self.logger.debug('a message that should never reach the handler')
self.logger.warning('a warning')
self.logger.debug('another debug message')
self.assertEquals(0, len(dc.records))
messages = [r.getMessage() for r in self.handler.records]
self.assertEquals(3, len(self.handler.records), messages)
self.handler.records = []
with DebugCapture(self.logger) as dc:
self.logger.debug('a message that should never reach the handler')
self.logger.info('a info message')
self.logger.debug('another debug message')
self.assertEquals(0, len(dc.records))
messages = [r.getMessage() for r in self.handler.records]
self.assertEquals(3, len(self.handler.records), messages)
def test_capture_non_debug_levels(self):
"""Test debug log capture in levels > DEBUG"""
levels = [logging.INFO, logging.ERROR,
NOTE, logging.CRITICAL]
for level in levels:
self.logger.setLevel(level)
self._test_capture()
self.logger.setLevel(logging.DEBUG)
self.handler.records = []
def _test_capture(self):
"""Tests for simple debug capture in INFO level"""
self.logger.debug('a message')
self.assertEquals(0, len(self.handler.records))
self.handler.records = []
with DebugCapture(self.logger) as dc:
self.logger.debug('a message that should never reach the handler')
self.assertEquals(1, len(dc.records))
messages = [r.getMessage() for r in self.handler.records]
self.assertEquals(0, len(self.handler.records), messages)
self.handler.records = []
with DebugCapture(self.logger) as dc:
self.logger.debug('a message that should never reach the handler')
self.logger.warning('a warning')
self.logger.debug('another debug message')
self.assertEquals(2, len(dc.records))
messages = [r.getMessage() for r in self.handler.records]
self.assertEquals(1, len(self.handler.records), messages)
self.handler.records = []
with DebugCapture(self.logger) as dc:
self.logger.debug('a message that should never reach the handler')
self.logger.info('a info message')
self.logger.debug('another debug message')
self.assertEquals(2, len(dc.records))
messages = [r.getMessage() for r in self.handler.records]
self.assertEquals(1, len(self.handler.records), messages)
def test_dump_on_unhandled_error(self):
"""Test that all captured debug info is dumped on a unhandled error and
the error itself is logged too
"""
self.logger.setLevel(logging.INFO)
with DebugCapture(self.logger) as dc:
self.logger.debug('a message that should go to the handler 1')
self.assertEquals(1, len(dc.records))
raise Exception('Expected exception!')
#.........这里部分代码省略.........
示例3: HeartbeatListenerTestCase
# 需要导入模块: from ubuntuone.devtools.handlers import MementoHandler [as 别名]
# 或者: from ubuntuone.devtools.handlers.MementoHandler import close [as 别名]
class HeartbeatListenerTestCase(TestCase):
"""Tests for HeartbeatListener class."""
def setUp(self):
super(HeartbeatListenerTestCase, self).setUp()
self.stdin = StringIO()
self.stdout = StringIO()
self.stderr = StringIO()
self.mocker = Mocker()
self.rpc = self.mocker.mock()
self.listener = HeartbeatListener(1, 10, ['foo'], [], self.rpc,
stdin=self.stdin, stdout=self.stdout,
stderr=self.stderr)
self.next_fail = {}
self.handler = MementoHandler()
self.listener.logger.addHandler(self.handler)
self.listener.logger.setLevel(logging.DEBUG)
self.handler.setLevel(logging.DEBUG)
self.listener.logger.propagate = False
self.processes = [dict(name="heartbeat", group="heartbeat", pid="101",
state=RUNNING)]
self.handler.debug = True
def tearDown(self):
self.listener.logger.removeHandler(self.handler)
self.handler.close()
self.next_fail = None
self.handler = None
self.listener = None
super(HeartbeatListenerTestCase, self).tearDown()
def fail_next_stop(self, pname):
"""Make next stopProcess to fail."""
expect(self.rpc.supervisor.stopProcess(pname)).throw(
xmlrpclib.Fault(42, "Failed to stop the process."))
def fail_next_start(self, pname):
"""Make next startProcess to fail."""
expect(self.rpc.supervisor.startProcess(pname)).throw(
xmlrpclib.Fault(42, "Failed to start the process."))
def test_restart(self):
"""Test the restart method."""
expect(self.rpc.supervisor.stopProcess("foo"))
expect(self.rpc.supervisor.startProcess("foo"))
with self.mocker:
self.listener.restart("foo", "testing")
self.assertTrue(self.handler.check_info("Restarting foo (last "
"hearbeat: testing)"))
def test_restart_fail_stop(self):
"""Test the restart method failing to stop the process."""
self.fail_next_stop("foo")
last = time.time()
with self.mocker:
try:
self.listener.restart("foo", last)
except xmlrpclib.Fault:
msg = ("Failed to stop process %s (last heartbeat: %s), "
"exiting: %s") % \
("foo", last, "<Fault 42: 'Failed to stop the process.'>")
self.assertTrue(self.handler.check_error(msg))
else:
self.fail("Should get an xmlrpclib.Fault")
def test_restart_fail_start(self):
"""Test the restart method failing to start the process."""
expect(self.rpc.supervisor.stopProcess("foo"))
self.fail_next_start("foo")
last = time.time()
with self.mocker:
try:
self.listener.restart("foo", last)
except xmlrpclib.Fault:
msg = (
'Failed to start process %s after stopping it, exiting: %s'
) % ("foo", "<Fault 42: 'Failed to start the process.'>")
self.assertTrue(self.handler.check_error(msg))
else:
self.fail("Should get an xmlrpclib.Fault")
def test_check_processes(self):
"""Test the check_processes method."""
# add the fake process to the process list
self.processes.append(dict(name="foo", group="foo", pid="42",
state=RUNNING))
self.processes.append(dict(name="bar", group="bar", pid="43",
state=RUNNING))
self.listener.processes = ['bar']
# 2 process to restart
self.listener.data['foo'] = {
'time': time.time() - (self.listener.timeout + 2)}
self.listener.data['bar'] = {
'time': time.time() - (self.listener.timeout + 3)}
self.listener.data['p-1'] = {
'time': time.time() - (self.listener.timeout - 1)}
expect(self.rpc.supervisor.getAllProcessInfo()).result(self.processes)
expect(self.rpc.supervisor.stopProcess("foo:"))
expect(self.rpc.supervisor.startProcess("foo:"))
expect(self.rpc.supervisor.stopProcess("bar:bar"))
#.........这里部分代码省略.........