Implement suggested changes from ixjlyons

This commit is contained in:
Ogi Moore 2021-04-06 11:51:10 -07:00
parent 58d126dcf3
commit d4c5025289

View File

@ -9,33 +9,23 @@ def test_parameter_hasdefault():
# default unspecified # default unspecified
p = Parameter(**opts) p = Parameter(**opts)
assert p.hasDefault() assert p.hasDefault()
assert p.defaultValue() == opts["value"]
p.setDefault(1) p.setDefault(2)
assert p.hasDefault() assert p.hasDefault()
assert p.defaultValue() == 1 assert p.defaultValue() == 2
# default specified # default specified
p = Parameter(default=0, **opts) p = Parameter(default=0, **opts)
assert p.hasDefault() assert p.hasDefault()
assert p.defaultValue() == 0 assert p.defaultValue() == 0
# default specified as None
@pytest.mark.parametrize('passdefault', [True, False]) p = Parameter(default=None, **opts)
def test_parameter_hasdefault_none(passdefault):
# test that Parameter essentially ignores defualt=None, same as not passing
# a default at all
opts = {'name': 'param', 'type': int, 'value': 0}
if passdefault:
opts['default'] = None
p = Parameter(**opts)
assert p.hasDefault() != passdefault
defaultCmp = None if passdefault else p.value()
assert p.defaultValue() == defaultCmp
p.setDefault(None)
assert not p.hasDefault() assert not p.hasDefault()
def test_unpack_parameter(): def test_unpack_parameter():
# test that **unpacking correctly returns child name/value maps # test that **unpacking correctly returns child name/value maps
params = [ params = [