Skip to content

Commit

Permalink
Further fixes
Browse files Browse the repository at this point in the history
As per the change for #20, handle the case where the user passes in
a `defaults` kwarg to `pysipp.scenario` and use it override the normal
template. To fully solve #12 also support assignment of `None` which
results in the tuple attribute taking a value of `(None, None)`
implicitly.
  • Loading branch information
goodboy committed Jul 5, 2019
1 parent c275334 commit 4bfe5db
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions pysipp/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ def getter(self):

def setter(self, pair):
if not isinstance(pair, tuple):
raise ValueError("{} must be a tuple".format(pair))
for attr, val in zip(attrs, pair or itertools.repeat(None)):
if pair is None:
pair = (None, None)
else:
raise ValueError("{} must be a tuple".format(pair))
for attr, val in zip(attrs, pair):
setattr(self, attr, val)

doc = "{} parameters composed as a tuple".format(', '.join(attrs))
Expand Down Expand Up @@ -233,6 +236,12 @@ def Scenario(agents, **kwargs):
if key in _defs:
_defs[key] = kwargs.pop(key)

# if a `defaults` kwarg is passed in by the user override template values with
# values from that as well
user_defaults = kwargs.pop('defaults', None)
if user_defaults:
_defs.update(user_defaults)

# this gives us scen.<param> attribute access to scen.defaults
utils.DictProxy(_defs, UserAgent.keys(), cls=scentype)
return scentype(agents, _defs, **kwargs)
Expand Down

0 comments on commit 4bfe5db

Please sign in to comment.