1 # Copyright 2019 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.
14 """Tests of the error handling example."""
16 # NOTE(lidiz) This module only exists in Bazel BUILD file, for more details
17 # please refer to comments in the "bazel_namespace_package_hack" module.
19 from tests import bazel_namespace_package_hack
20 bazel_namespace_package_hack.sys_path_to_site_dir_hack()
29 from examples.protos import helloworld_pb2_grpc
30 from examples.python.errors import client as error_handling_client
31 from examples.python.errors import server as error_handling_server
34 class ErrorHandlingExampleTest(unittest.TestCase):
37 self._server, port = error_handling_server.create_server('[::]:0')
39 self._channel = grpc.insecure_channel('localhost:%d' % port)
43 self._server.stop(None)
45 def test_error_handling_example(self):
46 stub = helloworld_pb2_grpc.GreeterStub(self._channel)
47 error_handling_client.process(stub)
48 error_handling_client.process(stub)
49 # No unhandled exception raised, test passed!
52 if __name__ == '__main__':
54 unittest.main(verbosity=2)