MCPcopy Create free account
hub / github.com/python/cpython / test_attach_detach

Method test_attach_detach

Lib/idlelib/idle_test/test_configdialog.py:1547–1576  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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
1579if __name__ == '__main__':

Callers

nothing calls this directly

Calls 7

assertCountEqualMethod · 0.80
addMethod · 0.45
attachMethod · 0.45
assertEqualMethod · 0.45
setMethod · 0.45
getMethod · 0.45
detachMethod · 0.45

Tested by

no test coverage detected