def test_converts_input_objects(): value = OrderedDict([('foo', 3), ('bar', 'HELLO')]) assert ast_from_value(value) == ast.ObjectValue(fields=[ ast.ObjectField(name=ast.Name('foo'), value=ast.IntValue('3')), ast.ObjectField(name=ast.Name('bar'), value=ast.StringValue('HELLO')) ]) input_obj = GraphQLInputObjectType( 'MyInputObj', { 'foo': GraphQLInputObjectField(GraphQLFloat), 'bar': GraphQLInputObjectField(my_enum) }) assert ast_from_value(value, input_obj) == ast.ObjectValue(fields=[ ast.ObjectField(name=ast.Name('foo'), value=ast.FloatValue('3.0')), ast.ObjectField(name=ast.Name('bar'), value=ast.EnumValue('HELLO')) ])
def test_it_converts_numeric_values_to_float_asts(): assert ast_from_value(123, GraphQLFloat) == ast.FloatValue('123.0') assert ast_from_value(123.0, GraphQLFloat) == ast.FloatValue('123.0') assert ast_from_value(123.5, GraphQLFloat) == ast.FloatValue('123.5') assert ast_from_value(1e4, GraphQLFloat) == ast.FloatValue('10000.0') assert ast_from_value(1e40, GraphQLFloat) == ast.FloatValue('1e+40')
def test_converts_numeric_values_to_asts(): assert ast_from_value(123) == ast.IntValue('123') assert ast_from_value(123.0) == ast.IntValue('123') assert ast_from_value(123.5) == ast.FloatValue('123.5') assert ast_from_value(1e4) == ast.IntValue('10000') assert ast_from_value(1e40) == ast.FloatValue('1e+40')