Beispiel #1
0
    def test_crc32(self):
        filename = make_random_temp_file()
        self.tempfiles.append(filename)

        consumer = Crc32Consumer()
        producer = FileProducer(filename)
        
        yield producer.beginProducing(consumer)
        
        self.assertEquals(consumer.crc32(), producer.crc32())
Beispiel #2
0
    def create_zipstream_from_tempfiles(self, num_files, min_size=0, max_size=10 * (1024 ** 2)):
        consumer = TestConsumer()
        zipstream = ZipStream(consumer)
        deferreds = []
        producers = {}

        for i in range(num_files):
            producersize = random.randint(min_size, max_size)
            filename = make_random_temp_file(producersize)

            producer = FileProducer(filename)
            deferreds.append(zipstream.addProducer(producer))
            producers.update({filename: producer})
            self.tempfiles.append(filename)

        deferredlist = DeferredList(deferreds)
        deferredlist.addCallback(lambda _: zipstream.centralDirectory())
        deferredlist.addCallback(lambda _: consumer.seek(0))
        yield deferredlist

        returnValue((zipstream, consumer, producers))