本文整理汇总了Python中celery.tests.utils.WhateverIO.getvalue方法的典型用法代码示例。如果您正苦于以下问题:Python WhateverIO.getvalue方法的具体用法?Python WhateverIO.getvalue怎么用?Python WhateverIO.getvalue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类celery.tests.utils.WhateverIO
的用法示例。
在下文中一共展示了WhateverIO.getvalue方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_Dumper
# 需要导入模块: from celery.tests.utils import WhateverIO [as 别名]
# 或者: from celery.tests.utils.WhateverIO import getvalue [as 别名]
class test_Dumper(Case):
def setUp(self):
self.out = WhateverIO()
self.dumper = Dumper(out=self.out)
def test_humanize_type(self):
self.assertEqual(humanize_type('worker-offline'), 'shutdown')
self.assertEqual(humanize_type('task-started'), 'task started')
def test_format_task_event(self):
self.dumper.format_task_event(
'worker.example.com', time(), 'task-started', 'tasks.add', {})
self.assertTrue(self.out.getvalue())
def test_on_event(self):
event = {
'hostname': 'worker.example.com',
'timestamp': time(),
'uuid': '1ef',
'name': 'tasks.add',
'args': '(2, 2)',
'kwargs': '{}',
}
self.dumper.on_event(dict(event, type='task-received'))
self.assertTrue(self.out.getvalue())
self.dumper.on_event(dict(event, type='task-revoked'))
self.dumper.on_event(dict(event, type='worker-online'))
@patch('celery.events.EventReceiver.capture')
def test_evdump(self, capture):
capture.side_effect = KeyboardInterrupt()
evdump()
示例2: test_run
# 需要导入模块: from celery.tests.utils import WhateverIO [as 别名]
# 或者: from celery.tests.utils.WhateverIO import getvalue [as 别名]
def test_run(self, real):
out = WhateverIO()
i = inspect(app=self.app, stdout=out)
with self.assertRaises(Error):
i.run()
with self.assertRaises(Error):
i.run('help')
with self.assertRaises(Error):
i.run('xyzzybaz')
i.run('ping')
self.assertTrue(real.called)
i.run('ping', destination='foo,bar')
self.assertEqual(real.call_args[1]['destination'], ['foo', 'bar'])
self.assertEqual(real.call_args[1]['timeout'], 0.2)
callback = real.call_args[1]['callback']
callback({'foo': {'ok': 'pong'}})
self.assertIn('OK', out.getvalue())
instance = real.return_value = Mock()
instance.ping.return_value = None
with self.assertRaises(Error):
i.run('ping')
out.seek(0)
out.truncate()
i.quiet = True
i.say('<-', 'hello')
self.assertFalse(out.getvalue())
示例3: test_Dumper
# 需要导入模块: from celery.tests.utils import WhateverIO [as 别名]
# 或者: from celery.tests.utils.WhateverIO import getvalue [as 别名]
class test_Dumper(Case):
def setUp(self):
self.out = WhateverIO()
self.dumper = Dumper(out=self.out)
def test_humanize_type(self):
self.assertEqual(humanize_type("worker-offline"), "shutdown")
self.assertEqual(humanize_type("task-started"), "task started")
def test_format_task_event(self):
self.dumper.format_task_event(
"worker.example.com", time(), "task-started", "tasks.add", {})
self.assertTrue(self.out.getvalue())
def test_on_event(self):
event = {
"hostname": "worker.example.com",
"timestamp": time(),
"uuid": "1ef",
"name": "tasks.add",
"args": "(2, 2)",
"kwargs": "{}",
}
self.dumper.on_event(dict(event, type="task-received"))
self.assertTrue(self.out.getvalue())
self.dumper.on_event(dict(event, type="task-revoked"))
self.dumper.on_event(dict(event, type="worker-online"))
@patch("celery.events.EventReceiver.capture")
def test_evdump(self, capture):
evdump()
capture.side_effect = KeyboardInterrupt()
evdump()
示例4: test_run
# 需要导入模块: from celery.tests.utils import WhateverIO [as 别名]
# 或者: from celery.tests.utils.WhateverIO import getvalue [as 别名]
def test_run(self):
with patch("celery.result.AsyncResult.get") as get:
out = WhateverIO()
r = result(app=self.app, stdout=out)
get.return_value = "Jerry"
r.run("id")
self.assertIn("Jerry", out.getvalue())
get.return_value = "Elaine"
r.run("id", task=add.name)
self.assertIn("Elaine", out.getvalue())
with patch("celery.result.AsyncResult.traceback") as tb:
r.run("id", task=add.name, traceback=True)
self.assertIn(str(tb), out.getvalue())
示例5: _test_on_failure
# 需要导入模块: from celery.tests.utils import WhateverIO [as 别名]
# 或者: from celery.tests.utils.WhateverIO import getvalue [as 别名]
def _test_on_failure(self, exception):
app = app_or_default()
tid = uuid()
tw = TaskRequest(mytask.name, tid, [4], {"f": "x"})
try:
raise exception
except Exception:
exc_info = ExceptionInfo(sys.exc_info())
logfh = WhateverIO()
tw.logger.handlers = []
tw.logger = app.log.setup_logger("INFO", logfh, root=False)
app.conf.CELERY_SEND_TASK_ERROR_EMAILS = True
tw.on_failure(exc_info)
logvalue = logfh.getvalue()
self.assertIn(mytask.name, logvalue)
self.assertIn(tid, logvalue)
self.assertIn("ERROR", logvalue)
app.conf.CELERY_SEND_TASK_ERROR_EMAILS = False
示例6: test_rdb
# 需要导入模块: from celery.tests.utils import WhateverIO [as 别名]
# 或者: from celery.tests.utils.WhateverIO import getvalue [as 别名]
def test_rdb(self, get_avail_port):
sock = Mock()
get_avail_port.return_value = (sock, 8000)
sock.accept.return_value = (Mock(), ['helu'])
out = WhateverIO()
rdb = Rdb(out=out)
self.assertTrue(get_avail_port.called)
self.assertIn('helu', out.getvalue())
# set_quit
with patch('sys.settrace') as settrace:
rdb.set_quit()
settrace.assert_called_with(None)
# set_trace
with patch('celery.contrib.rdb.Pdb.set_trace') as pset:
with patch('celery.contrib.rdb._frame'):
rdb.set_trace()
rdb.set_trace(Mock())
pset.side_effect = socket.error
pset.side_effect.errno = errno.ECONNRESET
rdb.set_trace()
pset.side_effect.errno = errno.ENOENT
with self.assertRaises(socket.error):
rdb.set_trace()
# _close_session
rdb._close_session()
# do_continue
rdb.set_continue = Mock()
rdb.do_continue(Mock())
rdb.set_continue.assert_called_with()
# do_quit
rdb.set_quit = Mock()
rdb.do_quit(Mock())
rdb.set_quit.assert_called_with()
示例7: test_to_dot
# 需要导入模块: from celery.tests.utils import WhateverIO [as 别名]
# 或者: from celery.tests.utils.WhateverIO import getvalue [as 别名]
def test_to_dot(self):
s = WhateverIO()
self.graph1().to_dot(s)
self.assertTrue(s.getvalue())
示例8: test_AMQShell
# 需要导入模块: from celery.tests.utils import WhateverIO [as 别名]
# 或者: from celery.tests.utils.WhateverIO import getvalue [as 别名]
class test_AMQShell(AppCase):
def setup(self):
self.fh = WhateverIO()
self.app = Celery(broker='memory://', set_as_current=False)
self.adm = self.create_adm()
self.shell = AMQShell(connect=self.adm.connect, out=self.fh)
def create_adm(self, *args, **kwargs):
return AMQPAdmin(app=self.app, out=self.fh, *args, **kwargs)
def test_queue_declare(self):
self.shell.onecmd('queue.declare foo')
self.assertIn('ok', self.fh.getvalue())
def test_missing_command(self):
self.shell.onecmd('foo foo')
self.assertIn('unknown syntax', self.fh.getvalue())
def RV(self):
raise Exception(self.fh.getvalue())
def test_missing_namespace(self):
self.shell.onecmd('ns.cmd arg')
self.assertIn('unknown syntax', self.fh.getvalue())
def test_help(self):
self.shell.onecmd('help')
self.assertIn('Example:', self.fh.getvalue())
def test_help_command(self):
self.shell.onecmd('help queue.declare')
self.assertIn('passive:no', self.fh.getvalue())
def test_help_unknown_command(self):
self.shell.onecmd('help foo.baz')
self.assertIn('unknown syntax', self.fh.getvalue())
def test_exit(self):
with self.assertRaises(SystemExit):
self.shell.onecmd('exit')
self.assertIn("don't leave!", self.fh.getvalue())
def test_note_silent(self):
self.shell.silent = True
self.shell.note('foo bar')
self.assertNotIn('foo bar', self.fh.getvalue())
def test_reconnect(self):
self.shell.onecmd('queue.declare foo')
self.shell.needs_reconnect = True
self.shell.onecmd('queue.delete foo')
def test_completenames(self):
self.assertEqual(self.shell.completenames('queue.dec'),
['queue.declare'])
self.assertEqual(sorted(self.shell.completenames('declare')),
sorted(['queue.declare', 'exchange.declare']))
def test_empty_line(self):
self.shell.emptyline = Mock()
self.shell.default = Mock()
self.shell.onecmd('')
self.shell.emptyline.assert_called_with()
self.shell.onecmd('foo')
self.shell.default.assert_called_with('foo')
def test_respond(self):
self.shell.respond({'foo': 'bar'})
self.assertIn('foo', self.fh.getvalue())
def test_prompt(self):
self.assertTrue(self.shell.prompt)
def test_no_returns(self):
self.shell.onecmd('queue.declare foo')
self.shell.onecmd('exchange.declare bar direct yes')
self.shell.onecmd('queue.bind foo bar baz')
self.shell.onecmd('basic.ack 1')
def test_dump_message(self):
m = Mock()
m.body = 'the quick brown fox'
m.properties = {'a': 1}
m.delivery_info = {'exchange': 'bar'}
self.assertTrue(dump_message(m))
def test_dump_message_no_message(self):
self.assertIn('No messages in queue', dump_message(None))
def test_note(self):
self.adm.silent = True
self.adm.note('FOO')
self.assertNotIn('FOO', self.fh.getvalue())
def test_run(self):
a = self.create_adm('queue.declare foo')
a.run()
self.assertIn('ok', self.fh.getvalue())
#.........这里部分代码省略.........
示例9: test_MultiTool
# 需要导入模块: from celery.tests.utils import WhateverIO [as 别名]
# 或者: from celery.tests.utils.WhateverIO import getvalue [as 别名]
class test_MultiTool(Case):
def setUp(self):
self.fh = WhateverIO()
self.env = {}
self.t = MultiTool(env=self.env, fh=self.fh)
def test_note(self):
self.t.note('hello world')
self.assertEqual(self.fh.getvalue(), 'hello world\n')
def test_note_quiet(self):
self.t.quiet = True
self.t.note('hello world')
self.assertFalse(self.fh.getvalue())
def test_info(self):
self.t.verbose = True
self.t.info('hello info')
self.assertEqual(self.fh.getvalue(), 'hello info\n')
def test_info_not_verbose(self):
self.t.verbose = False
self.t.info('hello info')
self.assertFalse(self.fh.getvalue())
def test_error(self):
self.t.say = Mock()
self.t.usage = Mock()
self.assertEqual(self.t.error('foo'), 1)
self.t.say.assert_called_with('foo')
self.t.usage.assert_called_with()
self.t.say = Mock()
self.assertEqual(self.t.error(), 1)
self.assertFalse(self.t.say.called)
self.assertEqual(self.t.retcode, 1)
@patch('celery.bin.multi.Popen')
def test_waitexec(self, Popen):
self.t.note = Mock()
pipe = Popen.return_value = Mock()
pipe.wait.return_value = -10
self.assertEqual(self.t.waitexec(['-m', 'foo'], 'path'), 10)
Popen.assert_called_with(['path', '-m', 'foo'], env=self.t.env)
self.t.note.assert_called_with('* Child was terminated by signal 10')
pipe.wait.return_value = 2
self.assertEqual(self.t.waitexec(['-m', 'foo'], 'path'), 2)
self.t.note.assert_called_with(
'* Child terminated with errorcode 2',
)
pipe.wait.return_value = 0
self.assertFalse(self.t.waitexec(['-m', 'foo', 'path']))
def test_nosplash(self):
self.t.nosplash = True
self.t.splash()
self.assertFalse(self.fh.getvalue())
def test_splash(self):
self.t.nosplash = False
self.t.splash()
self.assertIn('celery multi', self.fh.getvalue())
def test_usage(self):
self.t.usage()
self.assertTrue(self.fh.getvalue())
def test_help(self):
self.t.help([])
self.assertIn(doc, self.fh.getvalue())
def test_expand(self):
self.t.expand(['foo%n', 'ask', 'klask', 'dask'])
self.assertEqual(
self.fh.getvalue(), 'fooask\nfooklask\nfoodask\n',
)
def test_restart(self):
stop = self.t._stop_nodes = Mock()
self.t.restart(['jerry', 'george'], 'celery worker')
waitexec = self.t.waitexec = Mock()
self.assertTrue(stop.called)
callback = stop.call_args[1]['callback']
self.assertTrue(callback)
waitexec.return_value = 0
callback('jerry', ['arg'], 13)
waitexec.assert_called_with(['arg'])
self.assertIn('OK', self.fh.getvalue())
self.fh.seek(0)
self.fh.truncate()
waitexec.return_value = 1
callback('jerry', ['arg'], 13)
self.assertIn('FAILED', self.fh.getvalue())
#.........这里部分代码省略.........
示例10: test_AMQShell
# 需要导入模块: from celery.tests.utils import WhateverIO [as 别名]
# 或者: from celery.tests.utils.WhateverIO import getvalue [as 别名]
class test_AMQShell(AppCase):
def setup(self):
self.fh = WhateverIO()
self.app = Celery(broker="memory://", set_as_current=False)
self.adm = self.create_adm()
self.shell = AMQShell(connect=self.adm.connect, out=self.fh)
def create_adm(self, *args, **kwargs):
return AMQPAdmin(app=self.app, out=self.fh, *args, **kwargs)
def test_queue_declare(self):
self.shell.onecmd("queue.declare foo")
self.assertIn("ok", self.fh.getvalue())
def test_missing_command(self):
self.shell.onecmd("foo foo")
self.assertIn("unknown syntax", self.fh.getvalue())
def RV(self):
raise Exception(self.fh.getvalue())
def test_missing_namespace(self):
self.shell.onecmd("ns.cmd arg")
self.assertIn("unknown syntax", self.fh.getvalue())
def test_help(self):
self.shell.onecmd("help")
self.assertIn("Example:", self.fh.getvalue())
def test_help_command(self):
self.shell.onecmd("help queue.declare")
self.assertIn("passive:no", self.fh.getvalue())
def test_help_unknown_command(self):
self.shell.onecmd("help foo.baz")
self.assertIn("unknown syntax", self.fh.getvalue())
def test_exit(self):
with self.assertRaises(SystemExit):
self.shell.onecmd("exit")
self.assertIn("don't leave!", self.fh.getvalue())
def test_note_silent(self):
self.shell.silent = True
self.shell.note("foo bar")
self.assertNotIn("foo bar", self.fh.getvalue())
def test_reconnect(self):
self.shell.onecmd("queue.declare foo")
self.shell.needs_reconnect = True
self.shell.onecmd("queue.delete foo")
def test_completenames(self):
self.assertEqual(self.shell.completenames("queue.dec"),
["queue.declare"])
self.assertEqual(self.shell.completenames("declare"),
["queue.declare", "exchange.declare"])
def test_empty_line(self):
self.shell.emptyline = Mock()
self.shell.default = Mock()
self.shell.onecmd("")
self.shell.emptyline.assert_called_with()
self.shell.onecmd("foo")
self.shell.default.assert_called_with("foo")
def test_respond(self):
self.shell.respond({"foo": "bar"})
self.assertIn("foo", self.fh.getvalue())
def test_prompt(self):
self.assertTrue(self.shell.prompt)
def test_no_returns(self):
self.shell.onecmd("queue.declare foo")
self.shell.onecmd("exchange.declare bar direct yes")
self.shell.onecmd("queue.bind foo bar baz")
self.shell.onecmd("basic.ack 1")
def test_dump_message(self):
m = Mock()
m.body = "the quick brown fox"
m.properties = {"a": 1}
m.delivery_info = {"exchange": "bar"}
self.assertTrue(dump_message(m))
def test_dump_message_no_message(self):
self.assertIn("No messages in queue", dump_message(None))
def test_note(self):
self.adm.silent = True
self.adm.note("FOO")
self.assertNotIn("FOO", self.fh.getvalue())
def test_run(self):
a = self.create_adm("queue.declare foo")
a.run()
self.assertIn("ok", self.fh.getvalue())
#.........这里部分代码省略.........
示例11: test_MultiTool
# 需要导入模块: from celery.tests.utils import WhateverIO [as 别名]
# 或者: from celery.tests.utils.WhateverIO import getvalue [as 别名]
class test_MultiTool(Case):
def setUp(self):
self.fh = WhateverIO()
self.env = {}
self.t = MultiTool(env=self.env, fh=self.fh)
def test_note(self):
self.t.note("hello world")
self.assertEqual(self.fh.getvalue(), "hello world\n")
def test_note_quiet(self):
self.t.quiet = True
self.t.note("hello world")
self.assertFalse(self.fh.getvalue())
def test_info(self):
self.t.verbose = True
self.t.info("hello info")
self.assertEqual(self.fh.getvalue(), "hello info\n")
def test_info_not_verbose(self):
self.t.verbose = False
self.t.info("hello info")
self.assertFalse(self.fh.getvalue())
def test_error(self):
self.t.say = Mock()
self.t.usage = Mock()
self.assertEqual(self.t.error("foo"), 1)
self.t.say.assert_called_with("foo")
self.t.usage.assert_called_with()
self.t.say = Mock()
self.assertEqual(self.t.error(), 1)
self.assertFalse(self.t.say.called)
self.assertEqual(self.t.retcode, 1)
@patch("celery.bin.celeryd_multi.Popen")
def test_waitexec(self, Popen):
self.t.note = Mock()
pipe = Popen.return_value = Mock()
pipe.wait.return_value = -10
self.assertEqual(self.t.waitexec(["-m", "foo"], "path"), 10)
Popen.assert_called_with(["path", "-m", "foo"], env=self.t.env)
self.t.note.assert_called_with("* Child was terminated by signal 10")
pipe.wait.return_value = 2
self.assertEqual(self.t.waitexec(["-m", "foo"], "path"), 2)
self.t.note.assert_called_with("* Child terminated with failure code 2")
pipe.wait.return_value = 0
self.assertFalse(self.t.waitexec(["-m", "foo", "path"]))
def test_nosplash(self):
self.t.nosplash = True
self.t.splash()
self.assertFalse(self.fh.getvalue())
def test_splash(self):
self.t.nosplash = False
self.t.splash()
self.assertIn("celeryd-multi", self.fh.getvalue())
def test_usage(self):
self.t.usage()
self.assertTrue(self.fh.getvalue())
def test_help(self):
self.t.help([])
self.assertIn(doc, self.fh.getvalue())
def test_expand(self):
self.t.expand(["foo%n", "ask", "klask", "dask"])
self.assertEqual(self.fh.getvalue(), "fooask\nfooklask\nfoodask\n")
def test_restart(self):
stop = self.t._stop_nodes = Mock()
self.t.restart(["jerry", "george"], "celeryd")
waitexec = self.t.waitexec = Mock()
self.assertTrue(stop.called)
callback = stop.call_args[1]["callback"]
self.assertTrue(callback)
waitexec.return_value = 0
callback("jerry", ["arg"], 13)
waitexec.assert_called_with(["arg"])
self.assertIn("OK", self.fh.getvalue())
self.fh.seek(0)
self.fh.truncate()
waitexec.return_value = 1
callback("jerry", ["arg"], 13)
self.assertIn("FAILED", self.fh.getvalue())
def test_stop(self):
self.t.getpids = Mock()
self.t.getpids.return_value = [2, 3, 4]
self.t.shutdown_nodes = Mock()
self.t.stop(["a", "b", "-INT"], "celeryd")
#.........这里部分代码省略.........