当前位置: 首页>>代码示例>>Python>>正文


Python multi.MultiTool类代码示例

本文整理汇总了Python中celery.bin.multi.MultiTool的典型用法代码示例。如果您正苦于以下问题:Python MultiTool类的具体用法?Python MultiTool怎么用?Python MultiTool使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MultiTool类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_splash

 def test_splash(self):
     x = MultiTool()
     x.note = Mock()
     x.nosplash = True
     x.splash()
     x.note.assert_not_called()
     x.nosplash = False
     x.splash()
     x.note.assert_called()
开发者ID:Changgyujin,项目名称:celery,代码行数:9,代码来源:test_multi.py

示例2: setup

 def setup(self):
     self.fh = WhateverIO()
     self.env = {}
     self.t = MultiTool(env=self.env, fh=self.fh)
     self.t.Cluster = Mock(name='Cluster')
     self.t.carp = Mock(name='.carp')
     self.t.usage = Mock(name='.usage')
     self.t.splash = Mock(name='.splash')
     self.t.say = Mock(name='.say')
     self.t.ok = Mock(name='.ok')
     self.cluster = self.t.Cluster.return_value
开发者ID:Charles-Yurun,项目名称:celery,代码行数:11,代码来源:test_multi.py

示例3: test_Cluster

 def test_Cluster(self):
     m = MultiTool()
     c = m.cluster_from_argv(['A', 'B', 'C'])
     assert c.env is m.env
     assert c.cmd == 'celery worker'
     assert c.on_stopping_preamble == m.on_stopping_preamble
     assert c.on_send_signal == m.on_send_signal
     assert c.on_still_waiting_for == m.on_still_waiting_for
     assert c.on_still_waiting_progress == m.on_still_waiting_progress
     assert c.on_still_waiting_end == m.on_still_waiting_end
     assert c.on_node_start == m.on_node_start
     assert c.on_node_restart == m.on_node_restart
     assert c.on_node_shutdown_ok == m.on_node_shutdown_ok
     assert c.on_node_status == m.on_node_status
     assert c.on_node_signal_dead == m.on_node_signal_dead
     assert c.on_node_signal == m.on_node_signal
     assert c.on_node_down == m.on_node_down
     assert c.on_child_spawn == m.on_child_spawn
     assert c.on_child_signalled == m.on_child_signalled
     assert c.on_child_failure == m.on_child_failure
开发者ID:ChillarAnand,项目名称:celery,代码行数:20,代码来源:test_multi.py

示例4: test_Cluster

 def test_Cluster(self):
     m = MultiTool()
     c = m.cluster_from_argv(['A', 'B', 'C'])
     self.assertIs(c.env, m.env)
     self.assertEqual(c.cmd, 'celery worker')
     self.assertEqual(c.on_stopping_preamble, m.on_stopping_preamble)
     self.assertEqual(c.on_send_signal, m.on_send_signal)
     self.assertEqual(c.on_still_waiting_for, m.on_still_waiting_for)
     self.assertEqual(
         c.on_still_waiting_progress,
         m.on_still_waiting_progress,
     )
     self.assertEqual(c.on_still_waiting_end, m.on_still_waiting_end)
     self.assertEqual(c.on_node_start, m.on_node_start)
     self.assertEqual(c.on_node_restart, m.on_node_restart)
     self.assertEqual(c.on_node_shutdown_ok, m.on_node_shutdown_ok)
     self.assertEqual(c.on_node_status, m.on_node_status)
     self.assertEqual(c.on_node_signal_dead, m.on_node_signal_dead)
     self.assertEqual(c.on_node_signal, m.on_node_signal)
     self.assertEqual(c.on_node_down, m.on_node_down)
     self.assertEqual(c.on_child_spawn, m.on_child_spawn)
     self.assertEqual(c.on_child_signalled, m.on_child_signalled)
     self.assertEqual(c.on_child_failure, m.on_child_failure)
开发者ID:Changgyujin,项目名称:celery,代码行数:23,代码来源:test_multi.py

示例5: setup

    def setup(self):
        self.fh = WhateverIO()
        self.env = {}
        self.t = MultiTool(env=self.env, fh=self.fh)
        self.t.cluster_from_argv = Mock(name='cluster_from_argv')
        self.t._cluster_from_argv = Mock(name='cluster_from_argv')
        self.t.Cluster = Mock(name='Cluster')
        self.t.carp = Mock(name='.carp')
        self.t.usage = Mock(name='.usage')
        self.t.splash = Mock(name='.splash')
        self.t.say = Mock(name='.say')
        self.t.ok = Mock(name='.ok')
        self.cluster = self.t.Cluster.return_value

        def _cluster_from_argv(argv):
            p = self.t.OptionParser(argv)
            p.parse()
            return p, self.cluster
        self.t.cluster_from_argv.return_value = self.cluster
        self.t._cluster_from_argv.side_effect = _cluster_from_argv
开发者ID:Changgyujin,项目名称:celery,代码行数:20,代码来源:test_multi.py

示例6: setup

 def setup(self):
     self.fh = WhateverIO()
     self.env = {}
     self.t = MultiTool(env=self.env, fh=self.fh)
