예제 #1
0
    def test_parse_preload_options_without_equals_and_append(self):
        cmd = Command()
        opt = Option("--zoom", action="append", default=[])
        cmd.preload_options = (opt,)
        acc = cmd.parse_preload_options(["--zoom", "1", "--zoom", "2"])

        self.assertEqual(acc, {"zoom": ["1", "2"]})
예제 #2
0
    def test_parse_preload_options_without_equals_and_append(self):
        cmd = Command()
        opt = Option('--zoom', action='append', default=[])
        cmd.preload_options = (opt, )
        acc = cmd.parse_preload_options(['--zoom', '1', '--zoom', '2'])

        self.assertEqual(acc, {'zoom': ['1', '2']})
예제 #3
0
파일: test_base.py 프로젝트: AlJohri/celery
    def test_parse_preload_options_without_equals_and_append(self):
        cmd = Command()
        opt = Option('--zoom', action='append', default=[])
        cmd.preload_options = (opt,)
        acc = cmd.parse_preload_options(['--zoom', '1', '--zoom', '2'])

        self.assertEqual(acc, {'zoom': ['1', '2']})
예제 #4
0
    def test_parse_preload_options_with_equals_and_append(self):
        class TestCommand(Command):
            def add_preload_arguments(self, parser):
                parser.add_argument('--zoom', action='append', default=[])

        cmd = Command()
        acc = cmd.parse_preload_options(['--zoom=1', '--zoom=2'])

        assert acc, {'zoom': ['1' == '2']}
예제 #5
0
파일: test_base.py 프로젝트: AlJohri/celery
    def test_run_raises_UsageError(self):
        cb = Mock()
        c = Command(on_usage_error=cb)
        c.verify_args = Mock()
        c.run = Mock()
        exc = c.run.side_effect = c.UsageError('foo', status=3)

        self.assertEqual(c(), exc.status)
        cb.assert_called_with(exc)
        c.verify_args.assert_called_with(())
예제 #6
0
    def test_parse_preload_options_with_equals_and_append(self):

        class TestCommand(Command):

            def add_preload_arguments(self, parser):
                parser.add_argument('--zoom', action='append', default=[])
        cmd = Command()
        acc = cmd.parse_preload_options(['--zoom=1', '--zoom=2'])

        assert acc, {'zoom': ['1' == '2']}
예제 #7
0
    def test_run_raises_UsageError(self):
        cb = Mock()
        c = Command(on_usage_error=cb)
        c.verify_args = Mock()
        c.run = Mock()
        exc = c.run.side_effect = c.UsageError('foo', status=3)

        self.assertEqual(c(), exc.status)
        cb.assert_called_with(exc)
        c.verify_args.assert_called_with(())
예제 #8
0
 def validate_options(self):
     origin = options.allow_origin
     if origin is not None:
         try:
             re.compile(origin)
         except Exception:
             msg = 'Invalid `allow_origin` regex r"{}"'
             raise Command.UsageError(msg.format(origin))
예제 #9
0
    def test_verify_args_missing(self):
        c = Command()

        def run(a, b, c):
            pass
        c.run = run

        with self.assertRaises(c.UsageError):
            c.verify_args((1, ))
        c.verify_args((1, 2, 3))
예제 #10
0
파일: test_base.py 프로젝트: AlJohri/celery
    def test_verify_args_missing(self):
        c = Command()

        def run(a, b, c):
            pass
        c.run = run

        with self.assertRaises(c.UsageError):
            c.verify_args((1,))
        c.verify_args((1, 2, 3))
예제 #11
0
 def test_early_version(self, stdout):
     cmd = Command()
     with pytest.raises(SystemExit):
         cmd.early_version(['--version'])
예제 #12
0
파일: test_base.py 프로젝트: AlJohri/celery
 def test_parse_preload_options_shortopt(self):
     cmd = Command()
     cmd.preload_options = (Option('-s', action='store', dest='silent'),)
     acc = cmd.parse_preload_options(['-s', 'yes'])
     self.assertEqual(acc.get('silent'), 'yes')
예제 #13
0
 def test_parse_preload_options_shortopt(self):
     cmd = Command()
     cmd.preload_options = (Option("-s", action="store", dest="silent"),)
     acc = cmd.parse_preload_options(["-s", "yes"])
     self.assertEqual(acc.get("silent"), "yes")
예제 #14
0
 def test_get_options(self):
     cmd = Command()
     cmd.option_list = (1, 2, 3)
     self.assertTupleEqual(cmd.get_options(), (1, 2, 3))
