1 # Copyright 2018 The gRPC Authors.
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 from concurrent import futures
22 class _ActualGenericRpcHandler(grpc.GenericRpcHandler):
24 def service(self, handler_call_details):
28 class ServerTest(unittest.TestCase):
30 def test_not_a_generic_rpc_handler_at_construction(self):
31 with self.assertRaises(AttributeError) as exception_context:
32 grpc.server(futures.ThreadPoolExecutor(max_workers=5),
34 _ActualGenericRpcHandler(),
37 self.assertIn('grpc.GenericRpcHandler',
38 str(exception_context.exception))
40 def test_not_a_generic_rpc_handler_after_construction(self):
41 server = grpc.server(futures.ThreadPoolExecutor(max_workers=5))
42 with self.assertRaises(AttributeError) as exception_context:
43 server.add_generic_rpc_handlers([
44 _ActualGenericRpcHandler(),
47 self.assertIn('grpc.GenericRpcHandler',
48 str(exception_context.exception))
51 if __name__ == '__main__':
53 unittest.main(verbosity=2)