Esempio n. 1
0
 def test_parse(self):
     x = NamespacedOptionParser(['-c:1,3', '4'])
     x.parse()
     self.assertEqual(x.namespaces.get('1,3'), {'-c': '4'})
     x = NamespacedOptionParser(['-c:jerry,elaine', '5',
                                 '--loglevel:kramer=DEBUG',
                                 '--flag',
                                 '--logfile=foo', '-Q', 'bar', 'a', 'b',
                                 '--', '.disable_rate_limits=1'])
     x.parse()
     self.assertEqual(x.options, {'--logfile': 'foo',
                                  '-Q': 'bar',
                                  '--flag': None})
     self.assertEqual(x.values, ['a', 'b'])
     self.assertEqual(x.namespaces.get('jerry,elaine'), {'-c': '5'})
     self.assertEqual(x.namespaces.get('kramer'), {'--loglevel': 'DEBUG'})
     self.assertEqual(x.passthrough, '-- .disable_rate_limits=1')
Esempio n. 2
0
 def test_parse(self):
     x = NamespacedOptionParser(['-c:1,3', '4'])
     x.parse()
     assert x.namespaces.get('1,3') == {'-c': '4'}
     x = NamespacedOptionParser([
         '-c:jerry,elaine', '5', '--loglevel:kramer=DEBUG', '--flag',
         '--logfile=foo', '-Q', 'bar', 'a', 'b', '--',
         '.disable_rate_limits=1'
     ])
     x.parse()
     assert x.options == {
         '--logfile': 'foo',
         '-Q': 'bar',
         '--flag': None,
     }
     assert x.values, ['a' == 'b']
     assert x.namespaces.get('jerry,elaine') == {'-c': '5'}
     assert x.namespaces.get('kramer') == {'--loglevel': 'DEBUG'}
     assert x.passthrough == '-- .disable_rate_limits=1'
