Skip to content
Snippets Groups Projects
Commit dd52a313 authored by siddharthshukla's avatar siddharthshukla
Browse files

Replace Python unit test iterables by iterators

Cast iterables into iterators for stream based compression, empty
message, and metadata tests.
parent 6bfa91a7
No related branches found
No related tags found
No related merge requests found
...@@ -125,7 +125,7 @@ class CompressionTest(unittest.TestCase): ...@@ -125,7 +125,7 @@ class CompressionTest(unittest.TestCase):
compressed_channel = grpc.insecure_channel('localhost:%d' % self._port, compressed_channel = grpc.insecure_channel('localhost:%d' % self._port,
options=[('grpc.default_compression_algorithm', 1)]) options=[('grpc.default_compression_algorithm', 1)])
multi_callable = compressed_channel.stream_stream(_STREAM_STREAM) multi_callable = compressed_channel.stream_stream(_STREAM_STREAM)
call = multi_callable([request] * test_constants.STREAM_LENGTH) call = multi_callable(iter([request] * test_constants.STREAM_LENGTH))
for response in call: for response in call:
self.assertEqual(request, response) self.assertEqual(request, response)
......
...@@ -123,12 +123,12 @@ class EmptyMessageTest(unittest.TestCase): ...@@ -123,12 +123,12 @@ class EmptyMessageTest(unittest.TestCase):
def testStreamUnary(self): def testStreamUnary(self):
response = self._channel.stream_unary(_STREAM_UNARY)( response = self._channel.stream_unary(_STREAM_UNARY)(
[_REQUEST] * test_constants.STREAM_LENGTH) iter([_REQUEST] * test_constants.STREAM_LENGTH))
self.assertEqual(_RESPONSE, response) self.assertEqual(_RESPONSE, response)
def testStreamStream(self): def testStreamStream(self):
response_iterator = self._channel.stream_stream(_STREAM_STREAM)( response_iterator = self._channel.stream_stream(_STREAM_STREAM)(
[_REQUEST] * test_constants.STREAM_LENGTH) iter([_REQUEST] * test_constants.STREAM_LENGTH))
self.assertSequenceEqual( self.assertSequenceEqual(
[_RESPONSE] * test_constants.STREAM_LENGTH, list(response_iterator)) [_RESPONSE] * test_constants.STREAM_LENGTH, list(response_iterator))
......
...@@ -240,7 +240,7 @@ if __name__ == '__main__': ...@@ -240,7 +240,7 @@ if __name__ == '__main__':
multi_callable = channel.stream_unary(method) multi_callable = channel.stream_unary(method)
future = multi_callable.future(infinite_request_iterator()) future = multi_callable.future(infinite_request_iterator())
result, call = multi_callable.with_call( result, call = multi_callable.with_call(
[REQUEST] * test_constants.STREAM_LENGTH) iter([REQUEST] * test_constants.STREAM_LENGTH))
elif (args.scenario == IN_FLIGHT_STREAM_STREAM_CALL or elif (args.scenario == IN_FLIGHT_STREAM_STREAM_CALL or
args.scenario == IN_FLIGHT_PARTIAL_STREAM_STREAM_CALL): args.scenario == IN_FLIGHT_PARTIAL_STREAM_STREAM_CALL):
multi_callable = channel.stream_stream(method) multi_callable = channel.stream_stream(method)
......
...@@ -193,7 +193,7 @@ class MetadataTest(unittest.TestCase): ...@@ -193,7 +193,7 @@ class MetadataTest(unittest.TestCase):
def testStreamUnary(self): def testStreamUnary(self):
multi_callable = self._channel.stream_unary(_STREAM_UNARY) multi_callable = self._channel.stream_unary(_STREAM_UNARY)
unused_response, call = multi_callable.with_call( unused_response, call = multi_callable.with_call(
[_REQUEST] * test_constants.STREAM_LENGTH, iter([_REQUEST] * test_constants.STREAM_LENGTH),
metadata=_CLIENT_METADATA) metadata=_CLIENT_METADATA)
self.assertTrue(test_common.metadata_transmitted( self.assertTrue(test_common.metadata_transmitted(
_SERVER_INITIAL_METADATA, call.initial_metadata())) _SERVER_INITIAL_METADATA, call.initial_metadata()))
...@@ -202,7 +202,7 @@ class MetadataTest(unittest.TestCase): ...@@ -202,7 +202,7 @@ class MetadataTest(unittest.TestCase):
def testStreamStream(self): def testStreamStream(self):
multi_callable = self._channel.stream_stream(_STREAM_STREAM) multi_callable = self._channel.stream_stream(_STREAM_STREAM)
call = multi_callable([_REQUEST] * test_constants.STREAM_LENGTH, call = multi_callable(iter([_REQUEST] * test_constants.STREAM_LENGTH),
metadata=_CLIENT_METADATA) metadata=_CLIENT_METADATA)
self.assertTrue(test_common.metadata_transmitted( self.assertTrue(test_common.metadata_transmitted(
_SERVER_INITIAL_METADATA, call.initial_metadata())) _SERVER_INITIAL_METADATA, call.initial_metadata()))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment