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)
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)
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!"
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
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
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
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
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) + ")"
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"
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"
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
def _pb(self): """ Get an Argument representation of the null, as defined in the Mercury protocol. """ return Message.Argument(type=Message.Argument.NULL)