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

Method test_tranform

tests/test_traitlets.py:2140–2162  ·  view source on GitHub ↗

Test transform link.

(self)

Source from the content-addressed store, hash-verified

2138 del callback_count[:]
2139
2140 def test_tranform(self):
2141 """Test transform link."""
2142
2143 # Create two simple classes with Int traitlets.
2144 class A(HasTraits):
2145 value = Int()
2146
2147 a = A(value=9)
2148 b = A(value=8)
2149
2150 # Connect the two classes.
2151 c = link((a, "value"), (b, "value"), transform=(lambda x: 2 * x, lambda x: int(x / 2.0)))
2152
2153 # Make sure the values are correct at the point of linking.
2154 self.assertEqual(b.value, 2 * a.value)
2155
2156 # Change one the value of the source and check that it modifies the target.
2157 a.value = 5
2158 self.assertEqual(b.value, 10)
2159 # Change one the value of the target and check that it modifies the
2160 # source.
2161 b.value = 6
2162 self.assertEqual(a.value, 3)
2163
2164 def test_link_broken_at_source(self):
2165 class MyClass(HasTraits):

Callers

nothing calls this directly

Calls 2

linkClass · 0.90
AClass · 0.70

Tested by

no test coverage detected