def set_source_select(cls, rpath, tuplelist, *filelists): """Initialize select object using tuplelist Note that each list in filelists must each be passed as separate arguments, so each is recognized as a file by the connection. Otherwise we will get an error because a list containing files can't be pickled. Also, cls._source_select needs to be cached so get_diffs below can retrieve the necessary rps. """ sel = selection.Select(rpath) sel.parse_selection_args(tuplelist, filelists) sel_iter = sel.get_select_iter() cache_size = Globals.pipeline_max_length * 3 # to and from+leeway cls._source_select = rorpiter.CacheIndexable(sel_iter, cache_size)
def testCaching(self): """Test basic properties of CacheIndexable object""" self.d = {} ci = rorpiter.CacheIndexable(self.get_iter(), 3) for i in range(3): # call 3 times next next(ci) self.assertEqual(ci.get((1, )), self.d[(1, )]) self.assertIsNone(ci.get((3, ))) for i in range(3): # call 3 times next next(ci) self.assertEqual(ci.get((3, )), self.d[(3, )]) self.assertEqual(ci.get((4, )), self.d[(4, )]) self.assertIsNone(ci.get((3, 5))) self.assertRaises(AssertionError, ci.get, (1, ))
def testCaching(self): """Test basic properties of CacheIndexable object""" self.d = {} ci = rorpiter.CacheIndexable(self.get_iter(), 3) val0 = ci.next() val1 = ci.next() val2 = ci.next() assert ci.get((1, )) == self.d[(1, )] assert ci.get((3, )) is None val3 = ci.next() val4 = ci.next() val5 = ci.next() assert ci.get((3, )) == self.d[(3, )] assert ci.get((4, )) == self.d[(4, )] assert ci.get((3, 5)) is None self.assertRaises(AssertionError, ci.get, (1, ))
def testEqual(self): """Make sure CI doesn't alter properties of underlying iter""" self.d = {} l1 = list(self.get_iter()) l2 = list(rorpiter.CacheIndexable(iter(l1), 10)) assert l1 == l2, (l1, l2)