def test_serializes_output_boolean():
    assert GraphQLBoolean.serialize('string') is True
    assert GraphQLBoolean.serialize('') is False
    assert GraphQLBoolean.serialize(1) is True
    assert GraphQLBoolean.serialize(0) is False
    assert GraphQLBoolean.serialize(True) is True
    assert GraphQLBoolean.serialize(False) is False
示例#2
0
 def _parse_literal(s: str):
     return GraphQLBoolean.parse_literal(parse_value_to_ast(s))
    def serializes_output_as_boolean():
        assert GraphQLBoolean.serialize(1) is True
        assert GraphQLBoolean.serialize(0) is False
        assert GraphQLBoolean.serialize(True) is True
        assert GraphQLBoolean.serialize(False) is False

        with raises(GraphQLError) as exc_info:
            GraphQLBoolean.serialize(nan)
        assert str(exc_info.value) == (
            "Boolean cannot represent a non boolean value: nan")

        with raises(GraphQLError) as exc_info:
            GraphQLBoolean.serialize("")
        assert str(exc_info.value) == (
            "Boolean cannot represent a non boolean value: ''")

        with raises(GraphQLError) as exc_info:
            GraphQLBoolean.serialize("True")
        assert str(exc_info.value) == (
            "Boolean cannot represent a non boolean value: 'True'")

        with raises(GraphQLError) as exc_info:
            GraphQLBoolean.serialize([False])
        assert str(exc_info.value) == (
            "Boolean cannot represent a non boolean value: [False]")

        with raises(GraphQLError) as exc_info:
            GraphQLBoolean.serialize({})
        assert str(exc_info.value) == (
            "Boolean cannot represent a non boolean value: {}")
示例#4
0
    def serializes_output_as_boolean():
        assert GraphQLBoolean.serialize(1) is True
        assert GraphQLBoolean.serialize(0) is False
        assert GraphQLBoolean.serialize(True) is True
        assert GraphQLBoolean.serialize(False) is False
        with raises(TypeError, match="not an acceptable base type"):
            # you can't subclass bool in Python
            assert GraphQLBoolean.serialize(
                type("Boolean", (bool, ), {})(True)) is True

        with raises(GraphQLError) as exc_info:
            GraphQLBoolean.serialize(nan)
        assert str(exc_info.value) == (
            "Boolean cannot represent a non boolean value: nan")

        with raises(GraphQLError) as exc_info:
            GraphQLBoolean.serialize("")
        assert str(exc_info.value) == (
            "Boolean cannot represent a non boolean value: ''")

        with raises(GraphQLError) as exc_info:
            GraphQLBoolean.serialize("True")
        assert str(exc_info.value) == (
            "Boolean cannot represent a non boolean value: 'True'")

        with raises(GraphQLError) as exc_info:
            GraphQLBoolean.serialize([False])
        assert str(exc_info.value) == (
            "Boolean cannot represent a non boolean value: [False]")

        with raises(GraphQLError) as exc_info:
            GraphQLBoolean.serialize({})
        assert str(exc_info.value) == (
            "Boolean cannot represent a non boolean value: {}")
    def serializes_output_as_boolean():
        assert GraphQLBoolean.serialize(1) is True
        assert GraphQLBoolean.serialize(0) is False
        assert GraphQLBoolean.serialize(True) is True
        assert GraphQLBoolean.serialize(False) is False

        with raises(Exception) as exc_info:
            GraphQLBoolean.serialize(nan)
        assert str(exc_info.value) == (
            'Boolean cannot represent a non boolean value: nan')

        with raises(Exception) as exc_info:
            GraphQLBoolean.serialize('')
        assert str(exc_info.value) == (
            "Boolean cannot represent a non boolean value: ''")

        with raises(Exception) as exc_info:
            GraphQLBoolean.serialize('True')
        assert str(exc_info.value) == (
            "Boolean cannot represent a non boolean value: 'True'")

        with raises(Exception) as exc_info:
            GraphQLBoolean.serialize([False])
        assert str(exc_info.value) == (
            'Boolean cannot represent a non boolean value: [False]')

        with raises(Exception) as exc_info:
            GraphQLBoolean.serialize({})
        assert str(exc_info.value) == (
            'Boolean cannot represent a non boolean value: {}')