Skip to content

Commit b63161c

Browse files
committed
Updated args_parser function and added unittest.
1 parent 0f8e30e commit b63161c

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

azure_functions_worker/main.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
# Licensed under the MIT License.
33
"""Main entrypoint."""
44

5-
65
import argparse
76

87

9-
def parse_args():
8+
def create_args_parser():
109
parser = argparse.ArgumentParser(
1110
description='Python Azure Functions Worker')
1211
parser.add_argument('--host',
@@ -26,18 +25,19 @@ def parse_args():
2625
'syslog, or a file path')
2726
parser.add_argument('--grpcMaxMessageLength', type=int,
2827
dest='grpc_max_msg_len')
29-
parser.add_argument('--functions-uri', dest='functions_uri',
28+
parser.add_argument('--functions-uri', dest='functions_uri', type=str,
3029
help='URI with IP Address and Port used to'
3130
' connect to the Host via gRPC.')
3231
parser.add_argument('--functions-request-id', dest='functions_request_id',
33-
help='Request ID used for gRPC communication '
34-
'with the Host.')
35-
parser.add_argument('--functions-worker-id', dest='functions_worker_id',
32+
type=str, help='Request ID used for gRPC communication '
33+
'with the Host.')
34+
parser.add_argument('--functions-worker-id',
35+
dest='functions_worker_id', type=str,
3636
help='Worker ID assigned to this language worker.')
3737
parser.add_argument('--functions-grpc-max-message-length', type=int,
3838
dest='functions_grpc_max_msg_len',
3939
help='Max grpc message length for Functions')
40-
return parser.parse_args()
40+
return parser
4141

4242

4343
def main():
@@ -49,7 +49,8 @@ def main():
4949
from ._thirdparty import aio_compat
5050
from .logging import error_logger, logger, format_exception
5151

52-
args = parse_args()
52+
parser = create_args_parser()
53+
args = parser.parse_args()
5354
logging.setup(log_level=args.log_level, log_destination=args.log_to)
5455

5556
logger.info('Starting Azure Functions Python Worker.')

tests/unittests/test_main.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import unittest
2+
3+
from azure_functions_worker.main import create_args_parser
4+
5+
6+
class TestMain(unittest.TestCase):
7+
8+
def test_args_parser(self):
9+
parser = create_args_parser()
10+
parsed = parser.parse_args(
11+
['--host', '127.0.0.1',
12+
'--port', '50821',
13+
'--workerId', 'e9efd817-47a1-45dc-9e20-e6f975d7a025',
14+
'--requestId', 'cbef5957-cdb3-4462-9ee7-ac9f91be0a51',
15+
'--grpcMaxMessageLength', '2147483647',
16+
'--functions-uri', 'http://127.0.0.1:50821',
17+
'--functions-worker-id', 'e9efd817-47a1-45dc-9e20-e6f975d7a025',
18+
'--functions-request-id', 'cbef5957-cdb3-4462-9ee7-ac9f91be0a51',
19+
'--functions-grpc-max-message-length', '2147483647'])
20+
self.assertEqual(parsed.host, '127.0.0.1')
21+
self.assertEqual(parsed.worker_id,
22+
'e9efd817-47a1-45dc-9e20-e6f975d7a025')
23+
self.assertEqual(parsed.request_id,
24+
'cbef5957-cdb3-4462-9ee7-ac9f91be0a51')
25+
self.assertEqual(parsed.grpc_max_msg_len, 2147483647)
26+
self.assertEqual(parsed.functions_uri, 'http://127.0.0.1:50821')
27+
self.assertEqual(parsed.functions_worker_id,
28+
'e9efd817-47a1-45dc-9e20-e6f975d7a025')
29+
self.assertEqual(parsed.functions_request_id,
30+
'cbef5957-cdb3-4462-9ee7-ac9f91be0a51')
31+
self.assertEqual(parsed.functions_grpc_max_msg_len, 2147483647)

0 commit comments

Comments
 (0)