_server_test.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Copyright 2018 The gRPC Authors.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from concurrent import futures
  15. import unittest
  16. import grpc
  17. class _ActualGenericRpcHandler(grpc.GenericRpcHandler):
  18. def service(self, handler_call_details):
  19. return None
  20. class ServerTest(unittest.TestCase):
  21. def test_not_a_generic_rpc_handler_at_construction(self):
  22. with self.assertRaises(AttributeError) as exception_context:
  23. grpc.server(
  24. futures.ThreadPoolExecutor(max_workers=5),
  25. handlers=[
  26. _ActualGenericRpcHandler(),
  27. object(),
  28. ])
  29. self.assertIn('grpc.GenericRpcHandler',
  30. str(exception_context.exception))
  31. def test_not_a_generic_rpc_handler_after_construction(self):
  32. server = grpc.server(futures.ThreadPoolExecutor(max_workers=5))
  33. with self.assertRaises(AttributeError) as exception_context:
  34. server.add_generic_rpc_handlers([
  35. _ActualGenericRpcHandler(),
  36. object(),
  37. ])
  38. self.assertIn('grpc.GenericRpcHandler',
  39. str(exception_context.exception))
  40. if __name__ == '__main__':
  41. unittest.main(verbosity=2)