Merge pull request #1690 from ntjess/master

revert to old behavior: default created from value if not present
This commit is contained in:
Ogi Moore 2021-04-06 13:07:10 -07:00 committed by GitHub
commit 3ed206fa70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 17 deletions

View File

@ -201,6 +201,7 @@ class Parameter(QtCore.QObject):
if 'default' not in self.opts:
self.opts['default'] = None
self.setDefault(self.opts['value'])
## Connect all state changed signals to the general sigStateChanged
self.sigValueChanged.connect(self._emitValueChanged)

View File

@ -8,32 +8,23 @@ def test_parameter_hasdefault():
# default unspecified
p = Parameter(**opts)
assert not p.hasDefault()
p.setDefault(1)
assert p.hasDefault()
assert p.defaultValue() == 1
assert p.defaultValue() == opts["value"]
p.setDefault(2)
assert p.hasDefault()
assert p.defaultValue() == 2
# default specified
p = Parameter(default=0, **opts)
assert p.hasDefault()
assert p.defaultValue() == 0
@pytest.mark.parametrize('passdefault', [True, False])
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)
# default specified as None
p = Parameter(default=None, **opts)
assert not p.hasDefault()
assert p.defaultValue() is None
p.setDefault(None)
assert not p.hasDefault()
def test_unpack_parameter():
# test that **unpacking correctly returns child name/value maps