def testUnaryUnary(self): divisor = 59 dividend = 973 expected_quotient = dividend / divisor expected_remainder = dividend % divisor with self.stub: response = self.stub.Div( math_pb2.DivArgs(divisor=divisor, dividend=dividend), _TIMEOUT) self.assertEqual(expected_quotient, response.quotient) self.assertEqual(expected_remainder, response.remainder)
def testUnaryUnary(self): divisor = 59 dividend = 973 expected_quotient = dividend / divisor expected_remainder = dividend % divisor pipe = PipeLink() service = implementations.assemble_service(_IMPLEMENTATIONS, pipe) dynamic_stub = implementations.assemble_dynamic_inline_stub( _IMPLEMENTATIONS, pipe) service.start() with dynamic_stub: response = dynamic_stub.Div( math_pb2.DivArgs(divisor=divisor, dividend=dividend), _TIMEOUT) self.assertEqual(expected_quotient, response.quotient) self.assertEqual(expected_remainder, response.remainder) service.stop()
def testStreamStream(self): stream_length = 179 divisor_offset = 71 dividend_offset = 1763 with self.stub: response_iterator = self.stub.DivMany( (math_pb2.DivArgs(divisor=divisor_offset + index, dividend=dividend_offset + index) for index in range(stream_length)), _TIMEOUT) for index, response in enumerate(response_iterator): self.assertEqual( (dividend_offset + index) / (divisor_offset + index), response.quotient) self.assertEqual( (dividend_offset + index) % (divisor_offset + index), response.remainder) self.assertEqual(stream_length, index + 1)
class BidirectionallyStreamingScenario(ProtoScenario): """A scenario that transmits no protocol buffers in either direction.""" _STREAM_LENGTH = 200 _REQUESTS = tuple( math_pb2.DivArgs(dividend=59 + index, divisor=7 + index) for index in range(_STREAM_LENGTH)) def __init__(self): self._lock = threading.Lock() self._responses = [] def group_and_method(self): return 'math.Math', 'DivMany' def serialize_request(self, request): return request.SerializeToString() def deserialize_request(self, request_bytestring): return math_pb2.DivArgs.FromString(request_bytestring) def serialize_response(self, response): return response.SerializeToString() def deserialize_response(self, response_bytestring): return math_pb2.DivReply.FromString(response_bytestring) def requests(self): return self._REQUESTS def response_for_request(self, request): quotient, remainder = divmod(request.dividend, request.divisor) response = math_pb2.DivReply(quotient=quotient, remainder=remainder) with self._lock: self._responses.append(response) return response def verify_requests(self, experimental_requests): return tuple(experimental_requests) == self._REQUESTS def verify_responses(self, experimental_responses): with self._lock: return tuple(experimental_responses) == tuple(self._responses)
def testUnaryUnary(self): divisor = 7 dividend = 13 expected_quotient = 1 expected_remainder = 6 pipe = PipeLink() service = implementations.assemble_service(_IMPLEMENTATIONS, pipe) face_stub = implementations.assemble_face_stub(pipe) service.start() try: with face_stub: response = face_stub.blocking_value_in_value_out( DIV, math_pb2.DivArgs(divisor=divisor, dividend=dividend), _TIMEOUT) self.assertEqual(expected_quotient, response.quotient) self.assertEqual(expected_remainder, response.remainder) finally: service.stop()
def testStreamStream(self): stream_length = 17 divisor_offset = 7 dividend_offset = 17 pipe = PipeLink() service = implementations.assemble_service(_IMPLEMENTATIONS, pipe) face_stub = implementations.assemble_face_stub(pipe) with service, face_stub: response_iterator = face_stub.inline_stream_in_stream_out( DIV_MANY, (math_pb2.DivArgs(divisor=divisor_offset + index, dividend=dividend_offset + index) for index in range(stream_length)), _TIMEOUT) for index, response in enumerate(response_iterator): self.assertEqual( (dividend_offset + index) / (divisor_offset + index), response.quotient) self.assertEqual( (dividend_offset + index) % (divisor_offset + index), response.remainder) self.assertEqual(stream_length, index + 1)
def testStreamStream(self): stream_length = 179 divisor_offset = 71 dividend_offset = 1763 pipe = PipeLink() service = implementations.assemble_service(_IMPLEMENTATIONS, pipe) dynamic_stub = implementations.assemble_dynamic_inline_stub( _IMPLEMENTATIONS, pipe) with service, dynamic_stub: response_iterator = dynamic_stub.DivMany( (math_pb2.DivArgs(divisor=divisor_offset + index, dividend=dividend_offset + index) for index in range(stream_length)), _TIMEOUT) for index, response in enumerate(response_iterator): self.assertEqual( (dividend_offset + index) / (divisor_offset + index), response.quotient) self.assertEqual( (dividend_offset + index) % (divisor_offset + index), response.remainder) self.assertEqual(stream_length, index + 1)
class BidirectionallyUnaryScenario(ProtoScenario): """A scenario that transmits no protocol buffers in either direction.""" _DIVIDEND = 59 _DIVISOR = 7 _QUOTIENT = 8 _REMAINDER = 3 _REQUEST = math_pb2.DivArgs(dividend=_DIVIDEND, divisor=_DIVISOR) _RESPONSE = math_pb2.DivReply(quotient=_QUOTIENT, remainder=_REMAINDER) def group_and_method(self): return 'math.Math', 'Div' def serialize_request(self, request): return request.SerializeToString() def deserialize_request(self, request_bytestring): return math_pb2.DivArgs.FromString(request_bytestring) def serialize_response(self, response): return response.SerializeToString() def deserialize_response(self, response_bytestring): return math_pb2.DivReply.FromString(response_bytestring) def requests(self): return [self._REQUEST] def response_for_request(self, request): return self._RESPONSE def verify_requests(self, experimental_requests): return tuple(experimental_requests) == (self._REQUEST,) def verify_responses(self, experimental_responses): return tuple(experimental_responses) == (self._RESPONSE,)