enthought / enthought/chaco

DataRange2D set_bounds method fires multiple events

Open
#516 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
305
Forks
97
PR merge metrics
No merged PRs in 30d

Description

**Problem Description**
The goal of ``set_bounds`` is to update all the bounds simultaneously under one event. Current implementation fires multiple events (depending on how many values have changed).

**Reproduction Steps:**
Checked by writing a unittest for ``DataRange2D``

```python
def test_set_bounds_events(self):
with self.subTest(msg="DataRange2D"):
r = DataRange2D()
with self.assertTraitChanges(r, 'updated', count=1):
r.set_bounds((-1, -2), (3, 4))

with self.subTest(msg="DataRange2D.x_range"):
r = DataRange2D()
with self.assertTraitChanges(r.x_range, 'updated', count=1):
r.set_bounds((-1, -2), (3, 4))

with self.subTest(msg="DataRange2D.y_range"):
r = DataRange2D()
with self.assertTraitChanges(r.y_range, 'updated', count=1):
r.set_bounds((-1, -2), (3, 4))
```
Output from each subtest:
```
FAIL: test_set_bounds_events (chaco.tests.test_datarange_2d.DataRange2DTestCase) [DataRange2D]
...
AssertionError: Change event for updated was fired 4 times instead of 1

FAIL: test_set_bounds_events (chaco.tests.test_datarange_2d.DataRange2DTestCase) [DataRange2D.x_range]
...
AssertionError: Change event for updated was fired 2 times instead of 1

FAIL: test_set_bounds_events (chaco.tests.test_datarange_2d.DataRange2DTestCase) [DataRange2D.y_range]
...
AssertionError: Change event for updated was fired 2 times instead of 1
```

**Expected behavior:**

The call to this method should fire only one event on DataRange2D and associated DataRange1D instances.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.