_error_handling_example_test.py
Go to the documentation of this file.
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 
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)
helloworld_pb2_grpc.GreeterStub
Definition: helloworld/helloworld_pb2_grpc.py:7
grpc.insecure_channel
def insecure_channel(target, options=None, compression=None)
Definition: src/python/grpcio/grpc/__init__.py:1962
_error_handling_example_test.ErrorHandlingExampleTest
Definition: _error_handling_example_test.py:34
_error_handling_example_test.ErrorHandlingExampleTest.test_error_handling_example
def test_error_handling_example(self)
Definition: _error_handling_example_test.py:45
_error_handling_example_test.ErrorHandlingExampleTest.setUp
def setUp(self)
Definition: _error_handling_example_test.py:36
start
static uint64_t start
Definition: benchmark-pound.c:74
_error_handling_example_test.ErrorHandlingExampleTest._channel
_channel
Definition: _error_handling_example_test.py:39
close
#define close
Definition: test-fs.c:48
_error_handling_example_test.ErrorHandlingExampleTest.tearDown
def tearDown(self)
Definition: _error_handling_example_test.py:41
stop
static const char stop[]
Definition: benchmark-async-pummel.c:35


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:27