Пример #1
0
    def test_get_arguments(self) -> None:
        input_string = """
        :type name: string
        :param name: The Bucket's name identifier. This **must** be set.

        **Request Syntax**::
        ::

            response = client.abort_multipart_upload(
                name='string'
            )

        """
        service_name_mock = MagicMock()
        docstring_parser = DocstringParser(service_name_mock, "ClassName",
                                           "method_name", [])
        result = docstring_parser.get_arguments(input_string)
        assert len(result) == 1
        assert result[0].name == "name"
        assert result[0].type_annotation == Type.str

        input_string = """
        :type name string
        :param name The Bucket's name identifier. This **must** be set.

        **Request Syntax**::
        ::

            response = client.abort_multipart_upload(
                name='string'

        """
        assert docstring_parser.get_arguments(input_string)
Пример #2
0
def parse_method(parent_name: str, name: str, method: FunctionType,
                 service_name: ServiceName) -> Method:
    """
    Parse method to a structure.

    Arguments:
        parent_name -- Parent class name.
        method -- Inspect method.

    Returns:
        Method structure.
    """
    logger = get_logger()
    docstring = textwrap.dedent(inspect.getdoc(method) or "")
    method_name = f"{parent_name}.{name}"

    logger.debug(f"Slow parsing of {method_name}: {len(docstring)} chars")
    prefix = f"{get_class_prefix(parent_name)}{get_class_prefix(name)}"
    arg_spec_parser = ArgSpecParser(prefix, service_name)

    arguments = get_method_arguments_stub(service_name, parent_name, name)
    if arguments is None:
        arguments = arg_spec_parser.get_arguments(parent_name, name, method)
        docstring_parser = DocstringParser(service_name, parent_name, name,
                                           arguments)
        arguments = docstring_parser.get_arguments(docstring)

    return_type = arg_spec_parser.get_return_type(parent_name, name)
    if return_type is None:
        return_type = DocstringParser(service_name, parent_name, name,
                                      []).get_return_type(docstring)

    return Method(name=name, arguments=arguments, return_type=return_type)
Пример #3
0
 def test_get_arguments(self) -> None:
     input_string = """
     :type name: string
     :param name: The Bucket's name identifier. This **must** be set.
     """
     service_name_mock = MagicMock()
     docstring_parser = DocstringParser(service_name_mock, "ClassName",
                                        "method_name", [])
     result = docstring_parser.get_arguments(input_string)
     assert len(result) == 1
     assert result[0].name == "name"
     assert result[0].type_annotation == Type.str
Пример #4
0
 def test_get_arguments(self) -> None:
     input_string = """
     :type name: string
     :param name: The Bucket's name identifier. This **must** be set.
     """
     service_name_mock = MagicMock()
     docstring_parser = DocstringParser(
         service_name_mock, "ClassName", "method_name", []
     )
     result = docstring_parser.get_arguments(input_string)
     self.assertEqual(len(result), 1)
     self.assertEqual(result[0].name, "name")
     self.assertEqual(result[0].type, Type.str)
def parse_method(
    parent_name: str, name: str, method: MethodType, service_name: ServiceName
) -> Method:
    """
    Parse method to a structure.

    Arguments:
        parent_name -- Parent class name.
        method -- Inspect method.

    Returns:
        Method structure.
    """
    logger = get_logger()
    docstring = textwrap.dedent(inspect.getdoc(method) or "")
    method_name = f"{parent_name}.{name}"

    logger.debug(f"Slow parsing of {method_name}: {len(docstring)} chars")
    prefix = f"{get_class_prefix(parent_name)}{get_class_prefix(name)}"
    arg_spec_parser = ArgSpecParser(prefix, service_name)

    arguments = get_method_arguments_stub(service_name, parent_name, name)
    if arguments is None:
        arguments = arg_spec_parser.get_arguments(parent_name, name, method)
        docstring_parser = DocstringParser(service_name, parent_name, name, arguments)
        arguments = docstring_parser.get_arguments(docstring)

    # do not add kwonly flag to resource generators
    if len(arguments) > 1 and not name[0].isupper():
        arguments.insert(1, Argument.kwflag())

    return_type = arg_spec_parser.get_return_type(parent_name, name)
    if return_type is None:
        return_type = DocstringParser(service_name, parent_name, name, []).get_return_type(
            docstring
        )

    result = Method(name=name, arguments=arguments, return_type=return_type)
    result.request_type_annotation = result.get_request_type_annotation(
        f"{parent_name}{get_class_prefix(name)}RequestTypeDef"
    )
    return result