def test_serializes_output_string():
    assert GraphQLString.serialize('string') == 'string'
    assert GraphQLString.serialize(1) == '1'
    assert GraphQLString.serialize(-1.1) == '-1.1'
    assert GraphQLString.serialize(True) == 'true'
    assert GraphQLString.serialize(False) == 'false'
    assert GraphQLString.serialize(u'\U0001F601') == u'\U0001F601'
Esempio n. 2
0
 def _parse_literal(s: str):
     return GraphQLString.parse_literal(parse_value_to_ast(s))
    def serializes_output_as_string():
        assert GraphQLString.serialize("string") == "string"
        assert GraphQLString.serialize(1) == "1"
        assert GraphQLString.serialize(-1.1) == "-1.1"
        assert GraphQLString.serialize(True) == "true"
        assert GraphQLString.serialize(False) == "false"

        class StringableObjValue:
            def __str__(self):
                return "something useful"

        assert GraphQLString.serialize(
            StringableObjValue()) == "something useful"

        with raises(GraphQLError) as exc_info:
            GraphQLString.serialize(nan)
        assert str(exc_info.value) == "String cannot represent value: nan"

        with raises(GraphQLError) as exc_info:
            GraphQLString.serialize([1])
        assert str(exc_info.value) == "String cannot represent value: [1]"

        with raises(GraphQLError) as exc_info:
            GraphQLString.serialize({})
        assert str(exc_info.value) == "String cannot represent value: {}"

        with raises(GraphQLError) as exc_info:
            GraphQLString.serialize({"value_of": "value_of string"})
        assert (str(exc_info.value) == "String cannot represent value:"
                " {'value_of': 'value_of string'}")
Esempio n. 4
0
    def serializes_output_as_string():
        assert GraphQLString.serialize("string") == "string"
        assert GraphQLString.serialize(1) == "1"
        assert GraphQLString.serialize(-1.1) == "-1.1"
        assert GraphQLString.serialize(True) == "true"
        assert GraphQLString.serialize(False) == "false"

        class StringableObjValue:
            def __str__(self):
                return "something useful"

        assert GraphQLString.serialize(
            StringableObjValue()) == "something useful"

        with raises(Exception) as exc_info:
            GraphQLString.serialize(nan)
        assert str(exc_info.value) == ("String cannot represent value: nan")

        with raises(Exception) as exc_info:
            GraphQLString.serialize([1])
        assert str(exc_info.value) == ("String cannot represent value: [1]")

        with raises(Exception) as exc_info:
            GraphQLString.serialize({})
        assert str(exc_info.value) == ("String cannot represent value: {}")
    def serializes_output_as_string():
        assert GraphQLString.serialize('string') == 'string'
        assert GraphQLString.serialize(1) == '1'
        assert GraphQLString.serialize(-1.1) == '-1.1'
        assert GraphQLString.serialize(True) == 'true'
        assert GraphQLString.serialize(False) == 'false'

        class StringableObjValue:
            def __str__(self):
                return 'something useful'

        assert GraphQLString.serialize(
            StringableObjValue()) == 'something useful'

        with raises(Exception) as exc_info:
            GraphQLString.serialize(nan)
        assert str(exc_info.value) == ('String cannot represent value: nan')

        with raises(Exception) as exc_info:
            GraphQLString.serialize([1])
        assert str(exc_info.value) == ('String cannot represent value: [1]')

        with raises(Exception) as exc_info:
            GraphQLString.serialize({})
        assert str(exc_info.value) == ('String cannot represent value: {}')