Esempio n. 1
0
    def test_param2ast_with_assign_dict(self) -> None:
        """ Check that `param2ast` behaves correctly with dict type """

        run_ast_test(
            self,
            param2ast(("menthol", {
                "typ": "dict"
            }), ),
            gold=AnnAssign(
                annotation=set_slice(Name("dict", Load())),
                simple=1,
                target=Name("menthol", Store()),
                value=Dict(keys=[], values=[], expr=None),
                expr=None,
                expr_target=None,
                expr_annotation=None,
            ),
        )
Esempio n. 2
0
    def test_param2ast_with_wrapped_default(self) -> None:
        """ Check that `param2ast` behaves correctly with a wrapped default """

        run_ast_test(
            self,
            param2ast(
                ("zion", {"typ": None, "default": set_value(NoneStr)}),
            ),
            gold=AnnAssign(
                annotation=Name("object", Load()),
                simple=1,
                target=Name("zion", Store()),
                value=set_value(None),
                expr=None,
                expr_target=None,
                expr_annotation=None,
            ),
        )
Esempio n. 3
0
    def test_param2ast_with_assign(self) -> None:
        """ Check that `param2ast` behaves correctly with a non annotated (typeless) input """

        run_ast_test(
            self,
            param2ast(("zion", {
                "typ": None
            }), ),
            gold=AnnAssign(
                annotation=Name("object", Load()),
                simple=1,
                target=Name("zion", Store()),
                value=set_value(None),
                expr=None,
                expr_target=None,
                expr_annotation=None,
            ),
        )
Esempio n. 4
0
    def test_param2ast_with_bad_default(self) -> None:
        """ Check that `param2ast` behaves correctly with a bad default """

        run_ast_test(
            self,
            param2ast(
                (
                    "stateful_metrics",
                    {"typ": "NoneType", "default": "the `Model`'s metrics"},
                ),
            ),
            gold=AnnAssign(
                annotation=Name("NoneType", Load()),
                simple=1,
                target=Name("stateful_metrics", Store()),
                value=set_value("```the `Model`'s metrics```"),
                expr=None,
                expr_annotation=None,
                expr_target=None,
            ),
        )