예제 #1
0
파일: utest_utils.py 프로젝트: cfobel/durus
 def b(self):
     n = 1000
     s = BytesIO()
     word_array = WordArray(file=s, bytes_per_word=8, number_of_words=n)
     for x in xrange(n):
         word_array[x] = int8_to_str(x)
     assert word_array[-1] == int8_to_str(n - 1)
     for x in xrange(n):
         assert x == str_to_int8(word_array[x])
         word_array[x] = int8_to_str(2*x)
         assert x == str_to_int8(word_array[x]) / 2
     assert len(word_array) == n
     assert raises(IndexError, word_array.__getitem__, n + 1)
     s.seek(0)
     word_array2 = WordArray(file=s)
     word_array2[-1] = as_bytes('mmmmmmmm')
     assert word_array2[-1] == as_bytes('mmmmmmmm')
예제 #2
0
파일: utest_utils.py 프로젝트: cfobel/durus
 def a(self):
     s = BytesIO()
     b = ByteArray(size=10000, file=s)
     assert list(b) == [as_bytes('\x00') for j in xrange(10000)], list(b)
     for j in xrange(10000):
         assert as_bytes('\x00') == b[j]
     for j in xrange(10000):
         b[j] = as_bytes('!')
     for j in xrange(10000):
         assert as_bytes('!') == b[j]
     assert b[0:3] == as_bytes('!!!')
     assert b[47:50] == as_bytes('!!!'), repr(b[47:50])
     s = BytesIO()
     b2 = ByteArray(file=s)
     b2.set_size(10000, init_byte=as_bytes('\xff'))
     for j in xrange(10000):
         assert as_bytes('\xff') == b2[j], (j, b2[j])
     s.seek(0)
     raises(AssertionError, ByteArray, size=20000, file=s)
예제 #3
0
 def gen_stitch(self):
     """
     Return a generator that does the following as it is consumed.
     Build the linked list of holes.
     Each value is the index of the next hole plus self.start.
     The offset is added so that we can distinguish ordinary offsets,
     which are less than self.start, from elements of this linked list.
     """
     last_index = len(self.int_array) - 1
     for index in xrange(0, len(self.int_array)):
         if self.get(index) is None:
             self.int_array[index] = last_index + self.start
             last_index = index
         yield index
예제 #4
0
파일: shelf.py 프로젝트: Schevo/durus
 def gen_stitch(self):
     """
     Return a generator that does the following as it is consumed.
     Build the linked list of holes.
     Each value is the index of the next hole plus self.start.
     The offset is added so that we can distinguish ordinary offsets,
     which are less than self.start, from elements of this linked list.
     """
     last_index = len(self.int_array) - 1
     for index in xrange(0, len(self.int_array)):
         if self.get(index) is None:
             self.int_array[index] = last_index + self.start
             last_index = index
         yield index