def test_idFind(self): alpha = FakeContainer('alpha', []) delta = FakeContainer('delta', []) beta = FakeContainer('beta', [delta]) gamma = FakeContainer('gamma', []) tree = FakeContainer( 'tree', [alpha, beta, gamma]) find = FindAdapter(tree) # some simple searches result = find.find([SimpleIdFindFilter(['beta'])]) self.assertEqual([beta], result) result = find.find([SimpleIdFindFilter(['gamma'])]) self.assertEqual([gamma], result) result = find.find([SimpleIdFindFilter(['delta'])]) self.assertEqual([delta], result) # we should not find the container we search on result = find.find([SimpleIdFindFilter(['tree'])]) self.assertEqual([], result) # search for multiple ids result = find.find([SimpleIdFindFilter(['alpha', 'beta'])]) self.assertEqual([alpha, beta], result) result = find.find([SimpleIdFindFilter(['beta', 'delta'])]) self.assertEqual([beta, delta], result) # search without any filters, find everything result = find.find([]) self.assertEqual([alpha, beta, delta, gamma], result) # search for something that doesn't exist result = find.find([SimpleIdFindFilter(['foo'])]) self.assertEqual([], result) # find for something that has two ids at the same time, # can't ever be the case result = find.find([SimpleIdFindFilter(['alpha']), SimpleIdFindFilter(['beta'])]) self.assertEqual([], result)
def test_objectFind(self): alpha = FakeContainer('alpha', []) delta = FakeContainer('delta', []) beta = FakeContainer('beta', [delta]) gamma = FakeContainer('gamma', []) tree = FakeContainer('tree', [alpha, beta, gamma]) find = FindAdapter(tree) result = find.find(object_filters=[TestObjectFindFilter(0)]) self.assertEquals([alpha, delta, gamma], result) result = find.find(object_filters=[TestObjectFindFilter(1)]) self.assertEquals([beta], result) result = find.find(object_filters=[TestObjectFindFilter(2)]) self.assertEquals([], result)
def test_interfaceFind(self): alpha = FakeContainer('alpha', []) directlyProvides(alpha, FakeInterfaceBar) delta = FakeContainer('delta', []) directlyProvides(delta, FakeInterfaceFoo) beta = FakeContainer('beta', [delta]) directlyProvides(beta, FakeInterfaceSpam) gamma = FakeContainer('gamma', []) tree = FakeContainer('tree', [alpha, beta, gamma]) find = FindAdapter(tree) result = find.find(object_filters=[ SimpleInterfacesFindFilter(FakeInterfaceFoo, FakeInterfaceSpam) ]) self.assertEqual([beta, delta], result)
def test_combinedFind(self): alpha = FakeContainer('alpha', []) delta = FakeContainer('delta', []) beta = FakeContainer('beta', [delta]) gamma = FakeContainer('gamma', []) tree = FakeContainer('tree', [alpha, beta, gamma]) find = FindAdapter(tree) result = find.find(id_filters=[SimpleIdFindFilter(['alpha'])], object_filters=[TestObjectFindFilter(0)]) self.assertEqual([alpha], result) result = find.find(id_filters=[SimpleIdFindFilter(['alpha'])], object_filters=[TestObjectFindFilter(1)]) self.assertEqual([], result)
def test_interfaceFind(self): alpha = FakeContainer('alpha', []) directlyProvides(alpha, FakeInterfaceBar) delta = FakeContainer('delta', []) directlyProvides(delta, FakeInterfaceFoo) beta = FakeContainer('beta', [delta]) directlyProvides(beta, FakeInterfaceSpam) gamma = FakeContainer('gamma', []) tree = FakeContainer( 'tree', [alpha, beta, gamma]) find = FindAdapter(tree) result = find.find(object_filters=[ SimpleInterfacesFindFilter(FakeInterfaceFoo, FakeInterfaceSpam)]) self.assertEqual([beta, delta], result)
def test_objectFind(self): alpha = FakeContainer('alpha', []) delta = FakeContainer('delta', []) beta = FakeContainer('beta', [delta]) gamma = FakeContainer('gamma', []) tree = FakeContainer( 'tree', [alpha, beta, gamma]) find = FindAdapter(tree) result = find.find(object_filters=[TestObjectFindFilter(0)]) self.assertEqual([alpha, delta, gamma], result) result = find.find(object_filters=[TestObjectFindFilter(1)]) self.assertEqual([beta], result) result = find.find(object_filters=[TestObjectFindFilter(2)]) self.assertEqual([], result)
def test_combinedFind(self): alpha = FakeContainer('alpha', []) delta = FakeContainer('delta', []) beta = FakeContainer('beta', [delta]) gamma = FakeContainer('gamma', []) tree = FakeContainer( 'tree', [alpha, beta, gamma]) find = FindAdapter(tree) result = find.find(id_filters=[SimpleIdFindFilter(['alpha'])], object_filters=[TestObjectFindFilter(0)]) self.assertEquals([alpha], result) result = find.find(id_filters=[SimpleIdFindFilter(['alpha'])], object_filters=[TestObjectFindFilter(1)]) self.assertEquals([], result)
def test_idFind(self): alpha = FakeContainer('alpha', []) delta = FakeContainer('delta', []) beta = FakeContainer('beta', [delta]) gamma = FakeContainer('gamma', []) tree = FakeContainer('tree', [alpha, beta, gamma]) find = FindAdapter(tree) # some simple searches result = find.find([SimpleIdFindFilter(['beta'])]) self.assertEquals([beta], result) result = find.find([SimpleIdFindFilter(['gamma'])]) self.assertEquals([gamma], result) result = find.find([SimpleIdFindFilter(['delta'])]) self.assertEquals([delta], result) # we should not find the container we search on result = find.find([SimpleIdFindFilter(['tree'])]) self.assertEquals([], result) # search for multiple ids result = find.find([SimpleIdFindFilter(['alpha', 'beta'])]) self.assertEquals([alpha, beta], result) result = find.find([SimpleIdFindFilter(['beta', 'delta'])]) self.assertEquals([beta, delta], result) # search without any filters, find everything result = find.find([]) self.assertEquals([alpha, beta, delta, gamma], result) # search for something that doesn't exist result = find.find([SimpleIdFindFilter(['foo'])]) self.assertEquals([], result) # find for something that has two ids at the same time, # can't ever be the case result = find.find( [SimpleIdFindFilter(['alpha']), SimpleIdFindFilter(['beta'])]) self.assertEquals([], result)
def test_find_non_container_return_default(self): data = {'a': 42} self.assertEqual(FindAdapter(data).find(), [42])