예제 #1
0
def test_preload_options():
    from pyramid_celery import celery_app
    from celery.bin.celery import Command

    with mock.patch('pyramid_celery.bootstrap') as boot:
        cmd = Command(celery_app)
        cmd.setup_app_from_commandline(['--ini', 'tests/configs/dev.ini'])
        boot.assert_called_with('tests/configs/dev.ini')

    with mock.patch('pyramid_celery.bootstrap') as boot:
        cmd = Command(celery_app)
        cmd.setup_app_from_commandline([
            '--ini',
            'tests/configs/dev.ini',
            '--ini-var',
            'foo=bar',
            '--ini-var=bar=baz',
        ])
예제 #2
0
 def setup(self):
     self.out = WhateverIO()
     self.err = WhateverIO()
     self.cmd = Command(self.app, stdout=self.out, stderr=self.err)
예제 #3
0
class test_Command(AppCase):

    def test_Error_repr(self):
        x = Error('something happened')
        self.assertIsNotNone(x.status)
        self.assertTrue(x.reason)
        self.assertTrue(str(x))

    def setup(self):
        self.out = WhateverIO()
        self.err = WhateverIO()
        self.cmd = Command(self.app, stdout=self.out, stderr=self.err)

    def test_error(self):
        self.cmd.out = Mock()
        self.cmd.error('FOO')
        self.cmd.out.assert_called()

    def test_out(self):
        f = Mock()
        self.cmd.out('foo', f)

    def test_call(self):

        def ok_run():
            pass

        self.cmd.run = ok_run
        self.assertEqual(self.cmd(), EX_OK)

        def error_run():
            raise Error('error', EX_FAILURE)
        self.cmd.run = error_run
        self.assertEqual(self.cmd(), EX_FAILURE)

    def test_run_from_argv(self):
        with self.assertRaises(NotImplementedError):
            self.cmd.run_from_argv('prog', ['foo', 'bar'])

    def test_pretty_list(self):
        self.assertEqual(self.cmd.pretty([])[1], '- empty -')
        self.assertIn('bar', self.cmd.pretty(['foo', 'bar'])[1])

    def test_pretty_dict(self):
        self.assertIn(
            'OK',
            str(self.cmd.pretty({'ok': 'the quick brown fox'})[0]),
        )
        self.assertIn(
            'ERROR',
            str(self.cmd.pretty({'error': 'the quick brown fox'})[0]),
        )

    def test_pretty(self):
        self.assertIn('OK', str(self.cmd.pretty('the quick brown')))
        self.assertIn('OK', str(self.cmd.pretty(object())))
        self.assertIn('OK', str(self.cmd.pretty({'foo': 'bar'})))
예제 #4
0
class test_Command(AppCase):

    def test_Error_repr(self):
        x = Error('something happened')
        self.assertIsNotNone(x.status)
        self.assertTrue(x.reason)
        self.assertTrue(str(x))

    def setup(self):
        self.out = WhateverIO()
        self.err = WhateverIO()
        self.cmd = Command(self.app, stdout=self.out, stderr=self.err)

    def test_show_help(self):
        self.cmd.run_from_argv = Mock()
        self.assertEqual(self.cmd.show_help('foo'), EX_USAGE)
        self.cmd.run_from_argv.assert_called_with(
                self.cmd.prog_name, ['foo', '--help']
        )

    def test_error(self):
        self.cmd.out = Mock()
        self.cmd.error('FOO')
        self.assertTrue(self.cmd.out.called)

    def test_out(self):
        f = Mock()
        self.cmd.out('foo', f)

    def test_call(self):
        self.cmd.run = Mock()
        self.cmd.run.return_value = None
        self.assertEqual(self.cmd(), EX_OK)

        self.cmd.run.side_effect = Error('error', EX_FAILURE)
        self.assertEqual(self.cmd(), EX_FAILURE)

    def test_run_from_argv(self):
        with self.assertRaises(NotImplementedError):
            self.cmd.run_from_argv('prog', ['foo', 'bar'])
        self.assertEqual(self.cmd.prog_name, 'prog')

    def test_prettify_list(self):
        self.assertEqual(self.cmd.prettify([])[1], '- empty -')
        self.assertIn('bar', self.cmd.prettify(['foo', 'bar'])[1])

    def test_prettify_dict(self):
        self.assertIn('OK',
            str(self.cmd.prettify({'ok': 'the quick brown fox'})[0]))
        self.assertIn('ERROR',
            str(self.cmd.prettify({'error': 'the quick brown fox'})[0]))

    def test_prettify(self):
        self.assertIn('OK', str(self.cmd.prettify('the quick brown')))
        self.assertIn('OK', str(self.cmd.prettify(object())))
        self.assertIn('OK', str(self.cmd.prettify({'foo': 'bar'})))