Esempio n. 3
0
    def test_parse(self, gethostname):
        gethostname.return_value = 'example.com'
        p = NamespacedOptionParser([
            '-c:jerry,elaine',
            '5',
            '--loglevel:kramer=DEBUG',
            '--flag',
            '--logfile=/var/log/celery/foo',
            '-Q',
            'bar',
            'jerry',
            'elaine',
            'kramer',
            '--',
            '.disable_rate_limits=1',
        ])
        p.parse()
        it = multi_args(p,
                        cmd='COMMAND',
                        append='*AP*',
                        prefix='*P*',
                        suffix='*S*')
        nodes = list(it)

        def assert_line_in(name, args):
            assert name in {n.name for n in nodes}
            argv = None
            for node in nodes:
                if node.name == name:
                    argv = node.argv
            assert argv
            for arg in args:
                assert arg in argv

        assert_line_in(
            '*P*jerry@*S*',
            [
                'COMMAND', '-n *P*jerry@*S*', '-Q bar', '-c 5', '--flag',
                '--logfile=/var/log/celery/foo', '-- .disable_rate_limits=1',
                '*AP*'
            ],
        )
        assert_line_in(
            '*P*elaine@*S*',
            [
                'COMMAND', '-n *P*elaine@*S*', '-Q bar', '-c 5', '--flag',
                '--logfile=/var/log/celery/foo', '-- .disable_rate_limits=1',
                '*AP*'
            ],
        )
        assert_line_in(
            '*P*kramer@*S*',
            [
                'COMMAND', '--loglevel=DEBUG', '-n *P*kramer@*S*', '-Q bar',
                '--flag', '--logfile=/var/log/celery/foo',
                '-- .disable_rate_limits=1', '*AP*'
            ],
        )
        expand = nodes[0].expander
        assert expand('%h') == '*P*jerry@*S*'
        assert expand('%n') == '*P*jerry'
        nodes2 = list(
            multi_args(p, cmd='COMMAND', append='', prefix='*P*',
                       suffix='*S*'))
        assert nodes2[0].argv[-1] == '-- .disable_rate_limits=1'

        p2 = NamespacedOptionParser(['10', '-c:1', '5'])
        p2.parse()
        nodes3 = list(multi_args(p2, cmd='COMMAND'))

        def _args(name, *args):
            return args + (
                '--pidfile={}.pid'.format(
                    os.path.join(os.path.normpath('/var/run/celery/'), name)),
                '--logfile={}%I.log'.format(
                    os.path.join(os.path.normpath('/var/log/celery/'), name)),
                '--executable={0}'.format(sys.executable),
                '',
            )

        assert len(nodes3) == 10
        assert nodes3[0].name == '*****@*****.**'
        assert nodes3[0].argv == ('COMMAND', '-c 5',
                                  '-n [email protected]') + _args('celery1')
        for i, worker in enumerate(nodes3[1:]):
            assert worker.name == '*****@*****.**' % (i + 2)
            node_i = 'celery%s' % (i + 2, )
            assert worker.argv == ('COMMAND', '-n %[email protected]' %
                                   (node_i, )) + _args(node_i)

        nodes4 = list(multi_args(p2, cmd='COMMAND', suffix='""'))
        assert len(nodes4) == 10
        assert nodes4[0].name == 'celery1@'
        assert nodes4[0].argv == ('COMMAND', '-c 5',
                                  '-n celery1@') + _args('celery1')

        p3 = NamespacedOptionParser(['foo@', '-c:foo', '5'])
        p3.parse()
        nodes5 = list(multi_args(p3, cmd='COMMAND', suffix='""'))
        assert nodes5[0].name == 'foo@'
        assert nodes5[0].argv == ('COMMAND', '-c 5', '-n foo@') + _args('foo')

        p4 = NamespacedOptionParser(['foo', '-Q:1', 'test'])
        p4.parse()
        nodes6 = list(multi_args(p4, cmd='COMMAND', suffix='""'))
        assert nodes6[0].name == 'foo@'
        assert nodes6[0].argv == ('COMMAND', '-Q test',
                                  '-n foo@') + _args('foo')

        p5 = NamespacedOptionParser(['foo@bar', '-Q:1', 'test'])
        p5.parse()
        nodes7 = list(multi_args(p5, cmd='COMMAND', suffix='""'))
        assert nodes7[0].name == 'foo@bar'
        assert nodes7[0].argv == ('COMMAND', '-Q test',
                                  '-n foo@bar') + _args('foo')

        p6 = NamespacedOptionParser(['foo@bar', '-Q:0', 'test'])
        p6.parse()
        with pytest.raises(KeyError):
            list(multi_args(p6))
Esempio n. 4
0
 def test_optmerge(self):
     p = NamespacedOptionParser(['foo', 'test'])
     p.parse()
     p.options = {'x': 'y'}
     r = p.optmerge('foo')
     assert r['x'] == 'y'
