Exemplo n.º 1
0
 def test_from_argparse_ast_empty(self) -> None:
     """
     Tests `argparse_ast` empty condition
     """
     self.assertEqual(
         emit.to_code(
             emit.argparse_function(
                 parse.argparse_ast(
                     FunctionDef(
                         body=[],
                         arguments_args=None,
                         identifier_name=None,
                         stmt=None,
                     )),
                 emit_default_doc=True,
             )).rstrip("\n"),
         "def set_cli_args(argument_parser):\n{tab}{body}".format(
             tab=tab,
             body=tab.join((
                 '"""\n',
                 "Set CLI arguments\n\n",
                 ":param argument_parser: argument parser\n",
                 ":type argument_parser: ```ArgumentParser```\n\n",
                 ":returns: argument_parser\n",
                 ":rtype: ```ArgumentParser```\n",
                 '"""\n',
                 "argument_parser.description = ''\n",
                 "return argument_parser",
             )),
         ),
     )
Exemplo n.º 2
0
 def test_from_argparse_ast(self) -> None:
     """
     Tests whether `argparse_ast` produces `intermediate_repr_no_default_doc`
           from `argparse_func_ast`"""
     ir = parse.argparse_ast(argparse_func_ast)
     del ir["_internal"]  # Not needed for this test
     self.assertDictEqual(ir, intermediate_repr_no_default_doc)
Exemplo n.º 3
0
 def test_to_class_from_argparse_action_append_ast(self) -> None:
     """
     Tests whether a class from an argparse function with `nargs` set
     """
     run_ast_test(
         self,
         emit.class_(
             parse.argparse_ast(argparse_func_action_append_ast),
         ),
         gold=class_nargs_ast,
     )
Exemplo n.º 4
0
 def test_to_class_from_argparse_ast(self) -> None:
     """
     Tests whether `class_` produces `class_ast` given `argparse_func_ast`
     """
     run_ast_test(
         self,
         gen_ast=emit.class_(
             parse.argparse_ast(argparse_func_ast), emit_default_doc=True
         ),
         gold=class_ast,
     )
Exemplo n.º 5
0
    def test_from_argparse_with_extra_body_to_argparse_with_extra_body(self) -> None:
        """ Tests if this can make the roundtrip from a full argparse function to a argparse full function """

        ir = parse.argparse_ast(argparse_func_with_body_ast)
        func = emit.argparse_function(
            ir,
            emit_default_doc=False,
            emit_default_doc_in_return=False,
        )
        run_ast_test(
            self,
            func,
            argparse_func_with_body_ast,
        )
Exemplo n.º 6
0
 def test_from_argparse_ast(self) -> None:
     """
     Tests whether `argparse_ast` produces `intermediate_repr_no_default_doc`
           from `argparse_func_ast`"""
     self.assertDictEqual(parse.argparse_ast(argparse_func_ast),
                          intermediate_repr_no_default_doc)