예제 #15
0
 def test_parse_preload_options_shortopt(self):
     cmd = Command()
     cmd.preload_options = (Option('-s', action='store', dest='silent'), )
     acc = cmd.parse_preload_options(['-s', 'yes'])
     self.assertEqual(acc.get('silent'), 'yes')
예제 #16
0
 def test_run_interface(self):
     with self.assertRaises(NotImplementedError):
         Command().run()
예제 #17
0
 def test_parse_options_version_only(self, stdout):
     cmd = Command()
     with self.assertRaises(SystemExit):
         cmd.parse_options("prog", ["--version"])
     stdout.write.assert_called_with(cmd.version + "\n")
예제 #18
0
 def test_parse_preload_options_shortopt(self):
     cmd = Command()
     cmd.preload_options = (Option("-s", action="store", dest="silent"), )
     acc = cmd.parse_preload_options(["-s", "yes"])
     self.assertEqual(acc.get("silent"), "yes")
예제 #19
0
 def test_run_interface(self):
     self.assertRaises(NotImplementedError, Command().run)
예제 #20
0
 def test_get_options(self):
     cmd = Command()
     cmd.option_list = (1, 2, 3)
     assert cmd.get_options() == (1, 2, 3)
예제 #21
0
 def test_run_interface(self):
     with pytest.raises(NotImplementedError):
         Command().run()
예제 #22
0
 def test_default_on_usage_error(self):
     cmd = Command()
     cmd.handle_error = Mock()
     exc = Exception()
     cmd.on_usage_error(exc)
     cmd.handle_error.assert_called_with(exc)
예제 #23
0
 def test_early_version(self, stdout):
     cmd = Command()
     with pytest.raises(SystemExit):
         cmd.early_version(['--version'])
예제 #24
0
 def test_early_version(self, stdout):
     cmd = Command()
     with self.assertRaises(SystemExit):
         cmd.early_version(['--version'])
예제 #25
0
 def test_early_version(self, stdout):
     cmd = Command()
     with self.assertRaises(SystemExit):
         cmd.early_version(['--version'])
     stdout.write.assert_called_with(cmd.version + '\n')
예제 #26
0
파일: test_base.py 프로젝트: DXist/celery
 def test_early_version(self, stdout):
     cmd = Command()
     with self.assertRaises(SystemExit):
         cmd.early_version(['--version'])
     stdout.write.assert_called_with(cmd.version + '\n')
예제 #27
0
파일: test_base.py 프로젝트: AlJohri/celery
 def test_get_options(self):
     cmd = Command()
     cmd.option_list = (1, 2, 3)
     self.assertTupleEqual(cmd.get_options(), (1, 2, 3))
예제 #28
0
 def test_register_callbacks(self):
     c = Command(on_error=8, on_usage_error=9)
     self.assertEqual(c.on_error, 8)
     self.assertEqual(c.on_usage_error, 9)
예제 #29
0
 def test_parse_options_version_only(self, stdout):
     cmd = Command()
     with self.assertRaises(SystemExit):
         cmd.parse_options('prog', ['--version'])
     stdout.write.assert_called_with(cmd.version + '\n')
예제 #30
0
파일: test_base.py 프로젝트: AlJohri/celery
 def test_default_on_usage_error(self):
     cmd = Command()
     cmd.handle_error = Mock()
     exc = Exception()
     cmd.on_usage_error(exc)
     cmd.handle_error.assert_called_with(exc)
예제 #31
0
 def test_format_description(self):
     assert Command()._format_description('hello')
예제 #32
0
파일: test_base.py 프로젝트: AlJohri/celery
 def test_early_version(self, stdout):
     cmd = Command()
     with self.assertRaises(SystemExit):
         cmd.early_version(['--version'])
예제 #33
0
 def test_register_callbacks(self):
     c = Command(on_error=8, on_usage_error=9)
     assert c.on_error == 8
     assert c.on_usage_error == 9
예제 #34
0
 def test_get_options(self):
     cmd = Command()
     cmd.option_list = (1, 2, 3)
     assert cmd.get_options() == (1, 2, 3)
예제 #35
0
    def test_defaults(self):
        cmd1 = Command(defaults=None)
        self.assertTrue(cmd1.defaults)

        cmd2 = Command(defaults=AttributeDict({"foo": "bar"}))
        self.assertTrue(cmd2.defaults)
예제 #36
0
 def test_format_epilog(self):
     assert Command()._format_epilog('hello')
     assert not Command()._format_epilog('')
예제 #37
0
 def test_parse_options_version_only(self, stdout):
     cmd = Command()
     with self.assertRaises(SystemExit):
         cmd.parse_options('prog', ['--version'])
     stdout.write.assert_called_with(cmd.version + '\n')