• 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(
34        '--server_host',
35        default="localhost",
36        type=str,
37        help='the host to which to connect')
38    parser.add_argument(
39        '--server_port',
40        type=int,
41        required=True,
42        help='the port to which to connect')
43    parser.add_argument(
44        '--test_case',
45        default='large_unary',
46        type=str,
47        help='the test case to execute')
48    parser.add_argument(
49        '--use_tls',
50        default=False,
51        type=parse_bool,
52        help='require a secure connection')
53    return parser.parse_args()
54
55
56def _test_case_from_arg(test_case_arg):
57    for test_case in methods.TestCase:
58        if test_case_arg == test_case.value:
59            return test_case
60    else:
61        raise ValueError('No test case "%s"!' % test_case_arg)
62
63
64def test_fork():
65    logging.basicConfig(level=logging.INFO)
66    args = _args()
67    if args.test_case == "all":
68        for test_case in methods.TestCase:
69            test_case.run_test(args)
70    else:
71        test_case = _test_case_from_arg(args.test_case)
72        test_case.run_test(args)
73
74
75if __name__ == '__main__':
76    test_fork()
77