def test_iter_last(self): for attr in self.schema: itr = sos.AttrIter(attr) self.assertTrue(itr.end()) obj = itr.item() self.assertEqual(obj2tuple(obj), self.input_data[len(self.input_data) - 1])
def test_iter_pos(self): for attr in self.schema: itr = sos.AttrIter(attr) self.assertTrue(itr.begin()) self.assertTrue(itr.next()) self.assertTrue(itr.next()) obj = itr.item() pos = itr.get_pos() self.assertIsNotNone(obj) itr2 = sos.AttrIter(attr) rc = itr2.set_pos(pos) self.assertEqual(rc, 0) obj2 = itr2.item() self.assertIsNotNone(obj2) self.assertEqual(obj[:], obj2[:])
def test_iter_pos_cleanup(self): poss = [] for count in range(0, 1024): for attr in self.schema: itr = sos.AttrIter(attr) self.assertTrue(itr.begin()) self.assertTrue(itr.next()) pos = itr.get_pos() self.assertIsNotNone(pos) poss.append([itr, pos])
def test_iter(self): for attr in self.schema: itr = sos.AttrIter(attr) data = [] b = itr.begin() while b: obj = itr.item() t = obj2tuple(obj) data.append(t) b = itr.next() self.assertEqual(data, self.input_data)
def test_iter_inf_exact(self): for attr in self.schema: aid = attr.attr_id() itr = sos.AttrIter(attr) for data in self.input_data: key = sos.Key(attr=attr) key.set_value(data[aid]) self.assertTrue(itr.find_inf(key)) obj = itr.item() self.assertEqual(obj2tuple(obj), data, msg="bad result attr: %s"%attr.name())
def test_iter_rev(self): for attr in self.schema: itr = sos.AttrIter(attr) data = [] b = itr.end() while b: obj = itr.item() t = obj2tuple(obj) data.append(t) b = itr.prev() data.reverse() self.assertEqual(data, self.input_data)
def test_iter_sup(self): for attr in self.schema: aid = attr.attr_id() itr = sos.AttrIter(attr) for idx in range(0, len(self.input_data), REPEAT): data = self.input_data[idx] key = self.attr_key_half_prev[aid](attr, data[aid]) self.assertTrue(itr.find_sup(key)) obj = itr.item() self.assertEqual(obj2tuple(obj)[aid], data[aid]) self.assertEqual(obj2tuple(obj), data) l0 = [obj2tuple(obj) for obj in SosIterWrap(itr)] l1 = self.input_data[idx:] self.assertEqual(l0, l1)
def test_iter_fwd_rev(self): for attr in self.schema: itr = sos.AttrIter(attr) data_fwd = [] itr.begin() for i in range(0, 10): data_fwd.append(obj2tuple(itr.item())) itr.next() data_rev = [] itr.prev() for i in range(0, 10): data_rev.append(obj2tuple(itr.item())) itr.prev() data_rev.reverse() self.assertEqual(data_fwd, data_rev)
def test_iter_inf(self): for attr in self.schema: aid = attr.attr_id() itr = sos.AttrIter(attr) for idx in range(0, len(self.input_data), REPEAT): data = self.input_data[idx] key = self.attr_key_half_next[aid](attr, data[aid]) itr.prop_set("inf_last_dup", 1) self.assertTrue(itr.find_inf(key)) obj = itr.item() self.assertEqual(obj2tuple(obj)[aid], data[aid]) self.assertEqual(obj2tuple(obj), data) l0 = [obj2tuple(obj) for obj in SosIterWrap(itr, rev=True)] l0.reverse() l1 = self.input_data[:(idx + REPEAT)] self.assertEqual(l0, l1)
def test_iter_pos_put_cleanup(self): poss = [] for count in range(0, 128): for attr in self.schema: itr = sos.AttrIter(attr) self.assertTrue(itr.begin()) self.assertTrue(itr.next()) self.assertTrue(itr.next()) pos = itr.get_pos() self.assertIsNotNone(pos) poss.append([itr, pos]) # Put all the positions for pos in poss: rc = pos[0].put_pos(pos[1]) self.assertEqual(rc, 0) # Confirm that the positions are invalid after put for pos in poss: rc = pos[0].set_pos(pos[1]) self.assertEqual(rc, errno.ENOENT)
def test_iter_begin(self): for attr in self.schema: itr = sos.AttrIter(attr) self.assertTrue(itr.begin()) self.assertEqual(obj2tuple(itr.item()), self.input_data[0])