def _createCpio(self, rpmName = None): if rpmName is None: rpmName = 'perl-Archive-Tar-1.46-68.fc11.x86_64.rpm' cpioPath = os.path.join(self.workDir, 'archive.cpio') rpmFile = file(os.path.join(self.archiveDir, rpmName)) rpmhelper.extractRpmPayload(rpmFile, file(cpioPath, "w")) return cpioPath
def testExtractRpmPayload(self): archives = [ ('popt-1.5-4x.i386.rpm', 78252), ('rpm-with-bzip-5.0.29-1.i386.rpm', 248), ] # We cannot unpack xz-compressed contents with /usr/bin/lzma if os.path.exists('/usr/bin/xz'): archives.extend([ ('popt-1.13-6.fc12.i686.rpm', 85544), ]) for rpmName, expectedSize in archives: fileobj = file(os.path.join(self.archiveDir, rpmName)) sio = StringIO.StringIO() rpmhelper.extractRpmPayload(fileobj, sio) sio.seek(0, 2) self.assertEqual(sio.tell(), expectedSize) # Test exception codepaths header = {rpmhelper.PAYLOADFORMAT: "super-payload format"} self.mock(rpmhelper, "readHeader", lambda x: header) e = self.assertRaises(rpmhelper.UnknownPayloadFormat, rpmhelper.extractRpmPayload, file("/dev/null"), None) self.assertEqual(e.args[0], "super-payload format") # No payload format, it should assume CPIO. Test compression header = {rpmhelper.PAYLOADCOMPRESSOR: "lame"} e = self.assertRaises(rpmhelper.UnknownCompressionType, rpmhelper.extractRpmPayload, file("/dev/null"), None) self.assertEqual(e.args[0], "lame") # No payload compressor defined we should detect gzip or # assume uncompressed header = {rpmhelper.PAYLOADFORMAT: "cpio"} fileIn = StringIO.StringIO() fileIn.write('\x1f\x8bThis should be some gziped data') fileIn.seek(0) def gzipFunc(*args, **kw): return 'Gzip File' self.mock(util, "GzipFile", gzipFunc) self.assertEqual(rpmhelper.UncompressedRpmPayload(fileIn), 'Gzip File') fileIn = StringIO.StringIO() fileIn.write('This is just some uncompressed data') fileIn.seek(0) self.assertEqual(rpmhelper.UncompressedRpmPayload(fileIn), fileIn)
def testExtractRpmPayload(self): archives = [("popt-1.5-4x.i386.rpm", 78252), ("rpm-with-bzip-5.0.29-1.i386.rpm", 248)] # We cannot unpack xz-compressed contents with /usr/bin/lzma if os.path.exists("/usr/bin/xz"): archives.extend([("popt-1.13-6.fc12.i686.rpm", 85544)]) for rpmName, expectedSize in archives: fileobj = file(os.path.join(self.archiveDir, rpmName)) sio = StringIO.StringIO() rpmhelper.extractRpmPayload(fileobj, sio) sio.seek(0, 2) self.assertEqual(sio.tell(), expectedSize) # Test exception codepaths header = {rpmhelper.PAYLOADFORMAT: "super-payload format"} self.mock(rpmhelper, "readHeader", lambda x: header) e = self.assertRaises(rpmhelper.UnknownPayloadFormat, rpmhelper.extractRpmPayload, file("/dev/null"), None) self.assertEqual(e.args[0], "super-payload format") # No payload format, it should assume CPIO. Test compression header = {rpmhelper.PAYLOADCOMPRESSOR: "lame"} e = self.assertRaises(rpmhelper.UnknownCompressionType, rpmhelper.extractRpmPayload, file("/dev/null"), None) self.assertEqual(e.args[0], "lame") # No payload compressor defined we should detect gzip or # assume uncompressed header = {rpmhelper.PAYLOADFORMAT: "cpio"} fileIn = StringIO.StringIO() fileIn.write("\x1f\x8bThis should be some gziped data") fileIn.seek(0) def gzipFunc(*args, **kw): return "Gzip File" self.mock(util, "GzipFile", gzipFunc) self.assertEqual(rpmhelper.UncompressedRpmPayload(fileIn), "Gzip File") fileIn = StringIO.StringIO() fileIn.write("This is just some uncompressed data") fileIn.seek(0) self.assertEqual(rpmhelper.UncompressedRpmPayload(fileIn), fileIn)