예제 #5
0
class test_Command:
    def test_Error_repr(self):
        x = Error('something happened')
        assert x.status is not None
        assert x.reason
        assert str(x)

    def setup(self):
        self.out = WhateverIO()
        self.err = WhateverIO()
        self.cmd = Command(self.app, stdout=self.out, stderr=self.err)

    def test_error(self):
        self.cmd.out = Mock()
        self.cmd.error('FOO')
        self.cmd.out.assert_called()

    def test_out(self):
        f = Mock()
        self.cmd.out('foo', f)

    def test_call(self):
        def ok_run():
            pass

        self.cmd.run = ok_run
        assert self.cmd() == EX_OK

        def error_run():
            raise Error('error', EX_FAILURE)

        self.cmd.run = error_run
        assert self.cmd() == EX_FAILURE

    def test_run_from_argv(self):
        with pytest.raises(NotImplementedError):
            self.cmd.run_from_argv('prog', ['foo', 'bar'])

    def test_pretty_list(self):
        assert self.cmd.pretty([])[1] == '- empty -'
        assert 'bar', self.cmd.pretty(['foo' in 'bar'][1])

    def test_pretty_dict(self, text='the quick brown fox'):
        assert 'OK' in str(self.cmd.pretty({'ok': text})[0])
        assert 'ERROR' in str(self.cmd.pretty({'error': text})[0])

    def test_pretty(self):
        assert 'OK' in str(self.cmd.pretty('the quick brown'))
        assert 'OK' in str(self.cmd.pretty(object()))
        assert 'OK' in str(self.cmd.pretty({'foo': 'bar'}))
예제 #6
0
class test_Command(AppCase):

    def test_Error_repr(self):
        x = Error('something happened')
        self.assertIsNotNone(x.status)
        self.assertTrue(x.reason)
        self.assertTrue(str(x))

    def setup(self):
        self.out = WhateverIO()
        self.err = WhateverIO()
        self.cmd = Command(self.app, stdout=self.out, stderr=self.err)

    def test_show_help(self):
        self.cmd.run_from_argv = Mock()
        self.assertEqual(self.cmd.show_help('foo'), EX_USAGE)
        self.cmd.run_from_argv.assert_called_with(
            self.cmd.prog_name, ['foo', '--help']
        )

    def test_error(self):
        self.cmd.out = Mock()
        self.cmd.error('FOO')
        self.assertTrue(self.cmd.out.called)

    def test_out(self):
        f = Mock()
        self.cmd.out('foo', f)
        f.write.assert_called_with('foo\n')
        self.cmd.out('foo\n', f)

    def test_call(self):
        self.cmd.run = Mock()
        self.cmd.run.return_value = None
        self.assertEqual(self.cmd(), EX_OK)

        self.cmd.run.side_effect = Error('error', EX_FAILURE)
        self.assertEqual(self.cmd(), EX_FAILURE)

    def test_run_from_argv(self):
        with self.assertRaises(NotImplementedError):
            self.cmd.run_from_argv('prog', ['foo', 'bar'])
        self.assertEqual(self.cmd.prog_name, 'prog')

    def test_prettify_list(self):
        self.assertEqual(self.cmd.prettify([])[1], '- empty -')
        self.assertIn('bar', self.cmd.prettify(['foo', 'bar'])[1])

    def test_prettify_dict(self):
        self.assertIn(
            'OK',
            str(self.cmd.prettify({'ok': 'the quick brown fox'})[0]),
        )
        self.assertIn(
            'ERROR',
            str(self.cmd.prettify({'error': 'the quick brown fox'})[0]),
        )

    def test_prettify(self):
        self.assertIn('OK', str(self.cmd.prettify('the quick brown')))
        self.assertIn('OK', str(self.cmd.prettify(object())))
        self.assertIn('OK', str(self.cmd.prettify({'foo': 'bar'})))
