def test_add_child_and_get(self): cont = container.ObjectProxyContainer(None) obj = TestC() cont._add_to_path("com.nokia", container.ObjectProxyContainer(obj, "test")) self.assertEquals(cont._get('com.nokia.test')._obj, obj) self.assertEquals(cont.com._get('nokia.test')._obj, obj) self.assertEquals(cont.com.nokia._get('test')._obj, obj)
def test_add_child_to_path(self): cont = container.ObjectProxyContainer(None) obj = TestC() cont._add_to_path("com.nokia", container.ObjectProxyContainer(obj, "test")) self.assertEquals(cont._list(), ['com']) self.assertEquals(cont.com.nokia._list(), ['test']) self.assertEquals(cont.com.nokia.test._obj, obj) self.assertEquals(cont.com.nokia.test.test(), "test string")
def test_add_children_and_traverse_and_get_path(self): cont = container.ObjectProxyContainer(None, "default") cont._add_to_path("com.nokia", container.ObjectProxyContainer(TestC(), "test")) cont._add_to_path("com.nokia", container.ObjectProxyContainer(TestC(), "foo")) cont._add_to_path("com", container.ObjectProxyContainer(TestC(), "bar")) cont.com._list() self.assertEquals(cont._traverse()[0]._path(), "default.com")
def test_add_children_and_list_all(self): cont = container.ObjectProxyContainer(None) obj = TestC() cont._add_to_path("com.nokia", container.ObjectProxyContainer(obj, "test")) cont._add_to_path("com.nokia", container.ObjectProxyContainer(TestC(), "foo")) cont._add_to_path("com", container.ObjectProxyContainer(TestC(), "bar")) self.assertEquals(len(cont._traverse()), 5)
def test_add_children_and_traverse_filter_name_many(self): cont = container.ObjectProxyContainer(None, "default") cont._add_to_path("com.nokia", container.ObjectProxyContainer(TestC(), "test")) cont._add_to_path("com.nokia", container.ObjectProxyContainer(TestC(), "foo")) cont._add_to_path("com", container.ObjectProxyContainer(TestC(), "bar")) cont.com._list() ret = cont._traverse(path=".*nokia.*") self.assertEquals(len(ret), 3) self.assertEquals(ret[0]._path(), "default.com.nokia")
def test_create_none_container(self): cont = container.ObjectProxyContainer(None) self.assertTrue(cont) try: cont.test() self.fail("calling None succeeds?") except AttributeError: pass
def test_add_children_and_traverse_filter_class_proxies(self): cont = container.ObjectProxyContainer(None, "default") cont._add_to_path("com.nokia", container.ObjectProxyContainer(TestC(), "test")) cont._add_to_path("com.nokia", container.ObjectProxyContainer(TestC(), "foo")) cont._add_to_path("com", container.ObjectProxyContainer(TestC(), "bar")) cont._add_to_path("com.nokia", container.ObjectProxyContainer(TestB(), "bee")) cont.com.nokia._add(container.ObjectProxyContainer(TestB(), "vee")) ret = cont._traverse( filters=[lambda x: isinstance(x, container.ObjectProxyContainer)]) self.assertEquals(len(ret), 5) self.assertEquals(ret[0]._path(cont), "com.nokia.test") self.assertEquals(ret[1]._path(cont), "com.nokia.foo")
def test_add_child(self): cont = container.ObjectProxyContainer(None) obj = TestC() cont._add(container.ObjectProxyContainer(obj, "test")) self.assertEquals(cont._list(), ['test']) self.assertEquals(cont.test._obj, obj)
def test_create_object_container(self): cont = container.ObjectProxyContainer(TestC()) self.assertTrue(cont)
def test_create_object_container_for_string(self): cont = container.ObjectProxyContainer("Test") self.assertTrue(cont) self.assertEquals(cont.startswith("Test"), True)
def test_create_object_container_for_test(self): cont = container.ObjectProxyContainer(TestC("foo")) self.assertTrue(cont) self.assertEquals(cont.test(), "test string")