def test_bad_root(self): c1 = Component(None) c2 = Component(None) c3 = Component(None) self.assertRaises(ComponentError, setattr, c1, 'root', c2) c1.parent = c2 self.assertEquals(c1.root, c2) self.assertRaises(ComponentError, setattr, c1, 'root', c3)
def test_root(self): c1 = Component(None) c2 = Component(c1) c3 = Component(c1) c4 = Component(c3) self.assertEquals(c1.root, c1.root) self.assertEquals(c2.root, c1) self.assertEquals(c3.root, c1) self.assertEquals(c4.root, c1)
def test_default(self): class MyComponent(Component): pass c1 = Component(None) c2 = MyComponent(None) c3 = Component(c2) self.assertNotEquals(c1.name, c2.name) self.assertNotEquals(c1.name, c3.name)
def test_manual(self): class MyComponent(Component): pass c1 = Component(None, name='foo') c2 = MyComponent(None, name='bar') c3 = Component(c2, name='bah') self.assertEquals(c1.name, 'foo') self.assertEquals(c2.name, 'bar') self.assertEquals(c3.name, 'bah')
def test_subclass_parent(self): c1 = Component(None) self.assertRaises(TraitletError, setattr, c1, 'parent', 10) class MyComponent(Component): pass c1 = Component(None) c2 = MyComponent(c1) self.assertEquals(MyComponent.parent.this_class, Component) self.assertEquals(c2.parent, c1)
def test_change_parent(self): c1 = Component(None) c2 = Component(None) c3 = Component(c1) self.assertEquals(c3.root, c1) self.assertEquals(c3.parent, c1) self.assertEquals(c1.children,[c3]) c3.parent = c2 self.assertEquals(c3.root, c2) self.assertEquals(c3.parent, c2) self.assertEquals(c2.children,[c3]) self.assertEquals(c1.children,[])
def test_change_parent(self): c1 = Component(None) c2 = Component(None) c3 = Component(c1) self.assertEquals(c3.root, c1) self.assertEquals(c3.parent, c1) self.assertEquals(c1.children, [c3]) c3.parent = c2 self.assertEquals(c3.root, c2) self.assertEquals(c3.parent, c2) self.assertEquals(c2.children, [c3]) self.assertEquals(c1.children, [])
def test_parent_child(self): c1 = Component(None) c2 = Component(c1) c3 = Component(c1) c4 = Component(c3) self.assertEquals(c1.parent, None) self.assertEquals(c2.parent, c1) self.assertEquals(c3.parent, c1) self.assertEquals(c4.parent, c3) self.assertEquals(c1.children, [c2, c3]) self.assertEquals(c2.children, []) self.assertEquals(c3.children, [c4]) self.assertEquals(c4.children, [])
def test_custom(self): config = Config() config.foo = 'foo' config.bar = 'bar' c1 = Component(None, config=config) c2 = Component(c1) c3 = Component(c2) self.assertEquals(c1.config, config) self.assertEquals(c2.config, config) self.assertEquals(c3.config, config) # Test that copies are not made self.assert_(c1.config is config) self.assert_(c2.config is config) self.assert_(c3.config is config) self.assert_(c1.config is c2.config) self.assert_(c2.config is c3.config)
def shell(self): return Component.get_instances(root=self.root, klass="IPython.core.iplib.InteractiveShell")[0]
def shell(self): return Component.get_instances( root=self.root, klass='IPython.core.iplib.InteractiveShell')[0]
def test_default(self): c1 = Component(None) c2 = Component(c1) c3 = Component(c2) self.assertEquals(c1.config, c2.config) self.assertEquals(c2.config, c3.config)