예제 #7
0
class test_Command(AppCase):
    def test_Error_repr(self):
        x = Error("something happened")
        self.assertIsNotNone(x.status)
        self.assertTrue(x.reason)
        self.assertTrue(str(x))

    def setup(self):
        self.out = WhateverIO()
        self.err = WhateverIO()
        self.cmd = Command(self.app, stdout=self.out, stderr=self.err)

    def test_error(self):
        self.cmd.out = Mock()
        self.cmd.error("FOO")
        self.assertTrue(self.cmd.out.called)

    def test_out(self):
        f = Mock()
        self.cmd.out("foo", f)

    def test_call(self):
        def ok_run():
            pass

        self.cmd.run = ok_run
        self.assertEqual(self.cmd(), EX_OK)

        def error_run():
            raise Error("error", EX_FAILURE)

        self.cmd.run = error_run
        self.assertEqual(self.cmd(), EX_FAILURE)

    def test_run_from_argv(self):
        with self.assertRaises(NotImplementedError):
            self.cmd.run_from_argv("prog", ["foo", "bar"])

    def test_pretty_list(self):
        self.assertEqual(self.cmd.pretty([])[1], "- empty -")
        self.assertIn("bar", self.cmd.pretty(["foo", "bar"])[1])

    def test_pretty_dict(self):
        self.assertIn("OK", str(self.cmd.pretty({"ok": "the quick brown fox"})[0]))
        self.assertIn("ERROR", str(self.cmd.pretty({"error": "the quick brown fox"})[0]))

    def test_pretty(self):
        self.assertIn("OK", str(self.cmd.pretty("the quick brown")))
        self.assertIn("OK", str(self.cmd.pretty(object())))
        self.assertIn("OK", str(self.cmd.pretty({"foo": "bar"})))
예제 #8
0
class test_Command(AppCase):
    def test_Error_repr(self):
        x = Error("something happened")
        self.assertIsNotNone(x.status)
        self.assertTrue(x.reason)
        self.assertTrue(str(x))

    def setup(self):
        self.out = WhateverIO()
        self.err = WhateverIO()
        self.cmd = Command(self.app, stdout=self.out, stderr=self.err)

    def test_show_help(self):
        self.cmd.run_from_argv = Mock()
        self.assertEqual(self.cmd.show_help("foo"), EX_USAGE)
        self.cmd.run_from_argv.assert_called_with(self.cmd.prog_name,
                                                  ["foo", "--help"])

    def test_error(self):
        self.cmd.out = Mock()
        self.cmd.error("FOO")
        self.assertTrue(self.cmd.out.called)

    def test_out(self):
        f = Mock()
        self.cmd.out("foo", f)
        f.write.assert_called_with("foo\n")
        self.cmd.out("foo\n", f)

    def test_call(self):
        self.cmd.run = Mock()
        self.cmd.run.return_value = None
        self.assertEqual(self.cmd(), EX_OK)

        self.cmd.run.side_effect = Error("error", EX_FAILURE)
        self.assertEqual(self.cmd(), EX_FAILURE)

    def test_run_from_argv(self):
        with self.assertRaises(NotImplementedError):
            self.cmd.run_from_argv("prog", ["foo", "bar"])
        self.assertEqual(self.cmd.prog_name, "prog")

    def test_prettify_list(self):
        self.assertEqual(self.cmd.prettify([])[1], "- empty -")
        self.assertIn("bar", self.cmd.prettify(["foo", "bar"])[1])

    def test_prettify_dict(self):
        self.assertIn("OK",
                      str(self.cmd.prettify({"ok": "the quick brown fox"})[0]))
        self.assertIn(
            "ERROR",
            str(self.cmd.prettify({"error": "the quick brown fox"})[0]))

    def test_prettify(self):
        self.assertIn("OK", str(self.cmd.prettify("the quick brown")))
        self.assertIn("OK", str(self.cmd.prettify(object())))
        self.assertIn("OK", str(self.cmd.prettify({"foo": "bar"})))
예제 #9
0
파일: test_celery.py 프로젝트: Scalr/celery
class test_Command:

    def test_Error_repr(self):
        x = Error('something happened')
        assert x.status is not None
        assert x.reason
        assert str(x)

    def setup(self):
        self.out = WhateverIO()
        self.err = WhateverIO()
        self.cmd = Command(self.app, stdout=self.out, stderr=self.err)

    def test_error(self):
        self.cmd.out = Mock()
        self.cmd.error('FOO')
        self.cmd.out.assert_called()

    def test_out(self):
        f = Mock()
        self.cmd.out('foo', f)

    def test_call(self):

        def ok_run():
            pass

        self.cmd.run = ok_run
        assert self.cmd() == EX_OK

        def error_run():
            raise Error('error', EX_FAILURE)
        self.cmd.run = error_run
        assert self.cmd() == EX_FAILURE

    def test_run_from_argv(self):
        with pytest.raises(NotImplementedError):
            self.cmd.run_from_argv('prog', ['foo', 'bar'])

    def test_pretty_list(self):
        assert self.cmd.pretty([])[1] == '- empty -'
        assert 'bar', self.cmd.pretty(['foo' in 'bar'][1])

    def test_pretty_dict(self, text='the quick brown fox'):
        assert 'OK' in str(self.cmd.pretty({'ok': text})[0])
        assert 'ERROR' in str(self.cmd.pretty({'error': text})[0])

    def test_pretty(self):
        assert 'OK' in str(self.cmd.pretty('the quick brown'))
        assert 'OK' in str(self.cmd.pretty(object()))
        assert 'OK' in str(self.cmd.pretty({'foo': 'bar'}))
예제 #10
0
class test_Command(AppCase):

    def test_Error_repr(self):
        x = Error("something happened")
        self.assertIsNotNone(x.status)
        self.assertTrue(x.reason)
        self.assertTrue(str(x))

    def setup(self):
        self.out = WhateverIO()
        self.err = WhateverIO()
        self.cmd = Command(self.app, stdout=self.out, stderr=self.err)

    def test_show_help(self):
        self.cmd.run_from_argv = Mock()
        self.assertEqual(self.cmd.show_help("foo"), EX_USAGE)
        self.cmd.run_from_argv.assert_called_with(
                self.cmd.prog_name, ["foo", "--help"]
        )

    def test_error(self):
        self.cmd.out = Mock()
        self.cmd.error("FOO")
        self.assertTrue(self.cmd.out.called)

    def test_out(self):
        f = Mock()
        self.cmd.out("foo", f)
        f.write.assert_called_with("foo\n")
        self.cmd.out("foo\n", f)

    def test_call(self):
        self.cmd.run = Mock()
        self.cmd.run.return_value = None
        self.assertEqual(self.cmd(), EX_OK)

        self.cmd.run.side_effect = Error("error", EX_FAILURE)
        self.assertEqual(self.cmd(), EX_FAILURE)

    def test_run_from_argv(self):
        with self.assertRaises(NotImplementedError):
            self.cmd.run_from_argv("prog", ["foo", "bar"])
        self.assertEqual(self.cmd.prog_name, "prog")

    def test_prettify_list(self):
        self.assertEqual(self.cmd.prettify([])[1], "- empty -")
        self.assertIn("bar", self.cmd.prettify(["foo", "bar"])[1])

    def test_prettify_dict(self):
        self.assertIn("OK",
            str(self.cmd.prettify({"ok": "the quick brown fox"})[0]))
        self.assertIn("ERROR",
            str(self.cmd.prettify({"error": "the quick brown fox"})[0]))

    def test_prettify(self):
        self.assertIn("OK", str(self.cmd.prettify("the quick brown")))
        self.assertIn("OK", str(self.cmd.prettify(object())))
        self.assertIn("OK", str(self.cmd.prettify({"foo": "bar"})))