• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2016 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 channel arguments on client/server side."""
15
16from concurrent import futures
17import unittest
18import logging
19
20import grpc
21
22
23class TestPointerWrapper(object):
24
25    def __int__(self):
26        return 123456
27
28
29TEST_CHANNEL_ARGS = (
30    ('arg1', b'bytes_val'),
31    ('arg2', 'str_val'),
32    ('arg3', 1),
33    (b'arg4', 'str_val'),
34    ('arg6', TestPointerWrapper()),
35)
36
37INVALID_TEST_CHANNEL_ARGS = [
38    {
39        'foo': 'bar'
40    },
41    (('key',),),
42    'str',
43]
44
45
46class ChannelArgsTest(unittest.TestCase):
47
48    def test_client(self):
49        grpc.insecure_channel('localhost:8080', options=TEST_CHANNEL_ARGS)
50
51    def test_server(self):
52        grpc.server(futures.ThreadPoolExecutor(max_workers=1),
53                    options=TEST_CHANNEL_ARGS)
54
55    def test_invalid_client_args(self):
56        for invalid_arg in INVALID_TEST_CHANNEL_ARGS:
57            self.assertRaises(ValueError,
58                              grpc.insecure_channel,
59                              'localhost:8080',
60                              options=invalid_arg)
61
62
63if __name__ == '__main__':
64    logging.basicConfig()
65    unittest.main(verbosity=2)
66