Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions chaco/data_range_1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ def _refresh_bounds(self):
self._high_value = inf
else:
self._high_value = self._high_setting
self.updated = (self._low_value, self._high_value)
return
else:
mins, maxes = zip(*bounds_list)
Expand Down
28 changes: 27 additions & 1 deletion chaco/tests/test_datarange_1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from numpy.testing import assert_equal

from traits.api import HasTraits, Instance, Bool, observe
from traits.testing.api import UnittestTools

from chaco.api import DataRange1D, ArrayDataSource

Expand All @@ -35,7 +36,7 @@ def range_changed(self, event):
self.range_updated = True


class DataRangeTestCase(unittest.TestCase):
class DataRangeTestCase(UnittestTools, unittest.TestCase):
def test_empty_range(self):
r = DataRange1D()
self.assertEqual(r.low, -inf)
Expand Down Expand Up @@ -337,3 +338,28 @@ def test_inf_in_source(self):
r.sources.append(ds1)
self.assertEqual(r.low, -inf)
self.assertEqual(r.high, inf)

def test_sources_changed_auto(self):
ds1 = ArrayDataSource(array([3, 4, 5, 6, 7]))
ds2 = ArrayDataSource(array([5, 10, 15, 20]))
r = DataRange1D()
events = []
r.observe(events.append, 'updated')

self.assertEqual(r.low, -inf)
self.assertEqual(r.high, inf)

with self.assertTraitChanges(r, "updated", count=1):
r.add(ds1)

self.assertEqual(events[-1].new, (3, 7))
self.assertEqual(r.low, 3)
self.assertEqual(r.high, 7)


with self.assertTraitChanges(r, "updated", count=1):
r.remove(ds1)

self.assertEqual(events[-1].new, (-inf, inf))
self.assertEqual(r.low, -inf)
self.assertEqual(r.high, inf)