Show More
@@ -367,29 +367,29 b' class TestHasTraitsNotify(TestCase):' | |||||
367 |
|
367 | |||
368 | class A(HasTraits): |
|
368 | class A(HasTraits): | |
369 | listen_to = ['a'] |
|
369 | listen_to = ['a'] | |
370 |
|
370 | |||
371 | a = Int(0) |
|
371 | a = Int(0) | |
372 | b = 0 |
|
372 | b = 0 | |
373 |
|
373 | |||
374 | def __init__(self, **kwargs): |
|
374 | def __init__(self, **kwargs): | |
375 | super(A, self).__init__(**kwargs) |
|
375 | super(A, self).__init__(**kwargs) | |
376 | self.on_trait_change(self.listener1, ['a']) |
|
376 | self.on_trait_change(self.listener1, ['a']) | |
377 |
|
377 | |||
378 | def listener1(self, name, old, new): |
|
378 | def listener1(self, name, old, new): | |
379 | self.b += 1 |
|
379 | self.b += 1 | |
380 |
|
380 | |||
381 | class B(A): |
|
381 | class B(A): | |
382 |
|
382 | |||
383 | c = 0 |
|
383 | c = 0 | |
384 | d = 0 |
|
384 | d = 0 | |
385 |
|
385 | |||
386 | def __init__(self, **kwargs): |
|
386 | def __init__(self, **kwargs): | |
387 | super(B, self).__init__(**kwargs) |
|
387 | super(B, self).__init__(**kwargs) | |
388 | self.on_trait_change(self.listener2) |
|
388 | self.on_trait_change(self.listener2) | |
389 |
|
389 | |||
390 | def listener2(self, name, old, new): |
|
390 | def listener2(self, name, old, new): | |
391 | self.c += 1 |
|
391 | self.c += 1 | |
392 |
|
392 | |||
393 | def _a_changed(self, name, old, new): |
|
393 | def _a_changed(self, name, old, new): | |
394 | self.d += 1 |
|
394 | self.d += 1 | |
395 |
|
395 | |||
@@ -455,7 +455,7 b' class TestHasTraits(TestCase):' | |||||
455 | def __init__(self, i): |
|
455 | def __init__(self, i): | |
456 | super(A, self).__init__() |
|
456 | super(A, self).__init__() | |
457 | self.i = i |
|
457 | self.i = i | |
458 |
|
458 | |||
459 | a = A(5) |
|
459 | a = A(5) | |
460 | self.assertEqual(a.i, 5) |
|
460 | self.assertEqual(a.i, 5) | |
461 | # should raise TypeError if no positional arg given |
|
461 | # should raise TypeError if no positional arg given | |
@@ -888,12 +888,31 b' class TestList(TraitTestBase):' | |||||
888 | _default_value = [] |
|
888 | _default_value = [] | |
889 | _good_values = [[], [1], list(range(10)), (1,2)] |
|
889 | _good_values = [[], [1], list(range(10)), (1,2)] | |
890 | _bad_values = [10, [1,'a'], 'a'] |
|
890 | _bad_values = [10, [1,'a'], 'a'] | |
891 |
|
891 | |||
892 | def coerce(self, value): |
|
892 | def coerce(self, value): | |
893 | if value is not None: |
|
893 | if value is not None: | |
894 | value = list(value) |
|
894 | value = list(value) | |
895 | return value |
|
895 | return value | |
896 |
|
896 | |||
|
897 | class Foo(object): | |||
|
898 | pass | |||
|
899 | ||||
|
900 | class InstanceListTrait(HasTraits): | |||
|
901 | ||||
|
902 | value = List(Instance(__name__+'.Foo')) | |||
|
903 | ||||
|
904 | class TestInstanceList(TraitTestBase): | |||
|
905 | ||||
|
906 | obj = InstanceListTrait() | |||
|
907 | ||||
|
908 | def test_klass(self): | |||
|
909 | """Test that the instance klass is properly assigned.""" | |||
|
910 | self.assertIs(self.obj.traits()['value']._trait.klass, Foo) | |||
|
911 | ||||
|
912 | _default_value = [] | |||
|
913 | _good_values = [[Foo(), Foo(), None], None] | |||
|
914 | _bad_values = [['1', 2,], '1', [Foo]] | |||
|
915 | ||||
897 | class LenListTrait(HasTraits): |
|
916 | class LenListTrait(HasTraits): | |
898 |
|
917 | |||
899 | value = List(Int, [0], minlen=1, maxlen=2) |
|
918 | value = List(Int, [0], minlen=1, maxlen=2) | |
@@ -1067,7 +1086,7 b' class TestLink(TestCase):' | |||||
1067 | count = Int() |
|
1086 | count = Int() | |
1068 | a = A(value=9) |
|
1087 | a = A(value=9) | |
1069 | b = B(count=8) |
|
1088 | b = B(count=8) | |
1070 |
|
1089 | |||
1071 | # Register callbacks that count. |
|
1090 | # Register callbacks that count. | |
1072 | callback_count = [] |
|
1091 | callback_count = [] | |
1073 | def a_callback(name, old, new): |
|
1092 | def a_callback(name, old, new): |
General Comments 0
You need to be logged in to leave comments.
Login now