Show More
@@ -684,6 +684,20 b' class TestThis(TestCase):' | |||
|
684 | 684 | self.assertEqual(f.t, b) |
|
685 | 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 | 701 | class TraitTestBase(TestCase): |
|
688 | 702 | """A best testing class for basic trait types.""" |
|
689 | 703 |
@@ -1354,6 +1354,8 b' class Container(Instance):' | |||
|
1354 | 1354 | return self.klass(validated) |
|
1355 | 1355 | |
|
1356 | 1356 | def instance_init(self, obj): |
|
1357 | if isinstance(self._trait, TraitType): | |
|
1358 | self._trait.this_class = self.this_class | |
|
1357 | 1359 | if isinstance(self._trait, Instance): |
|
1358 | 1360 | self._trait._resolve_classes() |
|
1359 | 1361 | super(Container, self).instance_init(obj) |
General Comments 0
You need to be logged in to leave comments.
Login now