MCPcopy Create free account
hub / github.com/ipython/traitlets / test_notify_args

Method test_notify_args

tests/test_traitlets.py:537–583  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

535 self.assertTrue(("b", 0.0, 10.0) in b._notify2)
536
537 def test_notify_args(self):
538 def callback0():
539 self.cb = ()
540
541 def callback1(name):
542 self.cb = (name,) # type:ignore
543
544 def callback2(name, new):
545 self.cb = (name, new) # type:ignore
546
547 def callback3(name, old, new):
548 self.cb = (name, old, new) # type:ignore
549
550 def callback4(name, old, new, obj):
551 self.cb = (name, old, new, obj) # type:ignore
552
553 class A(HasTraits):
554 a = Int()
555
556 a = A()
557 a.on_trait_change(callback0, "a")
558 a.a = 10
559 self.assertEqual(self.cb, ())
560 a.on_trait_change(callback0, "a", remove=True)
561
562 a.on_trait_change(callback1, "a")
563 a.a = 100
564 self.assertEqual(self.cb, ("a",))
565 a.on_trait_change(callback1, "a", remove=True)
566
567 a.on_trait_change(callback2, "a")
568 a.a = 1000
569 self.assertEqual(self.cb, ("a", 1000))
570 a.on_trait_change(callback2, "a", remove=True)
571
572 a.on_trait_change(callback3, "a")
573 a.a = 10000
574 self.assertEqual(self.cb, ("a", 1000, 10000))
575 a.on_trait_change(callback3, "a", remove=True)
576
577 a.on_trait_change(callback4, "a")
578 a.a = 100000
579 self.assertEqual(self.cb, ("a", 10000, 100000, a))
580 self.assertEqual(len(a._trait_notifiers["a"]["change"]), 1)
581 a.on_trait_change(callback4, "a", remove=True)
582
583 self.assertEqual(len(a._trait_notifiers["a"]["change"]), 0)
584
585 def test_notify_only_once(self):
586 class A(HasTraits):

Callers

nothing calls this directly

Calls 2

on_trait_changeMethod · 0.80
AClass · 0.70

Tested by

no test coverage detected