Example #1
0
    def test_multiple_chunk_streams(self):
        c = chunks.Chunker()

        c1 = c(3, '\x00\x00\x00', VecBuf(['.' * 16]))
        c2 = c(4, '\x01\x01\x01', VecBuf([',' * 16]))

        i = 1
        cs1, cs2 = [], []
        while 1:
            c.set_chunk_size(i)
            try:
                (h1, b1), (h2, b2) = c1.next(), c2.next()
            except StopIteration:
                break
            cs1.append(h1 + flatten(b1))
            cs2.append(h2 + flatten(b2))
            i += 1

        self.assertEquals(cs1,
                          ['\x00\x00\x00' + '.',
                           '\xc3' + '..',
                           '\xc3' + '...',
                           '\xc3' + '....',
                           '\xc3' + '.....',
                           '\xc3' + '.'])
        self.assertEquals(cs2,
                          ['\x01\x01\x01' + ',',
                           '\xc4' + ',,',
                           '\xc4' + ',,,',
                           '\xc4' + ',,,,',
                           '\xc4' + ',,,,,',
                           '\xc4' + ','])

        self.assertRaises(StopIteration, c1.next)
        self.assertRaises(StopIteration, c2.next)
Example #2
0
class TestChunker(unittest.TestCase):
    def assertChunkerMatches(self, chunker, test_chunks):
        chunker_chunks = [(h, flatten(body)) for (h, body) in chunker]
        self.assertEquals(chunker_chunks, test_chunks)

    def assertChunkMatches(self, (h, body), test_chunk):
        self.assertEquals((h, flatten(body)), test_chunk)
Example #3
0
 def assertFlattens(self, to_flatten, target, msg=''):
     return self.assertEquals(flatten(to_flatten), target, msg=msg)
Example #4
0
 def assertChunkerMatches(self, chunker, test_chunks):
     chunker_chunks = [(h, flatten(body)) for (h, body) in chunker]
     self.assertEquals(chunker_chunks, test_chunks)