Exemplo n.º 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"]})
Exemplo n.º 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']})
Exemplo n.º 3
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']})
Exemplo n.º 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']}
Exemplo n.º 5
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(())
Exemplo n.º 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']}
Exemplo n.º 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(())
Exemplo n.º 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))
Exemplo n.º 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))
Exemplo n.º 10
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))
Exemplo n.º 11
0
 def test_early_version(self, stdout):
     cmd = Command()
     with pytest.raises(SystemExit):
         cmd.early_version(['--version'])
Exemplo n.º 12
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')
Exemplo n.º 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")
Exemplo n.º 14
0
 def test_get_options(self):
     cmd = Command()
     cmd.option_list = (1, 2, 3)
     self.assertTupleEqual(cmd.get_options(), (1, 2, 3))
Exemplo n.º 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')
Exemplo n.º 16
0
 def test_run_interface(self):
     with self.assertRaises(NotImplementedError):
         Command().run()
Exemplo n.º 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")
Exemplo 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")
Exemplo n.º 19
0
 def test_run_interface(self):
     self.assertRaises(NotImplementedError, Command().run)
Exemplo n.º 20
0
 def test_get_options(self):
     cmd = Command()
     cmd.option_list = (1, 2, 3)
     assert cmd.get_options() == (1, 2, 3)
Exemplo n.º 21
0
 def test_run_interface(self):
     with pytest.raises(NotImplementedError):
         Command().run()
Exemplo n.º 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)
Exemplo n.º 23
0
 def test_early_version(self, stdout):
     cmd = Command()
     with pytest.raises(SystemExit):
         cmd.early_version(['--version'])
Exemplo n.º 24
0
 def test_early_version(self, stdout):
     cmd = Command()
     with self.assertRaises(SystemExit):
         cmd.early_version(['--version'])
Exemplo n.º 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')
Exemplo n.º 26
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')
Exemplo n.º 27
0
 def test_get_options(self):
     cmd = Command()
     cmd.option_list = (1, 2, 3)
     self.assertTupleEqual(cmd.get_options(), (1, 2, 3))
Exemplo n.º 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)
Exemplo n.º 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')
Exemplo n.º 30
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)
Exemplo n.º 31
0
 def test_format_description(self):
     assert Command()._format_description('hello')
Exemplo n.º 32
0
 def test_early_version(self, stdout):
     cmd = Command()
     with self.assertRaises(SystemExit):
         cmd.early_version(['--version'])
Exemplo n.º 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
Exemplo n.º 34
0
 def test_get_options(self):
     cmd = Command()
     cmd.option_list = (1, 2, 3)
     assert cmd.get_options() == (1, 2, 3)
Exemplo n.º 35
0
    def test_defaults(self):
        cmd1 = Command(defaults=None)
        self.assertTrue(cmd1.defaults)

        cmd2 = Command(defaults=AttributeDict({"foo": "bar"}))
        self.assertTrue(cmd2.defaults)
Exemplo n.º 36
0
 def test_format_epilog(self):
     assert Command()._format_epilog('hello')
     assert not Command()._format_epilog('')
Exemplo n.º 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')