• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2018 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"""The Python implementation of the GRPC interoperability test client."""
15
16import argparse
17import logging
18import sys
19
20from tests.fork import methods
21
22
23def _args():
24
25    def parse_bool(value):
26        if value == 'true':
27            return True
28        if value == 'false':
29            return False
30        raise argparse.ArgumentTypeError('Only true/false allowed')
31
32    parser = argparse.ArgumentParser()
33    parser.add_argument('--server_host',
34                        default="localhost",
35                        type=str,
36                        help='the host to which to connect')
37    parser.add_argument('--server_port',
38                        type=int,
39                        required=True,
40                        help='the port to which to connect')
41    parser.add_argument('--test_case',
42                        default='large_unary',
43                        type=str,
44                        help='the test case to execute')
45    parser.add_argument('--use_tls',
46                        default=False,
47                        type=parse_bool,
48                        help='require a secure connection')
49    return parser.parse_args()
50
51
52def _test_case_from_arg(test_case_arg):
53    for test_case in methods.TestCase:
54        if test_case_arg == test_case.value:
55            return test_case
56    else:
57        raise ValueError('No test case "%s"!' % test_case_arg)
58
59
60def test_fork():
61    logging.basicConfig(level=logging.INFO)
62    args = vars(_args())
63    if args['test_case'] == "all":
64        for test_case in methods.TestCase:
65            test_case.run_test(args)
66    else:
67        test_case = _test_case_from_arg(args['test_case'])
68        test_case.run_test(args)
69
70
71if __name__ == '__main__':
72    test_fork()
73