Debian Codegraph @

examples/python/errors/test/_error_handling_example_test.py

raw
1 # Copyright 2019 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 """Tests of the error handling example."""
15
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.
18 try:
19 from tests import bazel_namespace_package_hack
20 bazel_namespace_package_hack.sys_path_to_site_dir_hack()
21 except ImportError:
22 pass
23
24 import logging
25 import unittest
26
27 import grpc
28
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
32
33
34 class ErrorHandlingExampleTest(unittest.TestCase):
35
36 def setUp(self):
37 self._server, port = error_handling_server.create_server('[::]:0')
38 self._server.start()
39 self._channel = grpc.insecure_channel('localhost:%d' % port)
40
41 def tearDown(self):
42 self._channel.close()
43 self._server.stop(None)
44
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!
50
51
52 if __name__ == '__main__':
53 logging.basicConfig()
54 unittest.main(verbosity=2)