| 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 AioRpcError class.""" |
| 15 |
|
| 16 |
import logging |
| 17 |
import unittest |
| 18 |
|
| 19 |
import grpc |
| 20 |
from grpc.aio._call import AioRpcError |
| 21 |
from grpc.experimental import aio |
| 22 |
|
| 23 |
from tests_aio.unit._test_base import AioTestBase |
| 24 |
|
| 25 |
_TEST_INITIAL_METADATA = aio.Metadata( |
| 26 |
('initial metadata key', 'initial metadata value')) |
| 27 |
_TEST_TRAILING_METADATA = aio.Metadata( |
| 28 |
('trailing metadata key', 'trailing metadata value')) |
| 29 |
_TEST_DEBUG_ERROR_STRING = '{This is a debug string}' |
| 30 |
|
| 31 |
|
| 32 |
class TestAioRpcError(unittest.TestCase): |
| 33 |
|
| 34 |
def test_attributes(self): |
| 35 |
aio_rpc_error = AioRpcError(grpc.StatusCode.CANCELLED, |
| 36 |
initial_metadata=_TEST_INITIAL_METADATA, |
| 37 |
trailing_metadata=_TEST_TRAILING_METADATA, |
| 38 |
details="details", |
| 39 |
debug_error_string=_TEST_DEBUG_ERROR_STRING) |
| 40 |
self.assertEqual(aio_rpc_error.code(), grpc.StatusCode.CANCELLED) |
| 41 |
self.assertEqual(aio_rpc_error.details(), 'details') |
| 42 |
self.assertEqual(aio_rpc_error.initial_metadata(), |
| 43 |
_TEST_INITIAL_METADATA) |
| 44 |
self.assertEqual(aio_rpc_error.trailing_metadata(), |
| 45 |
_TEST_TRAILING_METADATA) |
| 46 |
self.assertEqual(aio_rpc_error.debug_error_string(), |
| 47 |
_TEST_DEBUG_ERROR_STRING) |
| 48 |
|
| 49 |
|
| 50 |
if __name__ == '__main__': |
| 51 |
logging.basicConfig() |
| 52 |
unittest.main(verbosity=2) |