开发者ID:Deepakdubey90,项目名称:django-template-demo,代码行数:4,代码来源:test_multi.py

示例7: 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_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'])
        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())

#.........这里部分代码省略.........
开发者ID:Deepakdubey90,项目名称:django-template-demo,代码行数:101,代码来源:test_multi.py

示例8: run_from_argv

 def run_from_argv(self, prog_name, argv, command=None):
     from celery.bin.multi import MultiTool
     multi = MultiTool(quiet=self.quiet, no_color=self.no_color)
     return multi.execute_from_commandline(
         [command] + argv, prog_name,
     )
开发者ID:277800076,项目名称:celery,代码行数:6,代码来源:celery.py

示例9: 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(
#.........这里部分代码省略.........
开发者ID:Changgyujin,项目名称:celery,代码行数:101,代码来源:test_multi.py

示例10: test_MultiTool

class test_MultiTool(AppCase):

    def setup(self):
        self.fh = WhateverIO()
        self.env = {}
        self.t = MultiTool(env=self.env, fh=self.fh)
        self.t.cluster_from_argv = Mock(name='cluster_from_argv')
        self.t._cluster_from_argv = Mock(name='cluster_from_argv')
        self.t.Cluster = Mock(name='Cluster')
        self.t.carp = Mock(name='.carp')
        self.t.usage = Mock(name='.usage')
        self.t.splash = Mock(name='.splash')
        self.t.say = Mock(name='.say')
        self.t.ok = Mock(name='.ok')
        self.cluster = self.t.Cluster.return_value

        def _cluster_from_argv(argv):
            p = self.t.OptionParser(argv)
            p.parse()
            return p, self.cluster
        self.t.cluster_from_argv.return_value = self.cluster
        self.t._cluster_from_argv.side_effect = _cluster_from_argv

    def test_findsig(self):
        self.assert_sig_argument(['a', 'b', 'c', '-1'], 1)
        self.assert_sig_argument(['--foo=1', '-9'], 9)
        self.assert_sig_argument(['-INT'], signal.SIGINT)
        self.assert_sig_argument([], signal.SIGTERM)
        self.assert_sig_argument(['-s'], signal.SIGTERM)
        self.assert_sig_argument(['-log'], signal.SIGTERM)

    def assert_sig_argument(self, args, expected):
        p = self.t.OptionParser(args)
        p.parse()
        self.assertEqual(self.t._find_sig_argument(p), expected)

    def test_execute_from_commandline(self):
        self.t.call_command = Mock(name='call_command')
        self.t.execute_from_commandline(
            'multi start --verbose 10 --foo'.split(),
            cmd='X',
        )
        self.assertEqual(self.t.cmd, 'X')
        self.assertEqual(self.t.prog_name, 'multi')
        self.t.call_command.assert_called_with('start', ['10', '--foo'])

    def test_execute_from_commandline__arguments(self):
        self.assertTrue(self.t.execute_from_commandline('multi'.split()))
        self.assertTrue(self.t.execute_from_commandline('multi -bar'.split()))

    def test_call_command(self):
        cmd = self.t.commands['foo'] = Mock(name='foo')
        self.t.retcode = 303
        self.assertIs(
            self.t.call_command('foo', ['1', '2', '--foo=3']),
            cmd.return_value,
        )
        cmd.assert_called_with('1', '2', '--foo=3')

    def test_call_command__error(self):
        self.assertEqual(
            self.t.call_command('asdqwewqe', ['1', '2']),
            1,
        )
        self.t.carp.assert_called()

    def test_handle_reserved_options(self):
        self.assertListEqual(
            self.t._handle_reserved_options(
                ['a', '-q', 'b', '--no-color', 'c']),
            ['a', 'b', 'c'],
        )

    def test_start(self):
        self.cluster.start.return_value = [0, 0, 1, 0]
        self.assertTrue(self.t.start('10', '-A', 'proj'))
        self.t.splash.assert_called_with()
        self.t.cluster_from_argv.assert_called_with(('10', '-A', 'proj'))
        self.cluster.start.assert_called_with()

    def test_start__exitcodes(self):
        self.cluster.start.return_value = [0, 0, 0]
        self.assertFalse(self.t.start('foo', 'bar', 'baz'))
        self.cluster.start.assert_called_with()

        self.cluster.start.return_value = [0, 1, 0]
        self.assertTrue(self.t.start('foo', 'bar', 'baz'))

    def test_stop(self):
        self.t.stop('10', '-A', 'proj', retry=3)
        self.t.splash.assert_called_with()
        self.t._cluster_from_argv.assert_called_with(('10', '-A', 'proj'))
        self.cluster.stop.assert_called_with(retry=3, sig=signal.SIGTERM)

    def test_stopwait(self):
        self.t.stopwait('10', '-A', 'proj', retry=3)
        self.t.splash.assert_called_with()
        self.t._cluster_from_argv.assert_called_with(('10', '-A', 'proj'))
        self.cluster.stopwait.assert_called_with(retry=3, sig=signal.SIGTERM)

#.........这里部分代码省略.........
开发者ID:Changgyujin,项目名称:celery,代码行数:101,代码来源:test_multi.py


注:本文中的celery.bin.multi.MultiTool类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。