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

Method test_link_different

tests/test_traitlets.py:2049–2072  ·  view source on GitHub ↗

Verify two traitlets of different types can be linked together using link.

(self)

Source from the content-addressed store, hash-verified

2047 self.assertEqual(a.value, b.value)
2048
2049 def test_link_different(self):
2050 """Verify two traitlets of different types can be linked together using link."""
2051
2052 # Create two simple classes with Int traitlets.
2053 class A(HasTraits):
2054 value = Int()
2055
2056 class B(HasTraits):
2057 count = Int()
2058
2059 a = A(value=9)
2060 b = B(count=8)
2061
2062 # Connect the two classes.
2063 c = link((a, "value"), (b, "count"))
2064
2065 # Make sure the values are the same at the point of linking.
2066 self.assertEqual(a.value, b.count)
2067
2068 # Change one of the values to make sure they stay in sync.
2069 a.value = 5
2070 self.assertEqual(a.value, b.count)
2071 b.count = 4
2072 self.assertEqual(a.value, b.count)
2073
2074 def test_unlink_link(self):
2075 """Verify two linked traitlets can be unlinked and relinked."""

Callers

nothing calls this directly

Calls 3

linkClass · 0.90
AClass · 0.70
BClass · 0.70

Tested by

no test coverage detected