def test_overwrite(self):
        """
        L{twisted.python.zipstream.unzip} and
        L{twisted.python.zipstream.unzipIter} shouldn't overwrite files unless
        the 'overwrite' flag is passed
        """
        testfile = self.unzipdir.child('0')
        zpfilename = self.makeZipFile(['OVERWRITTEN'])

        testfile.setContent('NOT OVERWRITTEN')
        zipstream.unzip(zpfilename, self.unzipdir.path)
        self.assertEquals(testfile.open().read(), 'NOT OVERWRITTEN')
        zipstream.unzip(zpfilename, self.unzipdir.path, overwrite=True)
        self.assertEquals(testfile.open().read(), 'OVERWRITTEN')

        testfile.setContent('NOT OVERWRITTEN')
        uziter = zipstream.unzipIter(zpfilename, self.unzipdir.path)
        uziter.next()
        self.assertEquals(testfile.open().read(), 'NOT OVERWRITTEN')
        uziter = zipstream.unzipIter(zpfilename, self.unzipdir.path,
                                     overwrite=True)
        uziter.next()
        self.assertEquals(testfile.open().read(), 'OVERWRITTEN')
    def test_unzipIter(self):
        """
        L{twisted.python.zipstream.unzipIter} should unzip a file for each
        iteration and yield the number of files left to unzip after that
        iteration
        """
        numfiles = 10
        contents = ['This is test file %d!' % i for i in range(numfiles)]
        zpfilename = self.makeZipFile(contents)
        uziter = zipstream.unzipIter(zpfilename, self.unzipdir.path)
        for i in range(numfiles):
            self.assertEquals(len(list(self.unzipdir.children())), i)
            self.assertEquals(uziter.next(), numfiles - i - 1)
        self.assertEquals(len(list(self.unzipdir.children())), numfiles)

        for child in self.unzipdir.children():
            num = int(child.basename())
            self.assertEquals(child.open().read(), contents[num])