コード例 #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