(self)
| 1545 | changes.clear() |
| 1546 | |
| 1547 | def test_attach_detach(self): |
| 1548 | tr = self.tracers |
| 1549 | iv = tr.add(self.iv, self.var_changed_increment) |
| 1550 | bv = tr.add(self.bv, self.var_changed_boolean) |
| 1551 | expected = [(iv, self.var_changed_increment), |
| 1552 | (bv, self.var_changed_boolean)] |
| 1553 | |
| 1554 | # Attach callbacks and test call increment. |
| 1555 | tr.attach() |
| 1556 | self.assertEqual(tr.untraced, []) |
| 1557 | self.assertCountEqual(tr.traced, expected) |
| 1558 | iv.set(1) |
| 1559 | self.assertEqual(iv.get(), 1) |
| 1560 | self.assertEqual(self.called, 13) |
| 1561 | |
| 1562 | # Check that only one callback is attached to a variable. |
| 1563 | # If more than one callback were attached, then var_changed_increment |
| 1564 | # would be called twice and the counter would be 2. |
| 1565 | self.called = 0 |
| 1566 | tr.attach() |
| 1567 | iv.set(1) |
| 1568 | self.assertEqual(self.called, 13) |
| 1569 | |
| 1570 | # Detach callbacks. |
| 1571 | self.called = 0 |
| 1572 | tr.detach() |
| 1573 | self.assertEqual(tr.traced, []) |
| 1574 | self.assertCountEqual(tr.untraced, expected) |
| 1575 | iv.set(1) |
| 1576 | self.assertEqual(self.called, 0) |
| 1577 | |
| 1578 | |
| 1579 | if __name__ == '__main__': |
nothing calls this directly
no test coverage detected