本文整理汇总了Python中neubot.notify.NOTIFIER.is_subscribed方法的典型用法代码示例。如果您正苦于以下问题:Python NOTIFIER.is_subscribed方法的具体用法?Python NOTIFIER.is_subscribed怎么用?Python NOTIFIER.is_subscribed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类neubot.notify.NOTIFIER
的用法示例。
在下文中一共展示了NOTIFIER.is_subscribed方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_wrong_privacy
# 需要导入模块: from neubot.notify import NOTIFIER [as 别名]
# 或者: from neubot.notify.NOTIFIER import is_subscribed [as 别名]
def test_wrong_privacy(self):
''' Verify run_queue() behavior when privacy is wrong '''
#
# The whole point of this test is to make sure
# that privacy.complain() is invoked and "testdone"
# is published when privacy settings are not OK
# and a test is started.
#
# We need to ensure privacy.complain() is invoked
privacy_complain = [0]
def on_privacy_complain():
''' Register privacy.complain() invokation '''
privacy_complain[0] += 1
# Setup (we will restore that later)
saved_complain = privacy.complain
privacy.complain = on_privacy_complain
CONFIG.conf['privacy.informed'] = 0
core = RunnerCore()
core.queue.append(('foo', '/', lambda: None))
core.run_queue()
# Restore
privacy.complain = saved_complain
# Worked as expected?
self.assertTrue(privacy_complain[0])
self.assertFalse(NOTIFIER.is_subscribed("testdone"))
示例2: test_safety_net
# 需要导入模块: from neubot.notify import NOTIFIER [as 别名]
# 或者: from neubot.notify.NOTIFIER import is_subscribed [as 别名]
def test_safety_net(self):
''' Verify run_queue() safety net works '''
#
# The whole point of this test is to make sure
# that and error is printed and "testdone" is
# published when a new test is started and the
# test name is bad.
#
# We need to ensure LOG.error() is invoked
log_error = [0]
def on_log_error(message, *args):
''' Register LOG.error() invokation '''
# pylint: disable=W0613
log_error[0] += 1
# Setup (we will restore that later)
saved_log_error = LOG.error
LOG.error = on_log_error
CONFIG.conf['privacy.can_publish'] = 1
CONFIG.conf['privacy.informed'] = 1
CONFIG.conf['privacy.can_collect'] = 1
core = RunnerCore()
core.queue.append(('foo', '/', lambda: None))
core.run_queue()
# Restore
LOG.error = saved_log_error
# Worked as expected?
self.assertTrue(log_error[0])
self.assertFalse(NOTIFIER.is_subscribed("testdone"))
示例3: test_bittorrent_invokation_bad
# 需要导入模块: from neubot.notify import NOTIFIER [as 别名]
# 或者: from neubot.notify.NOTIFIER import is_subscribed [as 别名]
def test_bittorrent_invokation_bad(self):
''' Verify run_queue() behavior when bittorrent is invoked
and there is NOT a URI for bittorrent '''
#
# The whole point of this test is to make sure that
# the callback() is invoked and the "testdone" event
# has been fired, when we try to run a bittorrent
# test and we don't have a registered URI for such
# test.
#
# We need to ensure callback() is invoked
callback = [0]
def on_callback():
''' Register callback() invokation '''
# pylint: disable=W0613
callback[0] += 1
CONFIG.conf['privacy.can_publish'] = 1
CONFIG.conf['privacy.informed'] = 1
CONFIG.conf['privacy.can_collect'] = 1
core = RunnerCore()
core.queue.append(('bittorrent', on_callback, None))
core.run_queue()
# Worked as expected?
self.assertTrue(callback[0])
self.assertFalse(NOTIFIER.is_subscribed("testdone"))
示例4: run
# 需要导入模块: from neubot.notify import NOTIFIER [as 别名]
# 或者: from neubot.notify.NOTIFIER import is_subscribed [as 别名]
def run(poller, conf):
'''
This function is invoked when Neubot is already
running and you want to leverage some functionalities
of this module.
'''
# Make sure the conf makes sense before we go
config.finalize_conf(conf)
if conf["bittorrent.listen"]:
if conf["bittorrent.negotiate"]:
#
# We assume that the caller has already started
# the HTTP server and that it contains our negotiator
# so here we just bring up the test server.
#
server = ServerPeer(poller)
server.configure(conf)
server.listen((conf["bittorrent.address"],
conf["bittorrent.port"]))
else:
server = PeerNeubot(poller)
server.configure(conf)
server.listen((conf["bittorrent.address"],
conf["bittorrent.port"]))
else:
#
# Make sure there is someone ready to receive the
# "testdone" event. If there is noone it is a bug
# none times out of ten.
#
if not NOTIFIER.is_subscribed("testdone"):
log.oops("The 'testdone' event is not subscribed")
if conf["bittorrent.negotiate"]:
client = BitTorrentClient(poller)
client.configure(conf)
#
# The rendezvous client uses this hidden variable
# to pass us the URI to connect() to (the rendezvous
# returns an URI, not address and port).
#
uri = None
if "bittorrent._uri" in conf:
uri = conf["bittorrent._uri"]
client.connect_uri(uri)
else:
client = PeerNeubot(poller)
client.configure(conf)
client.connect((conf["bittorrent.address"],
conf["bittorrent.port"]))
示例5: connection_lost
# 需要导入模块: from neubot.notify import NOTIFIER [as 别名]
# 或者: from neubot.notify.NOTIFIER import is_subscribed [as 别名]
def connection_lost(self, stream):
if NOTIFIER.is_subscribed("testdone"):
LOG.debug("RendezVous: don't _schedule(): test in progress")
return
if self._task:
LOG.debug("RendezVous: don't _schedule(): we already have a task")
return
self._schedule()
示例6: test_bittorrent_invokation_good
# 需要导入模块: from neubot.notify import NOTIFIER [as 别名]
# 或者: from neubot.notify.NOTIFIER import is_subscribed [as 别名]
def test_bittorrent_invokation_good(self):
''' Verify run_queue() behavior when bittorrent is invoked
and there is a URI for bittorrent '''
#
# The whole point of this test is to make sure that
# bittorrent.run() is invoked when privacy is OK and
# we have a negotiate URI. We also want to check that
# the "testdone" event is subscribed after run_queue(),
# i.e. that someone is waiting for the event that
# signals the end of the test.
#
# We need to ensure bittorrent.run() is invoked
bittorrent_run = [0]
def on_bittorrent_run(poller, conf):
''' Register bittorrent.run() invokation '''
# pylint: disable=W0613
bittorrent_run[0] += 1
# Setup (we will restore that later)
saved_run = bittorrent.run
bittorrent.run = on_bittorrent_run
RUNNER_TESTS.update({'bittorrent': '/'})
CONFIG.conf['privacy.can_publish'] = 1
CONFIG.conf['privacy.informed'] = 1
CONFIG.conf['privacy.can_collect'] = 1
core = RunnerCore()
core.queue.append(('bittorrent', Deferred(), None))
core.run_queue()
# Restore
bittorrent.run = saved_run
RUNNER_TESTS.update({})
# Worked as expected?
self.assertTrue(bittorrent_run[0])
self.assertTrue(NOTIFIER.is_subscribed("testdone"))
#
# Clear the "testdone" because otherwise it will
# screw up other tests and we don't want that
#
NOTIFIER.publish("testdone")
示例7: _maintain_database
# 需要导入模块: from neubot.notify import NOTIFIER [as 别名]
# 或者: from neubot.notify.NOTIFIER import is_subscribed [as 别名]
def _maintain_database(self, *args, **kwargs):
POLLER.sched(INTERVAL, self._maintain_database)
if (self._use_database and not NOTIFIER.is_subscribed("testdone")):
self._writeback()