本文整理汇总了Python中ubuntuone.devtools.handlers.MementoHandler类的典型用法代码示例。如果您正苦于以下问题:Python MementoHandler类的具体用法?Python MementoHandler怎么用?Python MementoHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MementoHandler类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_disconnect_with_user_locked_after_auth
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)
开发者ID:CSRedRat,项目名称:magicicada-server,代码行数:32,代码来源:test_basic.py
示例2: BaseEQTestCase
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)
开发者ID:CSRedRat,项目名称:magicicada-client,代码行数:32,代码来源:test_eventqueue.py
示例3: SSLTestCase
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
开发者ID:magicicada-bot,项目名称:magicicada-client,代码行数:29,代码来源:test_webclient.py
示例4: test_message
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"))
开发者ID:CSRedRat,项目名称:magicicada-gui,代码行数:7,代码来源:test_logger.py
示例5: FilterTests
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))
开发者ID:CSRedRat,项目名称:magicicada-client,代码行数:31,代码来源:test_logger.py
示例6: auth
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)
开发者ID:CSRedRat,项目名称:magicicada-server,代码行数:25,代码来源:test_basic.py
示例7: test_failure
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"))
开发者ID:CSRedRat,项目名称:magicicada-gui,代码行数:8,代码来源:test_logger.py
示例8: OSWrapperTests
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"))
开发者ID:magicicada-bot,项目名称:magicicada-client,代码行数:57,代码来源:test_darwin.py
示例9: RemovableSignalTestCase
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)
开发者ID:CSRedRat,项目名称:magicicada-client,代码行数:53,代码来源:test_ipc_service.py
示例10: GetProjectDirTestCase
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))
开发者ID:magicicada-bot,项目名称:magicicada-client,代码行数:51,代码来源:test_common.py
示例11: test_logger_can_be_given
def test_logger_can_be_given(self):
"""Accept an external logger."""
logger = logging.getLogger("ubuntuone.SyncDaemon.Test")
handler = MementoHandler()
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)
logger.propagate = False
# acquire and test
release = yield self.plt.acquire('path', logger=logger)
self.assertTrue(handler.check_debug("acquiring on"))
# release and test
release()
self.assertTrue(handler.check_debug("releasing"))
开发者ID:magicicada-bot,项目名称:magicicada-client,代码行数:15,代码来源:test_pathlockingtree.py
示例12: setUp
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 = FakeVolumeManager(self.root_dir)
self.tritcask_dir = self.mktemp("tritcask_dir")
self.db = Tritcask(self.tritcask_dir)
self.addCleanup(self.db.shutdown)
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.addCleanup(self.monitor.shutdown)
self.log_handler = MementoHandler()
self.log_handler.setLevel(logging.DEBUG)
self.monitor.log.addHandler(self.log_handler)
self.addCleanup(self.monitor.log.removeHandler, self.log_handler)
开发者ID:CSRedRat,项目名称:magicicada-client,代码行数:31,代码来源:test_filesystem_notifications.py
示例13: setUp
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)
开发者ID:CSRedRat,项目名称:magicicada-client,代码行数:7,代码来源:test_logger.py
示例14: setUp
def setUp(self):
"""Set up."""
yield super(OSWrapperTests, self).setUp()
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)
开发者ID:CSRedRat,项目名称:magicicada-client,代码行数:8,代码来源:test_linux.py
示例15: test_gsettings_cannot_parse
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, {})
开发者ID:magicicada-bot,项目名称:magicicada-client,代码行数:17,代码来源:test_gsettings.py
示例16: test_called_back_log_ok
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)
开发者ID:CSRedRat,项目名称:magicicada-client,代码行数:45,代码来源:test_hashqueue.py
示例17: setUp
def setUp(self):
yield super(ClientDummyAuthTests, self).setUp()
self.creds = "open sesame"
self.bad_creds = "not my secret"
self.handler = MementoHandler()
logger = logging.getLogger("storage.server")
logger.addHandler(self.handler)
self.addCleanup(logger.removeHandler, self.handler)
self.handler.setLevel(logging.DEBUG)
开发者ID:CSRedRat,项目名称:magicicada-server,代码行数:9,代码来源:test_auth.py
示例18: setUp
def setUp(self):
"""Set up the test."""
self.qc = QueueContent(home='/')
self.handler = MementoHandler()
self.handler.setLevel(logging.DEBUG)
logger = logging.getLogger('magicicada.queue_content')
logger.addHandler(self.handler)
logger.setLevel(logging.DEBUG)
self.addCleanup(logger.removeHandler, self.handler)
开发者ID:CSRedRat,项目名称:magicicada-gui,代码行数:9,代码来源:test_queue_content.py
示例19: setUp
def setUp(self):
yield super(HeartbeatWriterTest, self).setUp()
self.logger = logging.Logger("HeartbeatWriter.test")
self.handler = MementoHandler()
self.logger.addHandler(self.handler)
self.addCleanup(self.logger.removeHandler, self.handler)
self.clock = task.Clock()
self.hw = HeartbeatWriter(self.interval, self.logger,
reactor=self.clock)
开发者ID:CSRedRat,项目名称:magicicada-server,代码行数:9,代码来源:test_utils.py
示例20: setUp
def setUp(self):
yield super(SignalBroadcasterTestCase, self).setUp()
self.client = FakeRemoteClient()
self.sb = ipc.SignalBroadcaster()
self.memento = MementoHandler()
ipc.logger.addHandler(self.memento)
ipc.logger.setLevel(logging.DEBUG)
self.addCleanup(ipc.logger.removeHandler, self.memento)
开发者ID:magicicada-bot,项目名称:magicicada-client,代码行数:9,代码来源:test_ipc.py
注:本文中的ubuntuone.devtools.handlers.MementoHandler类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论