本文整理汇总了Python中ubuntuone.devtools.handlers.MementoHandler.check_exception方法的典型用法代码示例。如果您正苦于以下问题:Python MementoHandler.check_exception方法的具体用法?Python MementoHandler.check_exception怎么用?Python MementoHandler.check_exception使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ubuntuone.devtools.handlers.MementoHandler
的用法示例。
在下文中一共展示了MementoHandler.check_exception方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LogginTestCase
# 需要导入模块: from ubuntuone.devtools.handlers import MementoHandler [as 别名]
# 或者: from ubuntuone.devtools.handlers.MementoHandler import check_exception [as 别名]
class LogginTestCase(BaseTestCase):
"""Ensure that proper debug logging is done."""
@defer.inlineCallbacks
def setUp(self):
"""Initialize this testcase."""
yield super(LogginTestCase, self).setUp()
self.memento = MementoHandler()
restful.logger.addHandler(self.memento)
restful.logger.setLevel(logging.DEBUG)
self.addCleanup(restful.logger.removeHandler, self.memento)
self.rc = restful.RestfulClient(SAMPLE_SERVICE_IRI)
self.addCleanup(self.rc.shutdown)
@defer.inlineCallbacks
def test_log_rest_call(self):
"""Check that proper DEBUG is made for every REST call."""
yield self.rc.restcall(SAMPLE_OPERATION, **SAMPLE_ARGS)
expected_msgs = (
SAMPLE_SERVICE_IRI + SAMPLE_NAMESPACE,
)
self.assertTrue(self.memento.check_debug(*expected_msgs))
@defer.inlineCallbacks
def test_log_json_loads_exception(self):
"""Check that json load errors are properly logged."""
invalid_json = 'NOTAVALIDJSON'
self.patch(self.wc, 'return_value', invalid_json)
yield self.assertFailure(self.rc.restcall(SAMPLE_OPERATION),
ValueError)
self.memento.debug = True
expected_msgs = (
ValueError,
'Can not load json from REST request response',
invalid_json
)
self.assertTrue(self.memento.check_exception(*expected_msgs))
示例2: OffloadQueueTestCase
# 需要导入模块: from ubuntuone.devtools.handlers import MementoHandler [as 别名]
# 或者: from ubuntuone.devtools.handlers.MementoHandler import check_exception [as 别名]
#.........这里部分代码省略.........
results.append(self.oq.pop())
# push the rest of the data, it should rotate at some point
for d in data[1:]:
self.oq.push(d)
assert self.oq._tempfile != orig_temp
# pop everything and compare
while len(self.oq):
results.append(self.oq.pop())
self.assertEqual(data, results)
def test_rotate_removes_old_file(self):
"""Rotation should start a new file and remove the previous one."""
data, item_size = self._get_data()
self.oq._rotation_soft_limit = item_size * 2.5
orig_fname = self.oq._tempfile_name
self.oq.push(data)
self.oq.pop()
self.oq.push(data)
self.oq.push(data)
self.assertFalse(os.path.exists(orig_fname))
def test_log_init_tempfile(self):
"""Log the initial temp file used."""
self.assertTrue(self.handler.check_debug("Using temporary file", repr(self.oq._tempfile_name)))
def test_log_rotate(self):
"""Log new file in rotation."""
data, item_size = self._get_data()
self.oq._rotation_soft_limit = item_size * 2.5
self.oq.push(data)
self.oq.pop()
self.oq.push(data)
self.oq.push(data)
self.assertTrue(self.handler.check_debug("Rotation into", "moving", repr(self.oq._tempfile_name)))
def test_safe_rotate_crash(self):
"""All is ok even after rotation crashes when getting temp file."""
def crash(*a):
"""Will crash."""
raise NameError("ugly")
self.patch(tempfile, "mkstemp", crash)
# do a lot of things, rotating in the middle, checking all is ok
self.test_rotate_keep_working()
self.assertTrue(self.handler.check_exception(NameError))
self.assertTrue(self.oq._in_memory)
def test_safe_rotate_unlink(self):
"""All is ok after failing to unlink old file."""
def crash(*a):
"""Will crash."""
raise NameError("ugly")
self.patch(os, "unlink", crash)
# do a lot of things, rotating in the middle, checking all is ok
self.test_rotate_keep_working()
self.assertTrue(self.handler.check_warning("Error when removing old tempfile", "NameError"))
def _test_safe_push_write(self, count):
"""Fail when pushing an item will leave it all ok."""
class CrashingFile(StringIO.StringIO):
"""File-like object that crashes in second write."""
def __init__(self):
self._fail_counter = 0
StringIO.StringIO.__init__(self)
def write(self, *a):
"""Crashing write."""
self._fail_counter += 1
if self._fail_counter == count:
raise ValueError("broken")
else:
StringIO.StringIO.write(self, *a)
self.oq._tempfile = CrashingFile()
# will try three items, checking all is ok
self.test_fifo_mixed()
self.assertTrue(self.handler.check_exception(ValueError))
self.assertTrue(self.oq._in_memory)
def test_safe_push_write_first(self):
"""Fail when pushing an item, on first write."""
self._test_safe_push_write(1)
def test_safe_push_write_second(self):
"""Fail when pushing an item, on second write."""
self._test_safe_push_write(2)