def test_parse_value_it_parses_block_strings(): assert_node_equal( parse_value('["""long""" "short"]'), _ast.ListValue( loc=(0, 20), values=[ _ast.StringValue(loc=(1, 11), value="long", block=True), _ast.StringValue(loc=(12, 19), value="short"), ], ), )
def test_it_parses_type_with_description_string(): assert_node_equal( parse( """ "Description" type Hello { world: String }""", allow_type_system=True, ), _ast.Document( loc=(0, 45), definitions=[ _ast.ObjectTypeDefinition( loc=(1, 45), name=_name((20, 25), "Hello"), interfaces=[], directives=[], description=_ast.StringValue(loc=(1, 14), value="Description"), fields=[ _field( (30, 43), _name((30, 35), "world"), _type((37, 43), "String"), ) ], ) ], ), )
def test_it_parses_type_with_description_multi_line_string(): body = ''' """ Description """ # Even with comments between them type Hello { world: String }''' assert_node_equal( parse(body, allow_type_system=True), _ast.Document( loc=(0, 85), definitions=[ _ast.ObjectTypeDefinition( loc=(1, 85), name=_name((60, 65), "Hello"), interfaces=[], directives=[], description=_ast.StringValue(loc=(1, 20), value="Description", block=True), fields=[ _field( (70, 83), _name((70, 75), "world"), _type((77, 83), "String"), ) ], ) ], ), )
def test_provided_invalid_value(): arg = Argument("foo", Int) field = Field("test", Int, [arg]) node = _test_node(_ast.StringValue(value="foo")) with pytest.raises(CoercionError) as exc_info: assert coerce_argument_values(field, node) assert str(exc_info.value) == ( 'Argument "foo" of type "Int" was provided invalid value "foo" ' "(Invalid literal StringValue)" )
def test_parse_value_it_parses_list_values(): assert_node_equal( parse_value('[123 "abc"]'), _ast.ListValue( loc=(0, 11), values=[ _ast.IntValue(loc=(1, 4), value="123"), _ast.StringValue(loc=(5, 10), value="abc"), ], ), )
def test_it_parses_multi_bytes_characters(): source = """ # This comment has a \u0A0A multi-byte character. { field(arg: "Has a \u0A0A multi-byte character.") } """ tree = parse(source, no_location=True) assert_node_equal( tree.definitions[0].selection_set.selections, # type: ignore [ _ast.Field( name=_ast.Name(value="field"), arguments=[ _ast.Argument( name=_ast.Name(value="arg"), value=_ast.StringValue( value="Has a \u0A0A multi-byte character." ), ) ], ) ], )
123.5, Int, ValueError("Int cannot represent non integer value: 123.5"), ), ( 1e40, Int, ValueError( "Int cannot represent non 32-bit signed integer: 1e+40"), ), (-1, Float, _ast.IntValue(value="-1")), (123.0, Float, _ast.IntValue(value="123")), (123.5, Float, _ast.FloatValue(value="123.5")), (1e4, Float, _ast.IntValue(value="10000")), (1e40, Float, _ast.FloatValue(value="1e+40")), ("hello", String, _ast.StringValue(value="hello")), ("VALUE", String, _ast.StringValue(value="VALUE")), ("VA\nLUE", String, _ast.StringValue(value="VA\nLUE")), (123, String, _ast.StringValue(value="123")), (False, String, _ast.StringValue(value="false")), (None, String, _ast.NullValue()), ("hello", ID, _ast.StringValue(value="hello")), (-1, ID, _ast.IntValue(value="-1")), (123, ID, _ast.IntValue(value="123")), ("01", ID, _ast.StringValue(value="01")), (None, ID, _ast.NullValue()), (42, CustomScalar, _ast.NullValue()), ("42.42", CustomScalar, _ast.FloatValue(value="42.42")), (42.42, CustomScalar, _ast.FloatValue(value="42.42")), (MAX_INT + 2, CustomScalar, _ast.FloatValue(value="2147483649")), ("foo", CustomScalar, _ast.StringValue(value="foo")),
_ast.Name("foo", " ... ", (0, 1)), _ast.Name("foo", " ", (0, 2)), False, ), ( _ast.Name("bar", " ... ", (0, 1)), _ast.Name("foo", " ", (0, 1)), False, ), ( _ast.Field( name=_ast.Name(value="field"), arguments=[ _ast.Argument( name=_ast.Name(value="arg"), value=_ast.StringValue( value="Has a \u0A0A multi-byte character."), ) ], ), _ast.Field( name=_ast.Name(value="field"), arguments=[ _ast.Argument( name=_ast.Name(value="arg"), value=_ast.StringValue( value="Has a \u0A0A multi-byte character."), ) ], ), True, ),