import os, shutil, zipfile import unittest class TestZipFile(unittest.TestCase): def setUp(self): self.src = 'zip.zip' self.target = "deleteme.zip" emptyFile = 'empty.txt' with open(emptyFile, 'w') as f: f.write('') with zipfile.ZipFile(self.src, 'w') as zipFile: zipFile.write(emptyFile) os.remove(emptyFile) def testDeleteZipTestZip(self): src = self.src target = self.target shutil.copy(src, target) with zipfile.ZipFile(target, 'r') as zipFile: zipFile.testzip() os.remove(target) self.assertEquals(os.path.isfile(target), False) def testDeleteZipExctractAll(self): src = self.src target = self.target shutil.copy(src, target) with zipfile.ZipFile(target, 'r') as zipFile: zipFile.extractall("extract") shutil.rmtree("extract") os.remove(target) self.assertEquals(os.path.isfile(target), False) def tearDown(self): os.remove(self.src) if __name__ == '__main__': unittest.main()