From d737d80c52be4577c51c501c6a7cb83b7160c53d Mon Sep 17 00:00:00 2001 From: Daniel Lidstrom Date: Sun, 20 Dec 2020 23:07:06 -0800 Subject: [PATCH] Improved data race test --- .../parametertree/tests/test_parametertypes.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/pyqtgraph/parametertree/tests/test_parametertypes.py b/pyqtgraph/parametertree/tests/test_parametertypes.py index e84036a9..4ce19ebf 100644 --- a/pyqtgraph/parametertree/tests/test_parametertypes.py +++ b/pyqtgraph/parametertree/tests/test_parametertypes.py @@ -147,11 +147,21 @@ def test_limits_enforcement(): def test_data_race(): + # Ensure widgets don't override user setting of param values whether + # they connect the signal before or after it's added to a tree p = pt.Parameter.create(name='int', type='int', value=0) - - p.sigValueChanged.connect(lambda: p.setValue(1)) # connect signal before adding to tree to ensure priority t = pt.ParameterTree() + + def override(): + p.setValue(1) + + p.sigValueChanged.connect(override) t.setParameters(p) - pi = t.nextFocusableChild(t.invisibleRootItem()) + pi, = t.listAllItems() + assert pi.param is p + pi.widget.setValue(2) + assert p.value() == pi.widget.value() == 1 + p.sigValueChanged.disconnect(override) + p.sigValueChanged.connect(override) pi.widget.setValue(2) assert p.value() == pi.widget.value() == 1