Пример #1
0
def lark_to_object_value_node(tree: "Tree") -> "ObjectValueNode":
    """
    Creates and returns an ObjectValueNode 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: an ObjectValueNode instance extracted from the parsing of the tree
    :rtype: ObjectValueNode
    """
    return ObjectValueNode(
        fields=[child.value for child in tree.children],
        location=lark_to_location_node(tree.meta),
    )
Пример #2
0
def _parse_object_value(object_value_ast: dict) -> "ObjectValueNode":
    """
    Creates and returns an ObjectValueNode instance from an object value's JSON
    AST libgraphqlparser representation.
    :param object_value_ast: object value's JSON AST libgraphqlparser
    representation
    :type object_value_ast: dict
    :return: an ObjectValueNode instance equivalent to the JSON AST
    representation
    :rtype: ObjectValueNode
    """
    return ObjectValueNode(
        fields=_parse_object_fields(object_value_ast["fields"]),
        location=_parse_location(object_value_ast["loc"]),
    )
Пример #3
0
def _parse_object_value(object_value_ast: dict, validators: Validators,
                        path: Path) -> "ObjectValueNode":
    """
    Creates and returns an ObjectValueNode instance from an object value's JSON
    AST libgraphqlparser representation.
    :param object_value_ast: object value's JSON AST libgraphqlparser
    representation
    :type object_value_ast: dict
    :param validators: the validators to use in order to validate this definition
    :type validators: Validators
    :param path: a Path object that contains the current field path
    :type path: Path
    :return: an ObjectValueNode instance equivalent to the JSON AST
    representation
    :rtype: ObjectValueNode
    """
    return ObjectValueNode(
        fields=_parse_object_fields(object_value_ast["fields"], validators,
                                    path),
        location=_parse_location(object_value_ast["loc"]),
    )
Пример #4
0
def test_objectvaluenode__init__():
    object_value_node = ObjectValueNode(fields="objectValueFields",
                                        location="objectValueLocation")
    assert object_value_node.fields == "objectValueFields"
    assert object_value_node.location == "objectValueLocation"
Пример #5
0
def test_objectfieldnode__repr__(object_field_node, expected):
    assert object_field_node.__repr__() == expected


def test_objectvaluenode__init__():
    object_value_node = ObjectValueNode(fields="objectValueFields",
                                        location="objectValueLocation")
    assert object_value_node.fields == "objectValueFields"
    assert object_value_node.location == "objectValueLocation"


@pytest.mark.parametrize(
    "object_value_node,other,expected",
    [
        (
            ObjectValueNode(fields="objectValueFields",
                            location="objectValueLocation"),
            Ellipsis,
            False,
        ),
        (
            ObjectValueNode(fields="objectValueFields",
                            location="objectValueLocation"),
            ObjectValueNode(fields="objectValueFieldsBis",
                            location="objectValueLocation"),
            False,
        ),
        (
            ObjectValueNode(fields="objectValueFields",
                            location="objectValueLocation"),
            ObjectValueNode(fields="objectValueFields",
                            location="objectValueLocationBis"),