Ejemplo n.º 1
0
    def test_positional_with_aliases(self):
        msg = "Aliases for positional not yet supported"
        with self.assertRaises(ValueError, msg=msg):

            @command
            @argument("arg", positional=True, aliases=["a"])
            def foo(arg="default"):
                return arg

            # validation happens on building parser time so let's build one
            parser = ContainedParser()
            add_command(parser, foo)
Ejemplo n.º 2
0
    def test_positional_with_default(self):
        msg = ("We explicitly do not support positional "
               "with default because it is confusing")
        with self.assertRaises(ValueError, msg=msg):

            @command
            @argument("arg", positional=True)
            def foo(arg="default"):
                return arg

            # validation happens on building parser time so let's build one
            parser = ContainedParser()
            add_command(parser, foo)
Ejemplo n.º 3
0
    def _test(self, command_function, arguments, expected_result):
        if isinstance(arguments, str):
            arguments = arguments.split()

        parser = ContainedParser()
        add_command(parser, command_function)
        try:
            parsed = parser.parse_args(args=arguments)
        except Exception as e:
            if inspect.isclass(expected_result):
                self.assertIsInstance(e, expected_result)
            elif isinstance(expected_result, ParseError):
                self.assertEqual(str(e), str(expected_result))
            else:
                raise
        else:
            command_function = find_command(parser, parsed, True)
            self.assertEqual(command_function(), expected_result)