def test_from_docstring_numpydoc(self) -> None:
     """
     Tests whether `docstring` produces `intermediate_repr_no_default_doc`
           from `docstring_numpydoc_str`"""
     ir, returns = parse.docstring(docstring_numpydoc_str,
                                   return_tuple=True,
                                   emit_default_doc=False)
     self.assertTrue(returns)
     self.assertDictEqual(ir, intermediate_repr_no_default_doc)
 def test_to_class_from_docstring_str(self) -> None:
     """
     Tests whether `class_` produces `class_ast` given `docstring_str`
     """
     run_ast_test(
         self,
         emit.class_(
             parse.docstring(docstring_str, emit_default_doc=True),
             emit_default_doc=True,
         ),
         gold=class_ast,
     )
 def test_from_docstring_numpydoc_only_params(self) -> None:
     """
     Tests whether `docstring` produces `intermediate_repr_no_default_doc`
           from `docstring_numpydoc_only_params_str`"""
     ir, returns = parse.docstring(
         docstring_numpydoc_only_params_str,
         return_tuple=True,
         emit_default_doc=False,
     )
     self.assertFalse(returns)
     gold = deepcopy(intermediate_repr_no_default_doc)
     del gold["returns"]
     gold.update({"doc": "", "returns": None})
     self.assertDictEqual(ir, gold)
 def test_from_docstring_numpydoc_only_doc_str(self) -> None:
     """
     Tests whether `docstring` produces `intermediate_repr_no_default_doc`
           from `docstring_numpydoc_only_doc_str`"""
     ir, returns = parse.docstring(docstring_numpydoc_only_doc_str,
                                   return_tuple=True)
     self.assertFalse(returns)
     self.assertDictEqual(
         ir,
         {
             "doc": intermediate_repr_no_default_doc["doc"],
             "name": None,
             "params": OrderedDict(),
             "returns": None,
             "type": "static",
         },
     )
    def test_to_function_emit_as_kwonlyargs(self) -> None:
        """
        Tests whether `function` produces method with keyword only arguments
        """

        function_def = deepcopy(
            next(
                filter(
                    rpartial(isinstance, FunctionDef),
                    ast.parse(class_with_method_types_str.replace("self", "self, *"))
                    .body[0]
                    .body,
                )
            )
        )
        # Reindent docstring
        function_def.body[0].value.value = "\n{tab}{docstring}\n{tab}".format(
            tab=tab,
            docstring=reindent(
                deindent(ast.get_docstring(function_def)),
            ),
        )

        function_name = function_def.name
        function_type = get_function_type(function_def)

        gen_ast = emit.function(
            parse.docstring(docstring_str),
            function_name=function_name,
            function_type=function_type,
            emit_default_doc=False,
            inline_types=True,
            emit_separating_tab=PY3_8,
            indent_level=0,
            emit_as_kwonlyargs=True,
        )

        gen_ast.body[0].value.value = "\n{tab}{docstring}".format(
            tab=tab, docstring=reindent(deindent(ast.get_docstring(gen_ast)))
        )

        run_ast_test(
            self,
            gen_ast=gen_ast,
            gold=function_def,
        )
    def test_to_function(self) -> None:
        """
        Tests whether `function` produces method from `class_with_method_types_ast` given `docstring_str`
        """

        function_def = deepcopy(
            next(
                filter(
                    rpartial(isinstance, FunctionDef), class_with_method_types_ast.body
                )
            )
        )
        # Reindent docstring
        function_def.body[0].value.value = "\n{tab}{docstring}\n{tab}".format(
            tab=tab,
            docstring=reindent(
                deindent(ast.get_docstring(function_def).translate("\n\t")),
            ),
        )

        function_name = function_def.name
        function_type = get_function_type(function_def)

        gen_ast = emit.function(
            parse.docstring(docstring_str),
            function_name=function_name,
            function_type=function_type,
            emit_default_doc=False,
            inline_types=True,
            emit_separating_tab=PY3_8,
            indent_level=0,
            emit_as_kwonlyargs=False,
        )

        gen_ast.body[0].value.value = "\n{tab}{docstring}".format(
            tab=tab, docstring=reindent(deindent(ast.get_docstring(gen_ast)))
        )

        run_ast_test(
            self,
            gen_ast=gen_ast,
            gold=function_def,
        )