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: if 'default' not in self.opts:
self.opts['default'] = None self.opts['default'] = None
self.setDefault(self.opts['value'])
## Connect all state changed signals to the general sigStateChanged ## Connect all state changed signals to the general sigStateChanged
self.sigValueChanged.connect(self._emitValueChanged) self.sigValueChanged.connect(self._emitValueChanged)

View File

@ -8,32 +8,23 @@ def test_parameter_hasdefault():
# default unspecified # default unspecified
p = Parameter(**opts) p = Parameter(**opts)
assert not p.hasDefault()
p.setDefault(1)
assert p.hasDefault() assert p.hasDefault()
assert p.defaultValue() == 1 assert p.defaultValue() == opts["value"]
p.setDefault(2)
assert p.hasDefault()
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 not p.hasDefault() assert not p.hasDefault()
assert p.defaultValue() is None
p.setDefault(None)
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