def lark_to_non_null_type_node(tree: "Tree") -> "NonNullTypeNode": """ Creates and returns a NonNullTypeNode instance extracted from the parsing of the tree instance. :param tree: the Tree to parse in order to extract the proper node :type tree: Tree :return: a NonNullTypeNode instance extracted from the parsing of the tree :rtype: NonNullTypeNode """ return NonNullTypeNode(type=tree.children[0].value, location=lark_to_location_node(tree.meta))
def _parse_type( type_ast: dict ) -> Union["ListTypeNode", "NonNullTypeNode", "NamedTypeNode"]: """ Creates and returns a TypeNode from a type's JSON AST libgraphqlparser representation. :param type_ast: type's JSON AST libgraphqlparser representation :type type_ast: dict :return: a TypeNode instance equivalent to the JSON AST representation :rtype: Union[ListTypeNode, NonNullTypeNode, NamedTypeNode] """ if type_ast["kind"] == "ListType": return ListTypeNode( type=_parse_type(type_ast["type"]), location=_parse_location(type_ast["loc"]), ) if type_ast["kind"] == "NonNullType": return NonNullTypeNode( type=_parse_type(type_ast["type"]), location=_parse_location(type_ast["loc"]), ) return _parse_named_type(type_ast)
def test_nonnulltypenode__init__(): non_null_type_node = NonNullTypeNode(type="nonNullTypeType", location="nonNullTypeLocation") assert non_null_type_node.type == "nonNullTypeType" assert non_null_type_node.location == "nonNullTypeLocation"
def test_listtypenode__repr__(list_type_node, expected): assert list_type_node.__repr__() == expected def test_nonnulltypenode__init__(): non_null_type_node = NonNullTypeNode(type="nonNullTypeType", location="nonNullTypeLocation") assert non_null_type_node.type == "nonNullTypeType" assert non_null_type_node.location == "nonNullTypeLocation" @pytest.mark.parametrize( "non_null_type_node,other,expected", [ ( NonNullTypeNode(type="nonNullTypeType", location="nonNullTypeLocation"), Ellipsis, False, ), ( NonNullTypeNode(type="nonNullTypeType", location="nonNullTypeLocation"), NonNullTypeNode(type="nonNullTypeTypeBis", location="nonNullTypeLocation"), False, ), ( NonNullTypeNode(type="nonNullTypeType", location="nonNullTypeLocation"), NonNullTypeNode(type="nonNullTypeType", location="nonNullTypeLocationBis"),