本文整理汇总了Python中ubuntuone.devtools.handlers.MementoHandler.setLevel方法的典型用法代码示例。如果您正苦于以下问题:Python MementoHandler.setLevel方法的具体用法?Python MementoHandler.setLevel怎么用?Python MementoHandler.setLevel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ubuntuone.devtools.handlers.MementoHandler
的用法示例。
在下文中一共展示了MementoHandler.setLevel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_disconnect_with_user_locked_after_auth
# 需要导入模块: from ubuntuone.devtools.handlers import MementoHandler [as 别名]
# 或者: from ubuntuone.devtools.handlers.MementoHandler import setLevel [as 别名]
def test_disconnect_with_user_locked_after_auth(self):
"""Client gets disconnected if the user is locked after auth."""
# add the log handler
logger = logging.getLogger('storage.server')
hdlr = MementoHandler()
hdlr.setLevel(logging.INFO)
logger.addHandler(hdlr)
# define a connectionLostHandler to know when the client
# gets disconnected.
d = defer.Deferred()
def conn_lost_handler(r):
"""Connection lost!"""
d.callback(None)
@defer.inlineCallbacks
def dummy(client):
# set the connection lost handler
client.connectionLostHandler = conn_lost_handler
# trigger an operation, which should
yield client.dummy_authenticate("open sesame")
root_id = yield client.get_root()
# lock the user:
usr = self.store.get(StorageUser, 0)
usr.locked = True
self.store.commit()
client.make_dir(request.ROOT, root_id, u"open sesame")
yield d
# check we logged a warning about this.
self.assertTrue(hdlr.check_warning(
"Shutting down protocol: user locked"))
return self.callback_test(dummy, add_default_callbacks=True)
示例2: auth
# 需要导入模块: from ubuntuone.devtools.handlers import MementoHandler [as 别名]
# 或者: from ubuntuone.devtools.handlers.MementoHandler import setLevel [as 别名]
def auth(client):
yield client.dummy_authenticate('open sesame')
d = defer.Deferred()
client.connectionLostHandler = d.callback
# add the log handler
logger = logging.getLogger('storage.server')
hdlr = MementoHandler()
hdlr.setLevel(logging.INFO)
logger.addHandler(hdlr)
# patch the looping ping values
server = self.service.factory.protocols[0]
server.ping_loop.interval = 0.1
server.ping_loop.idle_timeout = 0.3
# reschedule the ping loop
server.ping_loop.reset()
try:
yield d
except ConnectionDone:
msg = "Disconnecting - idle timeout"
self.assertTrue(hdlr.check_info(msg))
else:
self.fail("Should get disconnected.")
finally:
logger.removeHandler(hdlr)
示例3: test_message
# 需要导入模块: from ubuntuone.devtools.handlers import MementoHandler [as 别名]
# 或者: from ubuntuone.devtools.handlers.MementoHandler import setLevel [as 别名]
def test_message(self):
"""Just a message."""
handler = MementoHandler()
handler.setLevel(logging.DEBUG)
deferror_handler(dict(isError=True, message="foobar"))
self.assertFalse(handler.check_error("Unhandled error in deferred",
"foobar"))
示例4: FilterTests
# 需要导入模块: from ubuntuone.devtools.handlers import MementoHandler [as 别名]
# 或者: from ubuntuone.devtools.handlers.MementoHandler import setLevel [as 别名]
class FilterTests(unittest.TestCase):
"""Tests log filters"""
@defer.inlineCallbacks
def setUp(self):
"""Setup the logger and the handler"""
yield super(FilterTests, self).setUp()
self.handler = MementoHandler()
self.handler.setLevel(logging.DEBUG)
root_logger.addHandler(self.handler)
self.addCleanup(root_logger.removeHandler, self.handler)
if filesystem_logger is not None:
filesystem_logger.addHandler(self.handler)
self.addCleanup(filesystem_logger.removeHandler, self.handler)
twisted_logger.addHandler(self.handler)
self.addCleanup(twisted_logger.removeHandler, self.handler)
self.addCleanup(self.handler.close)
@skipIfOS('win32', 'There is not filesystem_logger implementation in '\
'windows yet, see bug #823316.')
def test_multiple_filters(self):
"""Tests logging with more than one filter."""
test_logger = logging.getLogger('ubuntuone.SyncDaemon.FilterTest')
test_logger.debug('debug info 0')
self.assertEquals(1, len(self.handler.records))
self.handler.addFilter(MultiFilter(['ubuntuone.SyncDaemon', 'twisted', 'pyinotify']))
test_logger.debug('debug info 1')
self.assertEquals(2, len(self.handler.records))
示例5: SSLTestCase
# 需要导入模块: from ubuntuone.devtools.handlers import MementoHandler [as 别名]
# 或者: from ubuntuone.devtools.handlers.MementoHandler import setLevel [as 别名]
class SSLTestCase(BaseSSLTestCase):
"""Test error handling when dealing with ssl."""
@defer.inlineCallbacks
def setUp(self):
"""Set the diff tests."""
yield super(SSLTestCase, self).setUp()
self.memento = MementoHandler()
self.memento.setLevel(logging.DEBUG)
logger = webclient.webclient_module().logger
logger.addHandler(self.memento)
self.addCleanup(logger.removeHandler, self.memento)
self.wc = webclient.webclient_factory()
self.addCleanup(self.wc.shutdown)
self.called = []
def test_ssl_fail(self):
"""Test showing the dialog and rejecting."""
self.failUnlessFailure(self.wc.request(
self.base_iri + SIMPLERESOURCE), WebClientError)
self.assertNotEqual(None, self.memento.check_error('SSL errors'))
if (WEBCLIENT_MODULE_NAME.endswith(".txweb") or
WEBCLIENT_MODULE_NAME.endswith(".libsoup")):
reason = 'SSL support has not yet been implemented.'
test_ssl_fail.skip = reason
示例6: BaseEQTestCase
# 需要导入模块: from ubuntuone.devtools.handlers import MementoHandler [as 别名]
# 或者: from ubuntuone.devtools.handlers.MementoHandler import setLevel [as 别名]
class BaseEQTestCase(BaseTwistedTestCase):
""" Setup an EQ for test. """
_monitor_class = FakeMonitor
@defer.inlineCallbacks
def setUp(self):
"""Setup the test."""
yield super(BaseEQTestCase, self).setUp()
self.fsmdir = self.mktemp('fsmdir')
self.partials_dir = self.mktemp('partials_dir')
self.root_dir = self.mktemp('root_dir')
self.vm = FakeVolumeManager(self.root_dir)
self.db = tritcask.Tritcask(self.mktemp('tritcask'))
self.addCleanup(self.db.shutdown)
self.fs = filesystem_manager.FileSystemManager(self.fsmdir,
self.partials_dir,
self.vm, self.db)
self.fs.create(path=self.root_dir,
share_id='', is_dir=True)
self.fs.set_by_path(path=self.root_dir,
local_hash=None, server_hash=None)
self.eq = event_queue.EventQueue(self.fs,
monitor_class=self._monitor_class)
self.eq.listener_map = {}
self.addCleanup(self.eq.shutdown)
self.fs.register_eq(self.eq)
# add a Memento handler to the logger
self.log_handler = MementoHandler()
self.log_handler.setLevel(logging.DEBUG)
self.eq.log.addHandler(self.log_handler)
示例7: test_failure
# 需要导入模块: from ubuntuone.devtools.handlers import MementoHandler [as 别名]
# 或者: from ubuntuone.devtools.handlers.MementoHandler import setLevel [as 别名]
def test_failure(self):
"""Received a full failure."""
handler = MementoHandler()
handler.setLevel(logging.DEBUG)
f = failure.Failure(ValueError('foobar'))
deferror_handler(dict(isError=True, failure=f, message=''))
self.assertFalse(handler.check_error("Unhandled error in deferred",
"ValueError", "foobar"))
示例8: OSWrapperTests
# 需要导入模块: from ubuntuone.devtools.handlers import MementoHandler [as 别名]
# 或者: from ubuntuone.devtools.handlers.MementoHandler import setLevel [as 别名]
class OSWrapperTests(test_os_helper.OSWrapperTests):
"""Tests for os wrapper functions."""
@defer.inlineCallbacks
def setUp(self, test_dir_name=None, test_file_name=None,
valid_file_path_builder=None):
"""Set up."""
yield super(OSWrapperTests, self).setUp(
test_dir_name=test_dir_name, test_file_name=test_file_name,
valid_file_path_builder=None)
self.handler = MementoHandler()
self.handler.setLevel(logging.DEBUG)
self._logger = logging.getLogger('ubuntuone.SyncDaemon')
self._logger.addHandler(self.handler)
self.addCleanup(self._logger.removeHandler, self.handler)
self.patch(darwin.shutil, "move", self._fake_move)
def _fake_move(*args):
"""Fake shutil move."""
raise Exception("Fail fake move")
def test_stat_symlink(self):
"""Test that it doesn't follow symlinks.
We compare the inode only (enough to see if it's returning info
from the link or the linked), as we can not compare the full stat
because the st_mode will be different.
"""
link = os.path.join(self.basedir, 'foo')
os.symlink(self.testfile, link)
self.assertNotEqual(os.stat(link).st_ino, stat_path(link).st_ino)
self.assertEqual(os.lstat(link).st_ino, stat_path(link).st_ino)
def test_movetotrash_file_bad(self):
"""Something bad happen when moving to trash, removed anyway."""
path = os.path.join(self.basedir, 'foo')
open_file(path, 'w').close()
move_to_trash(path)
self.assertFalse(os.path.exists(path))
self.assertTrue(self.handler.check_warning("Problems moving to trash!",
"Removing anyway", "foo"))
def test_movetotrash_file_not_exists(self):
"""Something bad happen when moving to trash, removed anyway."""
path = os.path.join(self.basedir, 'foo2')
self.assertFalse(os.path.exists(path))
self.assertRaises(OSError, move_to_trash, path)
def test_movetotrash_dir_bad(self):
"""Something bad happen when moving to trash, removed anyway."""
path = os.path.join(self.basedir, 'foo')
os.mkdir(path)
open_file(os.path.join(path, 'file inside directory'), 'w').close()
move_to_trash(path)
self.assertFalse(os.path.exists(path))
self.assertTrue(self.handler.check_warning("Problems moving to trash!",
"Removing anyway", "foo"))
示例9: RemovableSignalTestCase
# 需要导入模块: from ubuntuone.devtools.handlers import MementoHandler [as 别名]
# 或者: from ubuntuone.devtools.handlers.MementoHandler import setLevel [as 别名]
class RemovableSignalTestCase(TestCase):
"""Tests for RemovableSignal."""
@defer.inlineCallbacks
def setUp(self):
yield super(RemovableSignalTestCase, self).setUp()
self.proxy = FakeSSOProxy()
def test_creation(self):
"""When creating, bind properly to self.proxy."""
rs = RemovableSignal(self.proxy, "test", lambda *a: None)
self.assertIs(self.proxy.test, rs)
def test_dunder_callable(self):
"""__call__ works as expected."""
sample_store = []
expected = object()
test_cb = lambda res: sample_store.append(res)
rs = RemovableSignal(self.proxy, "on_credentials_found_cb", test_cb)
rs(APP_NAME, expected)
self.assertEqual(sample_store, [expected])
def test_callable_does_not_log_args(self):
"""__call__ does not log its arguments."""
self.handler = MementoHandler()
self.handler.setLevel(logging.DEBUG)
logger.addHandler(self.handler)
self.addCleanup(logger.removeHandler, self.handler)
secret_token = "secret token!"
test_cb = lambda _: None
rs = RemovableSignal(self.proxy, "on_credentials_found_cb", test_cb)
rs(APP_NAME, {"secret": secret_token})
for record in self.handler.records:
self.assertNotIn(secret_token, record.message)
def test_dunder_filters_other_apps(self):
"""__call__ filters by app_name."""
sample_store = []
test_cb = lambda res: sample_store.append(res)
rs = RemovableSignal(self.proxy, "on_credentials_found_cb", test_cb)
rs('other app name', object())
self.assertEqual(sample_store, [])
def test_remove(self):
"""The signal has a .remove that removes the callback."""
sample_store = []
test_cb = lambda app_name, creds: sample_store.append(creds)
rs = RemovableSignal(self.proxy, "on_credentials_found_cb", test_cb)
rs.remove()
rs(TEST_APP_NAME, TEST_CREDENTIALS)
self.assertEqual(len(sample_store), 0)
示例10: GetProjectDirTestCase
# 需要导入模块: from ubuntuone.devtools.handlers import MementoHandler [as 别名]
# 或者: from ubuntuone.devtools.handlers.MementoHandler import setLevel [as 别名]
class GetProjectDirTestCase(TestCase):
"""Test case for get_project_dir when constants module is not defined."""
DIR_NAME = utils.DATA_SUFFIX
DIR_CONSTANT = 'PROJECT_DIR'
DIR_GETTER = 'get_project_dir'
@defer.inlineCallbacks
def setUp(self):
yield super(GetProjectDirTestCase, self).setUp()
self._constants = sys.modules.get(CONSTANTS_MODULE, NOT_DEFINED)
sys.modules[CONSTANTS_MODULE] = None # force ImportError
self.memento = MementoHandler()
self.memento.setLevel(logging.DEBUG)
utils.logger.addHandler(self.memento)
self.addCleanup(utils.logger.removeHandler, self.memento)
self.get_dir = getattr(utils, self.DIR_GETTER)
@defer.inlineCallbacks
def tearDown(self):
if self._constants is not NOT_DEFINED:
sys.modules[CONSTANTS_MODULE] = self._constants
else:
sys.modules.pop(CONSTANTS_MODULE)
yield super(GetProjectDirTestCase, self).tearDown()
def test_get_dir_relative(self):
"""The relative path for the data directory is correctly retrieved."""
module = utils.os.path.dirname(utils.__file__)
rel_data = utils.os.path.join(module,
utils.os.path.pardir,
utils.os.path.pardir,
self.DIR_NAME)
expected_dir = utils.os.path.abspath(rel_data)
# ensure expected_path exists at os level
self.patch(utils.os.path, 'exists', lambda path: path == expected_dir)
result = self.get_dir()
self.assertEqual(expected_dir, result)
def test_get_dir_none_exists(self):
"""No data directory exists, return None and log as error."""
self.patch(utils.os.path, 'exists', lambda path: False)
sys.modules[CONSTANTS_MODULE] = None
self.assertRaises(AssertionError, self.get_dir)
msg = 'get_dir: can not build a valid path.'
self.assertTrue(self.memento.check_error(msg))
示例11: test_gsettings_cannot_parse
# 需要导入模块: from ubuntuone.devtools.handlers import MementoHandler [as 别名]
# 或者: from ubuntuone.devtools.handlers.MementoHandler import setLevel [as 别名]
def test_gsettings_cannot_parse(self):
"""Some weird setting that cannot be parsed is logged with warning."""
memento = MementoHandler()
memento.setLevel(logging.DEBUG)
gsettings.logger.addHandler(memento)
self.addCleanup(gsettings.logger.removeHandler, memento)
troublesome_value = "#bang"
template_values = dict(BASE_GSETTINGS_VALUES)
template_values["ignore_hosts"] = troublesome_value
fake_output = TEMPLATE_GSETTINGS_OUTPUT.format(**template_values)
self.patch(gsettings.subprocess, "check_output",
lambda _: fake_output)
ps = gsettings.get_proxy_settings()
self.assertTrue(memento.check_warning(gsettings.CANNOT_PARSE_WARNING %
troublesome_value))
self.assertEqual(ps, {})
示例12: test_called_back_log_ok
# 需要导入模块: from ubuntuone.devtools.handlers import MementoHandler [as 别名]
# 或者: from ubuntuone.devtools.handlers.MementoHandler import setLevel [as 别名]
def test_called_back_log_ok(self):
"""Test that the hasher produces correct info."""
# create the hasher
mark = object()
queue = hash_queue.UniqueQueue()
d = defer.Deferred()
class Helper(object):
"""Helper class."""
def push(self, event, **kwargs):
"""Callback."""
d.callback(kwargs)
receiver = Helper()
hasher = hash_queue._Hasher(queue, mark, receiver)
# log config
handler = MementoHandler()
handler.setLevel(logging.DEBUG)
hasher.logger.addHandler(handler)
# send what to hash
testfile = os.path.join(self.test_dir, "testfile")
with open_file(testfile, "wb") as fh:
fh.write("foobar")
item = ((testfile, "mdid"), FAKE_TIMESTAMP)
queue.put(item)
# start the hasher after putting the work items
hasher.start()
# wait event and stop hasher
yield d
hasher.stop()
hasher.join(timeout=5)
# check log
log_msg = [r.message for r in handler.records
if "path hash pushed" in r.message][0]
self.assertTrue("path" in log_msg)
self.assertTrue("hash" in log_msg)
self.assertTrue("crc" in log_msg)
self.assertTrue("size" in log_msg)
self.assertTrue("st_ino" in log_msg)
self.assertTrue("st_size" in log_msg)
self.assertTrue("st_mtime" in log_msg)
hasher.logger.removeHandler(handler)
示例13: BaseTestCase
# 需要导入模块: from ubuntuone.devtools.handlers import MementoHandler [as 别名]
# 或者: from ubuntuone.devtools.handlers.MementoHandler import setLevel [as 别名]
class BaseTestCase(DBusTestCase):
"""Base test case."""
timeout = 8
app_name = APP_NAME
error_dict = None
@inlineCallbacks
def setUp(self):
yield super(BaseTestCase, self).setUp()
FakedSSOService.app_name = self.app_name
FakedSSOService.error_dict = self.error_dict
self.memento = MementoHandler()
self.memento.setLevel(logging.DEBUG)
logger.addHandler(self.memento)
self.sso_server = self.register_server(ubuntu_sso.DBUS_BUS_NAME,
ubuntu_sso.DBUS_CREDENTIALS_PATH,
FakedSSOService) # faked SSO server
self.args = {'window_id': '803'}
def register_server(self, bus_name, object_path, service_class):
"""Register a service on the session bus."""
name = self.bus.request_name(bus_name, dbus.bus.NAME_FLAG_DO_NOT_QUEUE)
self.assertNotEqual(name, dbus.bus.REQUEST_NAME_REPLY_EXISTS,
'Service %s should not be running.' % bus_name)
mock = service_class(object_path=object_path, conn=self.bus)
self.addCleanup(mock.remove_from_connection)
self.addCleanup(self.bus.release_name, bus_name)
return mock
def get_proxy(self, bus_name, object_path, dbus_interface):
obj = self.bus.get_object(bus_name=bus_name, object_path=object_path,
follow_name_owner_changes=True)
proxy = dbus.Interface(object=obj, dbus_interface=dbus_interface)
return proxy
def get_sso_proxy(self):
return self.get_proxy(bus_name=ubuntu_sso.DBUS_BUS_NAME,
object_path=ubuntu_sso.DBUS_CREDENTIALS_PATH,
dbus_interface=ubuntu_sso.DBUS_CREDENTIALS_IFACE)
示例14: test_logs
# 需要导入模块: from ubuntuone.devtools.handlers import MementoHandler [as 别名]
# 或者: from ubuntuone.devtools.handlers.MementoHandler import setLevel [as 别名]
def test_logs(self):
"""Unhandled exceptions logs in error."""
# set up logger
handler = MementoHandler()
handler.setLevel(logging.DEBUG)
l = logging.getLogger('magicicada')
# call
l.addHandler(handler)
self.addCleanup(l.removeHandler, handler)
exc = self._get_exception_data()
try:
exception_handler(*exc)
finally:
l.removeHandler(handler)
# check
self.assertTrue(handler.check_error("Unhandled exception",
"ZeroDivisionError"))
示例15: BaseFSMonitorTestCase
# 需要导入模块: from ubuntuone.devtools.handlers import MementoHandler [as 别名]
# 或者: from ubuntuone.devtools.handlers.MementoHandler import setLevel [as 别名]
class BaseFSMonitorTestCase(testcase.BaseTwistedTestCase):
"""Test the structures where we have the path/watch."""
timeout = 3
@defer.inlineCallbacks
def setUp(self):
"""Set up."""
yield super(BaseFSMonitorTestCase, self).setUp()
fsmdir = self.mktemp('fsmdir')
partials_dir = self.mktemp('partials_dir')
self.root_dir = self.mktemp('root_dir')
self.vm = testcase.FakeVolumeManager(self.root_dir)
self.tritcask_dir = self.mktemp("tritcask_dir")
self.db = Tritcask(self.tritcask_dir)
self.fs = filesystem_manager.FileSystemManager(fsmdir, partials_dir,
self.vm, self.db)
self.fs.create(path=self.root_dir, share_id='', is_dir=True)
self.fs.set_by_path(path=self.root_dir,
local_hash=None, server_hash=None)
eq = event_queue.EventQueue(self.fs)
self.deferred = deferred = defer.Deferred()
class HitMe(object):
# class-closure, cannot use self, pylint: disable-msg=E0213
def handle_default(innerself, event, **args):
deferred.callback(True)
eq.subscribe(HitMe())
self.monitor = eq.monitor
self.log_handler = MementoHandler()
self.log_handler.setLevel(logging.DEBUG)
self.monitor.log.addHandler(self.log_handler)
@defer.inlineCallbacks
def tearDown(self):
"""Clean up the tests."""
self.monitor.shutdown()
self.monitor.log.removeHandler(self.log_handler)
yield super(BaseFSMonitorTestCase, self).tearDown()