From 4b002c06ba831b9c60fe9b86e14a2dd27da0891f Mon Sep 17 00:00:00 2001 From: Nathan Jessurun Date: Sat, 3 Apr 2021 17:07:02 -0400 Subject: [PATCH 1/3] revert to old behavior: default created from value if not present --- pyqtgraph/parametertree/Parameter.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pyqtgraph/parametertree/Parameter.py b/pyqtgraph/parametertree/Parameter.py index 2d830273..c084634a 100644 --- a/pyqtgraph/parametertree/Parameter.py +++ b/pyqtgraph/parametertree/Parameter.py @@ -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) From 58d126dcf3bb547827bfcfd3dc0c0c5bf87de2d3 Mon Sep 17 00:00:00 2001 From: Nathan Jessurun Date: Sat, 3 Apr 2021 20:31:04 -0400 Subject: [PATCH 2/3] fixes tests --- pyqtgraph/parametertree/tests/test_Parameter.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pyqtgraph/parametertree/tests/test_Parameter.py b/pyqtgraph/parametertree/tests/test_Parameter.py index 70feab5f..69dca1ff 100644 --- a/pyqtgraph/parametertree/tests/test_Parameter.py +++ b/pyqtgraph/parametertree/tests/test_Parameter.py @@ -8,7 +8,7 @@ def test_parameter_hasdefault(): # default unspecified p = Parameter(**opts) - assert not p.hasDefault() + assert p.hasDefault() p.setDefault(1) assert p.hasDefault() @@ -29,8 +29,9 @@ def test_parameter_hasdefault_none(passdefault): opts['default'] = None p = Parameter(**opts) - assert not p.hasDefault() - assert p.defaultValue() is None + assert p.hasDefault() != passdefault + defaultCmp = None if passdefault else p.value() + assert p.defaultValue() == defaultCmp p.setDefault(None) assert not p.hasDefault() From d4c50252890136e3e1f701fef0b60d53ee9f9a65 Mon Sep 17 00:00:00 2001 From: Ogi Moore Date: Tue, 6 Apr 2021 11:51:10 -0700 Subject: [PATCH 3/3] Implement suggested changes from ixjlyons --- .../parametertree/tests/test_Parameter.py | 24 ++++++------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/pyqtgraph/parametertree/tests/test_Parameter.py b/pyqtgraph/parametertree/tests/test_Parameter.py index 69dca1ff..e0c5a985 100644 --- a/pyqtgraph/parametertree/tests/test_Parameter.py +++ b/pyqtgraph/parametertree/tests/test_Parameter.py @@ -9,33 +9,23 @@ def test_parameter_hasdefault(): # default unspecified p = Parameter(**opts) assert p.hasDefault() + assert p.defaultValue() == opts["value"] - p.setDefault(1) + p.setDefault(2) assert p.hasDefault() - assert p.defaultValue() == 1 + 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) - assert p.hasDefault() != passdefault - defaultCmp = None if passdefault else p.value() - assert p.defaultValue() == defaultCmp - - p.setDefault(None) + # default specified as None + p = Parameter(default=None, **opts) assert not p.hasDefault() + + def test_unpack_parameter(): # test that **unpacking correctly returns child name/value maps params = [