def lark_to_directive_definition_node( tree: "Tree") -> "DirectiveDefinitionNode": """ Creates and returns a DirectiveDefinitionNode 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 DirectiveDefinitionNode instance extracted from the parsing of the tree :rtype: DirectiveDefinitionNode """ node_info = _extract_node_info( tree.children, types_to_value=[ "description", "name", "arguments_definition", "directive_locations", ], types_to_ignore=["DIRECTIVE", "ON"], ) return DirectiveDefinitionNode( description=node_info.get("description"), name=node_info["name"], arguments=node_info.get("arguments_definition") or [], locations=node_info.get("directive_locations") or [], location=lark_to_location_node(tree.meta), )
def test_directivedefinitionnode__init__(): directive_definition_node = DirectiveDefinitionNode( name="directiveDefinitionName", locations="directiveDefinitionLocations", description="directiveDefinitionDescription", arguments="directiveDefinitionArguments", location="directiveDefinitionLocation", ) assert directive_definition_node.name == "directiveDefinitionName" assert ( directive_definition_node.locations == "directiveDefinitionLocations" ) assert ( directive_definition_node.description == "directiveDefinitionDescription" ) assert ( directive_definition_node.arguments == "directiveDefinitionArguments" ) assert directive_definition_node.location == "directiveDefinitionLocation"
], ) def test_coerce_input_output(input_val, exception, output_val): scalar = MAC() if exception: with pytest.raises(exception): scalar.coerce_input(input_val) with pytest.raises(exception): scalar.coerce_output(input_val) else: assert scalar.coerce_output(input_val) == output_val assert scalar.coerce_input(input_val) == output_val @pytest.mark.parametrize( "input_val,output_val", [ ( DirectiveDefinitionNode( arguments=[], name="directive", locations=None ), UNDEFINED_VALUE, ), (StringValueNode(value="nok"), UNDEFINED_VALUE), (StringValueNode(value=None), UNDEFINED_VALUE), (StringValueNode(value="00:0a:95:9d:68:16"), "00:0a:95:9d:68:16"), ], ) def test_parse_literal(input_val, output_val): assert MAC().parse_literal(input_val) == output_val
== "directiveDefinitionDescription" ) assert ( directive_definition_node.arguments == "directiveDefinitionArguments" ) assert directive_definition_node.location == "directiveDefinitionLocation" @pytest.mark.parametrize( "directive_definition_node,other,expected", [ ( DirectiveDefinitionNode( name="directiveDefinitionName", locations="directiveDefinitionLocations", description="directiveDefinitionDescription", arguments="directiveDefinitionArguments", location="directiveDefinitionLocation", ), Ellipsis, False, ), ( DirectiveDefinitionNode( name="directiveDefinitionName", locations="directiveDefinitionLocations", description="directiveDefinitionDescription", arguments="directiveDefinitionArguments", location="directiveDefinitionLocation", ), DirectiveDefinitionNode(