init_test.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. import logging
  15. import unittest
  16. import grpc
  17. from grpc.experimental import aio
  18. from tests_aio.unit import test_base
  19. class TestAioRpcError(unittest.TestCase):
  20. _TEST_INITIAL_METADATA = ("initial metadata",)
  21. _TEST_TRAILING_METADATA = ("trailing metadata",)
  22. def test_attributes(self):
  23. aio_rpc_error = aio.AioRpcError(self._TEST_INITIAL_METADATA, 0,
  24. "details", self._TEST_TRAILING_METADATA)
  25. self.assertEqual(aio_rpc_error.initial_metadata(),
  26. self._TEST_INITIAL_METADATA)
  27. self.assertEqual(aio_rpc_error.code(), 0)
  28. self.assertEqual(aio_rpc_error.details(), "details")
  29. self.assertEqual(aio_rpc_error.trailing_metadata(),
  30. self._TEST_TRAILING_METADATA)
  31. def test_class_hierarchy(self):
  32. aio_rpc_error = aio.AioRpcError(self._TEST_INITIAL_METADATA, 0,
  33. "details", self._TEST_TRAILING_METADATA)
  34. self.assertIsInstance(aio_rpc_error, grpc.RpcError)
  35. def test_class_attributes(self):
  36. aio_rpc_error = aio.AioRpcError(self._TEST_INITIAL_METADATA, 0,
  37. "details", self._TEST_TRAILING_METADATA)
  38. self.assertEqual(aio_rpc_error.__class__.__name__, "AioRpcError")
  39. self.assertEqual(aio_rpc_error.__class__.__doc__,
  40. aio.AioRpcError.__doc__)
  41. def test_class_singleton(self):
  42. first_aio_rpc_error = aio.AioRpcError(self._TEST_INITIAL_METADATA, 0,
  43. "details",
  44. self._TEST_TRAILING_METADATA)
  45. second_aio_rpc_error = aio.AioRpcError(self._TEST_INITIAL_METADATA, 0,
  46. "details",
  47. self._TEST_TRAILING_METADATA)
  48. self.assertIs(first_aio_rpc_error.__class__,
  49. second_aio_rpc_error.__class__)
  50. class TestInsecureChannel(test_base.AioTestBase):
  51. def test_insecure_channel(self):
  52. async def coro():
  53. channel = aio.insecure_channel(self.server_target)
  54. self.assertIsInstance(channel, aio.Channel)
  55. self.loop.run_until_complete(coro())
  56. if __name__ == '__main__':
  57. logging.basicConfig()
  58. unittest.main(verbosity=2)