Пример #1
0
    def test_struct_list_scalars(self):
        schema = {
            "type": "object",
            "properties": {
                "Consistent": {
                    "type": "boolean",
                },
                "Args": {
                    "type": "array",
                    "items": {
                        "type": "string"
                    }
                }
            }
        }

        argument = CustomArgument('test', schema=schema)
        argument.create_argument_object()
        p = argument.argument_object

        returned = self.simplify(p, 'Consistent=true,Args=foo1,foo2')
        self.assertEqual(returned, {
            'Consistent': True,
            'Args': ['foo1', 'foo2']
        })
Пример #2
0
    def test_list_structure_list_scalar_3(self):
        arg = CustomArgument('foo',
                             schema={
                                 'type': 'array',
                                 'items': {
                                     'type': 'object',
                                     'properties': {
                                         'Name': {
                                             'type': 'string'
                                         },
                                         'Args': {
                                             'type': 'array',
                                             'items': {
                                                 'type': 'string'
                                             }
                                         }
                                     }
                                 }
                             })
        arg.create_argument_object()
        p = arg.argument_object

        expected = [{
            "Name": "foo",
            "Args": ["a", "k1=v1", "b"]
        }, {
            "Name": "bar",
            "Args": ["baz"]
        }]

        simplified = self.simplify(
            p, ["Name=foo,Args=[a,k1=v1,b]", "Name=bar,Args=baz"])

        self.assertEqual(simplified, expected)
Пример #3
0
    def test_list_structure_list_scalar_3(self):
        arg = CustomArgument('foo', schema={
            'type': 'array',
            'items': {
                'type': 'object',
                'properties': {
                    'Name': {
                        'type': 'string'
                    },
                    'Args': {
                        'type': 'array',
                        'items': {
                            'type': 'string'
                        }
                    }
                }
            }
        })
        arg.create_argument_object()
        p = arg.argument_object

        expected = [
            {"Name": "foo",
             "Args": ["a", "k1=v1", "b"]},
            {"Name": "bar",
             "Args": ["baz"]}
        ]

        simplified = self.simplify(p, [
            "Name=foo,Args=[a,k1=v1,b]",
            "Name=bar,Args=baz"
        ])

        self.assertEqual(simplified, expected)
Пример #4
0
    def test_gen_structure_list_scalar_docs(self):
        schema = {
            "type": "object",
            "properties": {
                "Consistent": {
                    "type": "boolean",
                },
                "Args": {
                    "type": "array",
                    "items": {
                        "type": "string"
                    }
                }
            }
        }

        argument = CustomArgument('test', schema=schema)
        argument.create_argument_object()

        p = argument.argument_object
        help_command = OperationHelpCommand(self.session,
                                            p.operation,
                                            None, {p.cli_name: argument},
                                            name='foo',
                                            event_class='bar')
        help_command.param_shorthand.add_example_fn(p.cli_name, help_command)

        doc_string = p.example_fn(p)

        self.assertIn('Key value pairs', doc_string)
        self.assertIn('Consistent=boolean1,Args=string1,string2', doc_string)
Пример #5
0
    def test_gen_structure_list_scalar_docs(self):
        schema = {
            "type": "object",
            "properties": {
                "Consistent": {
                    "type": "boolean",
                },
                "Args": {
                    "type": "array",
                    "items": {
                        "type": "string"
                    }
                }
            }
        }

        argument = CustomArgument('test', schema=schema)
        argument.create_argument_object()

        p = argument.argument_object
        help_command = OperationHelpCommand(
            self.session, p.operation, None, {p.cli_name: argument},
            name='foo', event_class='bar')
        help_command.param_shorthand.add_example_fn(p.cli_name, help_command)

        doc_string = p.example_fn(p)

        self.assertIn('Key value pairs', doc_string)
        self.assertIn('Consistent=boolean1,Args=string1,string2', doc_string)
Пример #6
0
    def arg_table(self):
        arg_table = OrderedDict()
        for arg_data in self.ARG_TABLE:
            custom_argument = CustomArgument(**arg_data)

            # If a custom schema was passed in, create the argument object
            # so that it can be validated and docs can be generated
            if 'schema' in arg_data:
                custom_argument.create_argument_object()

            arg_table[arg_data['name']] = custom_argument
        return arg_table
Пример #7
0
    def arg_table(self):
        arg_table = OrderedDict()
        for arg_data in self.ARG_TABLE:
            custom_argument = CustomArgument(**arg_data)

            # If a custom schema was passed in, create the argument object
            # so that it can be validated and docs can be generated
            if 'schema' in arg_data:
                custom_argument.create_argument_object()

            arg_table[arg_data['name']] = custom_argument
        return arg_table
Пример #8
0
    def test_struct_list_scalars(self):
        schema = {
            "type": "object",
            "properties": {
                "Consistent": {
                    "type": "boolean",
                },
                "Args": {
                    "type": "array",
                    "items": {
                        "type": "string"
                    }
                }
            }
        }
        argument_model = create_argument_model_from_schema(schema)
        cli_argument = CustomArgument('test', argument_model=argument_model)

        returned = self.shorthand(cli_argument,
                                  'Consistent=true,Args=foo1,foo2',
                                  'process-cli-arg.foo.bar')
        self.assertEqual(returned, {
            'Consistent': True,
            'Args': ['foo1', 'foo2']
        })
