示例#1
0
    def _pb(self):
        """
        Get the Argument representation of the String, as defined in the Mercury
        protocol.
        """

        return Message.Argument(type=Message.Argument.DATA, data=self._native)
示例#2
0
    def testItShouldBuildNullFromArgument(self):
        argument = Message.Argument(type=Message.Argument.NULL)

        type = reflection.types.ReflectedType.fromArgument(
            argument, reflector=self.reflector)

        assert isinstance(type, reflection.types.ReflectedNull)
示例#3
0
    def testItShouldBuildStringFromArgument(self):
        argument = Message.Argument(type=Message.Argument.STRING)
        argument.string = "Hello, World!"

        type = reflection.types.ReflectedType.fromArgument(
            argument, reflector=self.reflector)

        assert isinstance(type, reflection.types.ReflectedString)
        assert type.native() == "Hello, World!"
示例#4
0
    def testItShouldBuildObjectFromArgument(self):
        argument = Message.Argument(type=Message.Argument.OBJECT)
        argument.object.reference = 987654321

        type = reflection.types.ReflectedType.fromArgument(
            argument, reflector=self.reflector)

        assert isinstance(type, reflection.types.ReflectedObject)
        assert type._ref == 987654321
示例#5
0
    def testItShouldBuildPrimitiveFromArgument(self):
        argument = Message.Argument(type=Message.Argument.PRIMITIVE)
        argument.primitive.type = Message.Primitive.BOOL
        argument.primitive.bool = True

        type = reflection.types.ReflectedType.fromArgument(
            argument, reflector=self.reflector)

        assert isinstance(type, reflection.types.ReflectedPrimitive)
        assert type.type() == "boolean"
        assert type.native() == True
示例#6
0
    def _pb(self):
        """
        Get an Argument representation of the Object, as defined in the Mercury
        protocol.
        """

        argument = Message.Argument(type=Message.Argument.OBJECT)

        argument.object.reference = self._ref

        return argument
示例#7
0
    def testItShouldBuildObjectArrayFromArgument(self):
        argument = Message.Argument(type=Message.Argument.ARRAY)
        argument.array.type = Message.Array.OBJECT

        for i in range(0, 3):
            element = argument.array.element.add(type=Message.Argument.OBJECT)
            element.object.reference = i

        type = reflection.types.ReflectedType.fromArgument(
            argument, reflector=self.reflector)

        assert isinstance(type, reflection.types.ReflectedArray)
        assert len(type.native()) == 3

        for i in range(0, 3):
            assert isinstance(type.native()[i],
                              reflection.types.ReflectedObject)
            assert type.native()[i]._ref == i
示例#8
0
    def testItShouldBuildStringArrayFromArgument(self):
        argument = Message.Argument(type=Message.Argument.ARRAY)
        argument.array.type = Message.Array.STRING

        for i in range(0, 3):
            element = argument.array.element.add(type=Message.Argument.STRING)
            element.string = "Hello, World! (" + str(i) + ")"

        type = reflection.types.ReflectedType.fromArgument(
            argument, reflector=self.reflector)

        assert isinstance(type, reflection.types.ReflectedArray)
        assert len(type.native()) == 3

        for i in range(0, 3):
            assert isinstance(type.native()[i],
                              reflection.types.ReflectedString)
            assert type.native()[i].native(
            ) == "Hello, World! (" + str(i) + ")"
示例#9
0
    def testItShouldBuildPrimitiveArrayFromArgument(self):
        argument = Message.Argument(type=Message.Argument.ARRAY)
        argument.array.type = Message.Array.PRIMITIVE

        for i in range(0, 3):
            element = argument.array.element.add(
                type=Message.Argument.PRIMITIVE)
            element.primitive.type = Message.Primitive.BOOL
            element.primitive.bool = True

        type = reflection.types.ReflectedType.fromArgument(
            argument, reflector=self.reflector)

        assert isinstance(type, reflection.types.ReflectedArray)
        assert len(type.native()) == 3

        for i in range(0, 3):
            assert isinstance(type.native()[i],
                              reflection.types.ReflectedPrimitive)
            assert type.native()[i].type() == "boolean"
示例#10
0
    def testItShouldRaiseTypeErrorIfArrayIsMixedTypes(self):
        argument = Message.Argument(type=Message.Argument.ARRAY)
        argument.array.type = Message.Array.PRIMITIVE

        for i in range(0, 3):
            element = argument.array.element.add(
                type=Message.Argument.PRIMITIVE)
            element.primitive.type = Message.Primitive.BOOL
            element.primitive.bool = True
        for i in range(0, 3):
            element = argument.array.element.add(type=Message.Argument.OBJECT)
            element.object.reference = i

        try:
            type = reflection.types.ReflectedType.fromArgument(
                argument, reflector=self.reflector)

            assert False, "should have caused a TypeError building a mixed array"
        except TypeError as e:
            assert e.message == "mismatched array element types"
示例#11
0
    def _pb(self):
        """
        Get an Argument representation of the Array, as defined in the Mercury
        protocol.
        """

        argument = Message.Argument(type=Message.Argument.ARRAY)

        if self._native[0]._pb().type == Message.Argument.ARRAY:
            argument.array.type = Message.Array.ARRAY
        elif self._native[0]._pb().type == Message.Argument.NULL:
            argument.array.type = Message.Array.OBJECT
        elif self._native[0]._pb().type == Message.Argument.OBJECT:
            argument.array.type = Message.Array.OBJECT
        elif self._native[0]._pb().type == Message.Argument.STRING:
            argument.array.type = Message.Array.STRING
        elif self._native[0]._pb().type == Message.Argument.PRIMITIVE:
            argument.array.type = Message.Array.PRIMITIVE

        for e in self._native:
            element = argument.array.element.add()
            element.MergeFrom(ReflectedType.fromNative(e, reflector=self._reflector)._pb())

        return argument
示例#12
0
 def _pb(self):
     """
     Get an Argument representation of the null, as defined in the Mercury
     protocol.
     """
     return Message.Argument(type=Message.Argument.NULL)