Show More
@@ -973,3 +973,61 b' def test_dict_assignment():' | |||||
973 | d['a'] = 5 |
|
973 | d['a'] = 5 | |
974 | nt.assert_equal(d, c.value) |
|
974 | nt.assert_equal(d, c.value) | |
975 | nt.assert_true(c.value is d) |
|
975 | nt.assert_true(c.value is d) | |
|
976 | ||||
|
977 | def test_connect_same: | |||
|
978 | """Verify two traitlets of the same type can be bound together using Connect""" | |||
|
979 | ||||
|
980 | # Create two simple classes with Int traitlets. | |||
|
981 | class A(): | |||
|
982 | value = Int() | |||
|
983 | a = A(value=9) | |||
|
984 | b = A(value=8) | |||
|
985 | ||||
|
986 | # Conenct the two classes. | |||
|
987 | c = Connect((a, 'value'), (b, 'value')) | |||
|
988 | ||||
|
989 | # Make sure the values are the same at the point of connection. | |||
|
990 | assertEqual(a.value, b.value) | |||
|
991 | ||||
|
992 | # Change one of the values to make sure they stay in sync. | |||
|
993 | a.value = 5 | |||
|
994 | assertEqual(a.value, b.value) | |||
|
995 | ||||
|
996 | def test_connect_different: | |||
|
997 | """Verify two traitlets of different types can be bound together using Connect""" | |||
|
998 | ||||
|
999 | # Create two simple classes with Int traitlets. | |||
|
1000 | class A(): | |||
|
1001 | value = Int() | |||
|
1002 | class B(): | |||
|
1003 | count = Int() | |||
|
1004 | a = A(value=9) | |||
|
1005 | b = B(count=8) | |||
|
1006 | ||||
|
1007 | # Conenct the two classes. | |||
|
1008 | c = Connect((a, 'value'), (b, 'count')) | |||
|
1009 | ||||
|
1010 | # Make sure the values are the same at the point of connection. | |||
|
1011 | assertEqual(a.value, b.count) | |||
|
1012 | ||||
|
1013 | # Change one of the values to make sure they stay in sync. | |||
|
1014 | a.value = 5 | |||
|
1015 | assertEqual(a.value, b.count) | |||
|
1016 | ||||
|
1017 | def test_disconnect: | |||
|
1018 | """Verify two connected traitlets can be disconnected""" | |||
|
1019 | ||||
|
1020 | # Create two simple classes with Int traitlets. | |||
|
1021 | class A(): | |||
|
1022 | value = Int() | |||
|
1023 | a = A(value=9) | |||
|
1024 | b = A(value=8) | |||
|
1025 | ||||
|
1026 | # Conenct the two classes. | |||
|
1027 | c = Connect((a, 'value'), (b, 'value')) | |||
|
1028 | a.value = 4 | |||
|
1029 | c.disconnect() | |||
|
1030 | ||||
|
1031 | # Change one of the values to make sure they stay in sync. | |||
|
1032 | a.value = 5 | |||
|
1033 | assertNotEqual(a.value, b.value) No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now