本文整理汇总了Python中celery.five.WhateverIO类的典型用法代码示例。如果您正苦于以下问题:Python WhateverIO类的具体用法?Python WhateverIO怎么用?Python WhateverIO使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WhateverIO类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cry
def cry(out=None, sepchr='=', seplen=49): # pragma: no cover
"""Return stack-trace of all active threads,
taken from https://gist.github.com/737056."""
import threading
out = WhateverIO() if out is None else out
P = partial(print, file=out)
# get a map of threads by their ID so we can print their names
# during the traceback dump
tmap = {t.ident: t for t in threading.enumerate()}
sep = sepchr * seplen
for tid, frame in items(sys._current_frames()):
thread = tmap.get(tid)
if not thread:
# skip old junk (left-overs from a fork)
continue
P('{0.name}'.format(thread))
P(sep)
traceback.print_stack(frame, file=out)
P(sep)
P('LOCAL VARIABLES')
P(sep)
pprint(frame.f_locals, stream=out)
P('\n')
return out.getvalue()
示例2: test_run
def test_run(self):
out = WhateverIO()
h = help(app=self.app, stdout=out)
h.parser = Mock()
assert h.run() == EX_USAGE
assert out.getvalue()
assert h.usage('help')
h.parser.print_help.assert_called_with()
示例3: test_run
def test_run(self):
out = WhateverIO()
h = help(app=self.app, stdout=out)
h.parser = Mock()
self.assertEqual(h.run(), EX_USAGE)
self.assertTrue(out.getvalue())
self.assertTrue(h.usage('help'))
h.parser.print_help.assert_called_with()
示例4: test_Dumper
class test_Dumper(AppCase):
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(
'[email protected]', time(), 'task-started', 'tasks.add', {})
self.assertTrue(self.out.getvalue())
def test_on_event(self):
event = {
'hostname': '[email protected]',
'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(app=self.app)
def test_evdump_error_handler(self):
app = Mock(name='app')
with patch('celery.events.dumper.Dumper') as Dumper:
Dumper.return_value = Mock(name='dumper')
recv = app.events.Receiver.return_value = Mock()
def se(*_a, **_k):
recv.capture.side_effect = SystemExit()
raise KeyError()
recv.capture.side_effect = se
Conn = app.connection_for_read.return_value = Mock(name='conn')
conn = Conn.clone.return_value = Mock(name='cloned_conn')
conn.connection_errors = (KeyError,)
conn.channel_errors = ()
evdump(app)
conn.ensure_connection.assert_called()
errback = conn.ensure_connection.call_args[0][0]
errback(KeyError(), 1)
conn.as_uri.assert_called()
示例5: test_Dumper
class test_Dumper(AppCase):
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("[email protected]", time(), "task-started", "tasks.add", {})
self.assertTrue(self.out.getvalue())
def test_on_event(self):
event = {
"hostname": "[email protected]",
"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(app=self.app)
def test_evdump_error_handler(self):
app = Mock(name="app")
with patch("celery.events.dumper.Dumper") as Dumper:
Dumper.return_value = Mock(name="dumper")
recv = app.events.Receiver.return_value = Mock()
def se(*_a, **_k):
recv.capture.side_effect = SystemExit()
raise KeyError()
recv.capture.side_effect = se
Conn = app.connection_for_read.return_value = Mock(name="conn")
conn = Conn.clone.return_value = Mock(name="cloned_conn")
conn.connection_errors = (KeyError,)
conn.channel_errors = ()
evdump(app)
self.assertTrue(conn.ensure_connection.called)
errback = conn.ensure_connection.call_args[0][0]
errback(KeyError(), 1)
self.assertTrue(conn.as_uri.called)
示例6: test_run
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")
assert "Jerry" in out.getvalue()
get.return_value = "Elaine"
r.run("id", task=self.add.name)
assert "Elaine" in out.getvalue()
with patch("celery.result.AsyncResult.traceback") as tb:
r.run("id", task=self.add.name, traceback=True)
assert str(tb) in out.getvalue()
示例7: test_run
def test_run(self, purge_):
out = WhateverIO()
a = purge(app=self.app, stdout=out)
purge_.return_value = 0
a.run(force=True)
self.assertIn('No messages purged', out.getvalue())
purge_.return_value = 100
a.run(force=True)
self.assertIn('100 messages', out.getvalue())
a.out = Mock(name='out')
a.ask = Mock(name='ask')
a.run(force=False)
a.ask.assert_called_with(a.warn_prompt, ('yes', 'no'), 'no')
a.ask.return_value = 'yes'
a.run(force=False)
示例8: test_rdb
def test_rdb(self, get_avail_port):
sock = Mock()
get_avail_port.return_value = (sock, 8000)
sock.accept.return_value = (Mock(), ['helu'])
out = WhateverIO()
with Rdb(out=out) as rdb:
get_avail_port.assert_called()
assert 'helu' in 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 = SockErr
pset.side_effect.errno = errno.ENOENT
with pytest.raises(SockErr):
rdb.set_trace()
# _close_session
rdb._close_session()
rdb.active = True
rdb._handle = None
rdb._client = None
rdb._sock = None
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()
示例9: setup
class test_AMQShell:
def setup(self):
self.fh = WhateverIO()
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')
assert 'ok' in self.fh.getvalue()
def test_missing_command(self):
self.shell.onecmd('foo foo')
assert 'unknown syntax' in self.fh.getvalue()
def RV(self):
raise Exception(self.fh.getvalue())
def test_spec_format_response(self):
spec = self.shell.amqp['exchange.declare']
assert spec.format_response(None) == 'ok.'
assert spec.format_response('NO') == 'NO'
def test_missing_namespace(self):
self.shell.onecmd('ns.cmd arg')
assert 'unknown syntax' in self.fh.getvalue()
def test_help(self):
self.shell.onecmd('help')
assert 'Example:' in self.fh.getvalue()
def test_help_command(self):
self.shell.onecmd('help queue.declare')
assert 'passive:no' in self.fh.getvalue()
def test_help_unknown_command(self):
self.shell.onecmd('help foo.baz')
assert 'unknown syntax' in self.fh.getvalue()
def test_onecmd_error(self):
self.shell.dispatch = Mock()
self.shell.dispatch.side_effect = MemoryError()
self.shell.say = Mock()
assert not self.shell.needs_reconnect
self.shell.onecmd('hello')
self.shell.say.assert_called()
assert self.shell.needs_reconnect
def test_exit(self):
with pytest.raises(SystemExit):
self.shell.onecmd('exit')
assert "don't leave!" in self.fh.getvalue()
def test_note_silent(self):
self.shell.silent = True
self.shell.note('foo bar')
assert 'foo bar' not in 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):
assert self.shell.completenames('queue.dec') == ['queue.declare']
assert (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'})
assert 'foo' in self.fh.getvalue()
def test_prompt(self):
assert 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'}
assert dump_message(m)
def test_dump_message_no_message(self):
#.........这里部分代码省略.........
示例10: test_MultiTool
class test_MultiTool(AppCase):
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_carp(self):
self.t.say = Mock()
self.t.carp('foo')
self.t.say.assert_called_with('foo', True, self.t.stderr)
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.carp = Mock()
self.t.usage = Mock()
self.assertEqual(self.t.error('foo'), 1)
self.t.carp.assert_called_with('foo')
self.t.usage.assert_called_with()
self.t.carp = Mock()
self.assertEqual(self.t.error(), 1)
self.assertFalse(self.t.carp.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'], path=sys.executable)
self.assertIn('OK', self.fh.getvalue())
self.fh.seek(0)
self.fh.truncate()
#.........这里部分代码省略.........
示例11: test_MultiTool_functional
class test_MultiTool_functional(AppCase):
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_carp(self):
self.t.say = Mock()
self.t.carp('foo')
self.t.say.assert_called_with('foo', True, self.t.stderr)
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.carp = Mock()
self.t.usage = Mock()
self.assertEqual(self.t.error('foo'), 1)
self.t.carp.assert_called_with('foo')
self.t.usage.assert_called_with()
self.t.carp = Mock()
self.assertEqual(self.t.error(), 1)
self.t.carp.assert_not_called()
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',
)
@patch('celery.apps.multi.gethostname')
def test_get(self, gethostname):
gethostname.return_value = 'e.com'
self.t.get('[email protected]', 'foo', 'bar', 'baz')
self.assertFalse(self.fh.getvalue())
self.t.get('[email protected]', 'foo', 'bar', 'baz')
self.assertTrue(self.fh.getvalue())
@patch('celery.apps.multi.gethostname')
def test_names(self, gethostname):
gethostname.return_value = 'e.com'
self.t.names('foo', 'bar', 'baz')
self.assertIn('[email protected]\[email protected]\[email protected]', self.fh.getvalue())
def test_execute_from_commandline(self):
start = self.t.commands['start'] = Mock()
self.t.error = Mock()
self.t.execute_from_commandline(['multi', 'start', 'foo', 'bar'])
self.t.error.assert_not_called()
start.assert_called_with('foo', 'bar')
self.t.error = Mock()
self.t.execute_from_commandline(['multi', 'frob', 'foo', 'bar'])
self.t.error.assert_called_with('Invalid command: frob')
self.t.error = Mock()
self.t.execute_from_commandline(['multi'])
self.t.error.assert_called_with()
self.t.error = Mock()
self.t.execute_from_commandline(['multi', '-foo'])
self.t.error.assert_called_with()
self.t.execute_from_commandline(
#.........这里部分代码省略.........
示例12: setup
def setup(self):
self.fh = WhateverIO()
self.env = {}
self.t = MultiTool(env=self.env, fh=self.fh)
示例13: setup
def setup(self):
self.out = WhateverIO()
self.dumper = Dumper(out=self.out)
示例14: test_to_dot
def test_to_dot(self):
s = WhateverIO()
self.graph1().to_dot(s)
assert s.getvalue()