Verify two traitlets of different types can be linked together using link.
(self)
| 2236 | self.assertEqual(a.value, 5) |
| 2237 | |
| 2238 | def test_link_different(self): |
| 2239 | """Verify two traitlets of different types can be linked together using link.""" |
| 2240 | |
| 2241 | # Create two simple classes with Int traitlets. |
| 2242 | class A(HasTraits): |
| 2243 | value = Int() |
| 2244 | |
| 2245 | class B(HasTraits): |
| 2246 | count = Int() |
| 2247 | |
| 2248 | a = A(value=9) |
| 2249 | b = B(count=8) |
| 2250 | |
| 2251 | # Connect the two classes. |
| 2252 | c = directional_link((a, "value"), (b, "count")) |
| 2253 | |
| 2254 | # Make sure the values are the same at the point of linking. |
| 2255 | self.assertEqual(a.value, b.count) |
| 2256 | |
| 2257 | # Change one the value of the source and check that it synchronizes the target. |
| 2258 | a.value = 5 |
| 2259 | self.assertEqual(b.count, 5) |
| 2260 | # Change one the value of the target and check that it has no impact on the source |
| 2261 | b.value = 6 # type:ignore |
| 2262 | self.assertEqual(a.value, 5) |
| 2263 | |
| 2264 | def test_unlink_link(self): |
| 2265 | """Verify two linked traitlets can be unlinked and relinked.""" |
nothing calls this directly
no test coverage detected