Show More
@@ -684,6 +684,20 b' class TestThis(TestCase):' | |||||
684 | self.assertEqual(f.t, b) |
|
684 | self.assertEqual(f.t, b) | |
685 | self.assertRaises(TraitError, setattr, b, 't', f) |
|
685 | self.assertRaises(TraitError, setattr, b, 't', f) | |
686 |
|
686 | |||
|
687 | def test_this_in_container(self): | |||
|
688 | ||||
|
689 | class Tree(HasTraits): | |||
|
690 | value = Unicode() | |||
|
691 | leaves = List(This()) | |||
|
692 | ||||
|
693 | tree = Tree( | |||
|
694 | value='foo', | |||
|
695 | leaves=[Tree('bar'), Tree('buzz')] | |||
|
696 | ) | |||
|
697 | ||||
|
698 | with self.assertRaises(TraitError): | |||
|
699 | tree.leaves = [1, 2] | |||
|
700 | ||||
687 | class TraitTestBase(TestCase): |
|
701 | class TraitTestBase(TestCase): | |
688 | """A best testing class for basic trait types.""" |
|
702 | """A best testing class for basic trait types.""" | |
689 |
|
703 |
@@ -1354,6 +1354,8 b' class Container(Instance):' | |||||
1354 | return self.klass(validated) |
|
1354 | return self.klass(validated) | |
1355 |
|
1355 | |||
1356 | def instance_init(self, obj): |
|
1356 | def instance_init(self, obj): | |
|
1357 | if isinstance(self._trait, TraitType): | |||
|
1358 | self._trait.this_class = self.this_class | |||
1357 | if isinstance(self._trait, Instance): |
|
1359 | if isinstance(self._trait, Instance): | |
1358 | self._trait._resolve_classes() |
|
1360 | self._trait._resolve_classes() | |
1359 | super(Container, self).instance_init(obj) |
|
1361 | super(Container, self).instance_init(obj) |
General Comments 0
You need to be logged in to leave comments.
Login now