Пример #9
0
 def _create_argument_object(self, option_name, option_params):
     return CustomArgument(
         option_name, help_text=option_params.get('help', ''),
         dest=option_params.get('dest'),default=option_params.get('default'),
         action=option_params.get('action'),
         required=option_params.get('required'),
         choices=option_params.get('choices'))
Пример #10
0
    def test_struct_list_scalars(self):
        schema = {
            "type": "object",
            "properties": {
                "Consistent": {
                    "type": "boolean",
                },
                "Args": {
                    "type": "array",
                    "items": {
                        "type": "string"
                    }
                }
            }
        }

        argument = CustomArgument('test', schema=schema)
        argument.create_argument_object()
        p = argument.argument_object

        returned = self.simplify(p, 'Consistent=true,Args=foo1,foo2')
        self.assertEqual(returned, {'Consistent': True,
                                    'Args': ['foo1', 'foo2']})
Пример #11
0
    def _build_arg_table(self):
        arg_table = OrderedDict()
        self._session.emit('building-arg-table.%s' % self.NAME,
                           arg_table=self.ARG_TABLE)
        for arg_data in self.ARG_TABLE:

            # If a custom schema was passed in, create the argument_model
            # so that it can be validated and docs can be generated.
            if 'schema' in arg_data:
                argument_model = create_argument_model_from_schema(
                    arg_data.pop('schema'))
                arg_data['argument_model'] = argument_model
            custom_argument = CustomArgument(**arg_data)

            arg_table[arg_data['name']] = custom_argument
        return arg_table
Пример #12
0
 def test_complete_positional_argument(self):
     commands = {
         'subcommands': {
             'foo': {'subcommands': {
                 'bar': {'arguments': [
                     'baz',
                     CustomArgument('bin', positional_arg=True)
                 ]}
             }}
         },
         'arguments': []
     }
     completer = Completer(
         self.clidriver_creator.create_clidriver(commands))
     self.assert_completion(completer, 'aws foo bar --bin ', [])
     self.assert_completion(completer, 'aws foo bar --bin blah --',
                            ['--baz'])
Пример #13
0
    def test_list_structure_list_scalar_custom_arg(self):
        schema = {
            'type': 'array',
            'items': {
                'type': 'object',
                'properties': {
                    'Name': {
                        'type': 'string'
                    },
                    'Args': {
                        'type': 'array',
                        'items': {
                            'type': 'string'
                        }
                    }
                }
            }
        }
        argument_model = create_argument_model_from_schema(schema)
        cli_argument = CustomArgument('foo', argument_model=argument_model)

        expected = [{
            "Name": "foo",
            "Args": ["a", "k1=v1", "b"]
        }, {
            "Name": "bar",
            "Args": ["baz"]
        }, {
            "Name": "single_kv",
            "Args": ["key=value"]
        }, {
            "Name": "single_v",
            "Args": ["value"]
        }]

        simplified = self.simplify(cli_argument, [
            "Name=foo,Args=[a,k1=v1,b]", "Name=bar,Args=baz",
            "Name=single_kv,Args=[key=value]", "Name=single_v,Args=[value]"
        ])

        self.assertEqual(simplified, expected)
Пример #14
0
    def test_gen_structure_list_scalar_docs(self):
        schema = {
            "type": "object",
            "properties": {
                "Consistent": {
                    "type": "boolean",
                },
                "Args": {
                    "type": "array",
                    "items": {
                        "type": "string"
                    }
                }
            }
        }
        argument_model = create_argument_model_from_schema(schema)
        cli_argument = CustomArgument('test', argument_model=argument_model)

        generated_example = self.get_generated_example_for(cli_argument)
        self.assertIn('Key value pairs', generated_example)
        self.assertIn('Consistent=boolean1,Args=string1,string2',
                      generated_example)
Пример #15
0
 def assert_custom_shape_type(self, schema, expected_type):
     argument_model = create_argument_model_from_schema(schema)
     argument = CustomArgument('test', argument_model=argument_model)
     actual_structure = detect_shape_structure(argument.argument_model)
     self.assertEqual(actual_structure, expected_type)
Пример #16
0
 def arg_table(self):
     arg_table = OrderedDict()
     for arg_data in self.ARG_TABLE:
         custom_argument = CustomArgument(**arg_data)
         arg_table[arg_data['name']] = custom_argument
     return arg_table
Пример #17
0
 def assert_custom_shape_type(self, schema, expected_type):
     argument = CustomArgument('test', schema=schema)
     argument.create_argument_object()
     actual_structure = detect_shape_structure(argument.argument_object)
     self.assertEqual(actual_structure, expected_type)
Пример #18
0
 def assert_custom_shape_type(self, schema, expected_type):
     argument = CustomArgument('test', schema=schema)
     argument.create_argument_object()
     actual_structure = detect_shape_structure(argument.argument_object)
     self.assertEqual(actual_structure, expected_type)