Show More
@@ -898,6 +898,25 b' class TestList(TraitTestBase):' | |||||
898 | value = list(value) |
|
898 | value = list(value) | |
899 | return value |
|
899 | return value | |
900 |
|
900 | |||
|
901 | class Foo(object): | |||
|
902 | pass | |||
|
903 | ||||
|
904 | class InstanceListTrait(HasTraits): | |||
|
905 | ||||
|
906 | value = List(Instance(__name__+'.Foo')) | |||
|
907 | ||||
|
908 | class TestInstanceList(TraitTestBase): | |||
|
909 | ||||
|
910 | obj = InstanceListTrait() | |||
|
911 | ||||
|
912 | def test_klass(self): | |||
|
913 | """Test that the instance klass is properly assigned.""" | |||
|
914 | self.assertIs(self.obj.traits()['value']._trait.klass, Foo) | |||
|
915 | ||||
|
916 | _default_value = [] | |||
|
917 | _good_values = [[Foo(), Foo(), None], None] | |||
|
918 | _bad_values = [['1', 2,], '1', [Foo]] | |||
|
919 | ||||
901 | class LenListTrait(HasTraits): |
|
920 | class LenListTrait(HasTraits): | |
902 |
|
921 | |||
903 | value = List(Int, [0], minlen=1, maxlen=2) |
|
922 | value = List(Int, [0], minlen=1, maxlen=2) | |
@@ -1122,4 +1141,4 b' def test_pickle_hastraits():' | |||||
1122 | c2 = pickle.loads(p) |
|
1141 | c2 = pickle.loads(p) | |
1123 | nt.assert_equal(c2.i, c.i) |
|
1142 | nt.assert_equal(c2.i, c.i) | |
1124 | nt.assert_equal(c2.j, c.j) |
|
1143 | nt.assert_equal(c2.j, c.j) | |
1125 | No newline at end of file |
|
1144 |
@@ -1284,6 +1284,11 b' class Container(Instance):' | |||||
1284 | validated.append(v) |
|
1284 | validated.append(v) | |
1285 | return self.klass(validated) |
|
1285 | return self.klass(validated) | |
1286 |
|
1286 | |||
|
1287 | def instance_init(self, obj): | |||
|
1288 | if isinstance(self._trait, Instance): | |||
|
1289 | self._trait._resolve_classes() | |||
|
1290 | super(Container, self).instance_init(obj) | |||
|
1291 | ||||
1287 |
|
1292 | |||
1288 | class List(Container): |
|
1293 | class List(Container): | |
1289 | """An instance of a Python list.""" |
|
1294 | """An instance of a Python list.""" |
General Comments 0
You need to be logged in to leave comments.
Login now