| 583 | self.assertEqual(len(a._trait_notifiers["a"]["change"]), 0) |
| 584 | |
| 585 | def test_notify_only_once(self): |
| 586 | class A(HasTraits): |
| 587 | listen_to = ["a"] |
| 588 | |
| 589 | a = Int(0) |
| 590 | b = 0 |
| 591 | |
| 592 | def __init__(self, **kwargs): |
| 593 | super().__init__(**kwargs) |
| 594 | self.on_trait_change(self.listener1, ["a"]) |
| 595 | |
| 596 | def listener1(self, name, old, new): |
| 597 | self.b += 1 |
| 598 | |
| 599 | class B(A): |
| 600 | c = 0 |
| 601 | d = 0 |
| 602 | |
| 603 | def __init__(self, **kwargs): |
| 604 | super().__init__(**kwargs) |
| 605 | self.on_trait_change(self.listener2) |
| 606 | |
| 607 | def listener2(self, name, old, new): |
| 608 | self.c += 1 |
| 609 | |
| 610 | def _a_changed(self, name, old, new): |
| 611 | self.d += 1 |
| 612 | |
| 613 | b = B() |
| 614 | b.a += 1 |
| 615 | self.assertEqual(b.b, b.c) |
| 616 | self.assertEqual(b.b, b.d) |
| 617 | b.a += 1 |
| 618 | self.assertEqual(b.b, b.c) |
| 619 | self.assertEqual(b.b, b.d) |
| 620 | |
| 621 | |
| 622 | class TestObserveDecorator(TestCase): |