Esempio n. 5
0
    def test_parse(self, gethostname):
        gethostname.return_value = 'example.com'
        p = NamespacedOptionParser([
            '-c:jerry,elaine', '5',
            '--loglevel:kramer=DEBUG',
            '--flag',
            '--logfile=foo', '-Q', 'bar', 'jerry',
            'elaine', 'kramer',
            '--', '.disable_rate_limits=1',
        ])
        p.parse()
        it = multi_args(p, cmd='COMMAND', append='*AP*',
                        prefix='*P*', suffix='*S*')
        nodes = list(it)

        def assert_line_in(name, args):
            assert name in {n.name for n in nodes}
            argv = None
            for node in nodes:
                if node.name == name:
                    argv = node.argv
            assert argv
            for arg in args:
                assert arg in argv

        assert_line_in(
            '*P*jerry@*S*',
            ['COMMAND', '-n *P*jerry@*S*', '-Q bar',
             '-c 5', '--flag', '--logfile=foo',
             '-- .disable_rate_limits=1', '*AP*'],
        )
        assert_line_in(
            '*P*elaine@*S*',
            ['COMMAND', '-n *P*elaine@*S*', '-Q bar',
             '-c 5', '--flag', '--logfile=foo',
             '-- .disable_rate_limits=1', '*AP*'],
        )
        assert_line_in(
            '*P*kramer@*S*',
            ['COMMAND', '--loglevel=DEBUG', '-n *P*kramer@*S*',
             '-Q bar', '--flag', '--logfile=foo',
             '-- .disable_rate_limits=1', '*AP*'],
        )
        expand = nodes[0].expander
        assert expand('%h') == '*P*jerry@*S*'
        assert expand('%n') == '*P*jerry'
        nodes2 = list(multi_args(p, cmd='COMMAND', append='',
                                 prefix='*P*', suffix='*S*'))
        assert nodes2[0].argv[-1] == '-- .disable_rate_limits=1'

        p2 = NamespacedOptionParser(['10', '-c:1', '5'])
        p2.parse()
        nodes3 = list(multi_args(p2, cmd='COMMAND'))

        def _args(name, *args):
            return args + (
                '--pidfile={0}.pid'.format(name),
                '--logfile={0}%I.log'.format(name),
                '--executable={0}'.format(sys.executable),
                '',
            )

        assert len(nodes3) == 10
        assert nodes3[0].name == '*****@*****.**'
        assert nodes3[0].argv == (
            'COMMAND', '-c 5', '-n [email protected]') + _args('celery1')
        for i, worker in enumerate(nodes3[1:]):
            assert worker.name == '*****@*****.**' % (i + 2)
            node_i = 'celery%s' % (i + 2,)
            assert worker.argv == (
                'COMMAND',
                '-n %[email protected]' % (node_i,)) + _args(node_i)

        nodes4 = list(multi_args(p2, cmd='COMMAND', suffix='""'))
        assert len(nodes4) == 10
        assert nodes4[0].name == 'celery1@'
        assert nodes4[0].argv == (
            'COMMAND', '-c 5', '-n celery1@') + _args('celery1')

        p3 = NamespacedOptionParser(['foo@', '-c:foo', '5'])
        p3.parse()
        nodes5 = list(multi_args(p3, cmd='COMMAND', suffix='""'))
        assert nodes5[0].name == 'foo@'
        assert nodes5[0].argv == (
            'COMMAND', '-c 5', '-n foo@') + _args('foo')

        p4 = NamespacedOptionParser(['foo', '-Q:1', 'test'])
        p4.parse()
        nodes6 = list(multi_args(p4, cmd='COMMAND', suffix='""'))
        assert nodes6[0].name == 'foo@'
        assert nodes6[0].argv == (
            'COMMAND', '-Q test', '-n foo@') + _args('foo')

        p5 = NamespacedOptionParser(['foo@bar', '-Q:1', 'test'])
        p5.parse()
        nodes7 = list(multi_args(p5, cmd='COMMAND', suffix='""'))
        assert nodes7[0].name == 'foo@bar'
        assert nodes7[0].argv == (
            'COMMAND', '-Q test', '-n foo@bar') + _args('foo')

        p6 = NamespacedOptionParser(['foo@bar', '-Q:0', 'test'])
        p6.parse()
        with pytest.raises(KeyError):
            list(multi_args(p6))
Esempio n. 6
0
 def test_optmerge(self):
     p = NamespacedOptionParser(['foo', 'test'])
     p.parse()
     p.options = {'x': 'y'}
     r = p.optmerge('foo')
     assert r['x'] == 'y'
Esempio n. 7
0
 def test_optmerge(self):
     p = NamespacedOptionParser(['foo', 'test'])
     p.parse()
     p.options = {'x': 'y'}
     r = p.optmerge('foo')
     self.assertEqual(r['x'], 'y')