Commit 3de61af5 authored by Robin Obůrka's avatar Robin Obůrka

Fix argument parser - several changes

1) Something new for me: def foo(arg1, arg2=bar()) means that bar() is
called during "definition" of foo function. Thus every time. It is
impossible to prepare structure for tests.

2) I had this on "review". There are some notes about design of SN and
the way how it uses arguments. One small but mighty change is that
arguments are parsed on one place.
parent 1d702567
......@@ -9,10 +9,10 @@ from random import randint
# Custom argument parser is created here
aparser = sn.get_arg_parser()
args = sn.parse(aparser)
ctx = zmq.Context.instance()
sctx = sn.SN(ctx, args)
args = sctx.args
sock_cli, sock_cli2 = sctx.get_socket("sock_cli", ("sock_cli2", "REQ"))
rand_ID = randint(10,99)
......
......@@ -45,13 +45,18 @@ class SN:
an API-like interface for requesting ZMQ sockets based on available
resources.
"""
def __init__(self, ctx, args=get_arg_parser().parse_args()):
def __init__(self, ctx, argparser=None):
""" Gets a list of command line arguments - each for one socket
connection and creates a dict of ZMQ socket configs.
"""
self.context = ctx
self.sock_configs = dict()
res_avail = resource_parser(args.resource)
if argparser:
self.args = argparser.parse_args()
else:
self.args = get_arg_parser.parse_args()
res_avail = resource_parser(self.args.resource)
for res in res_avail:
sc = None
......@@ -70,7 +75,7 @@ class SN:
connection.direction,
connection.address,
connection.port,
ipv6=not args.disable_ipv6
ipv6=not self.args.disable_ipv6
)
self.sock_configs[res] = sc
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment