Revision: 21069 http://gar.svn.sourceforge.net/gar/?rev=21069&view=rev Author: wahwah Date: 2013-05-13 22:54:09 +0000 (Mon, 13 May 2013) Log Message: ----------- pkgdb: Fix inspective_package unit tests
Modified Paths: -------------- csw/mgar/gar/v2/lib/python/inspective_package.py csw/mgar/gar/v2/lib/python/inspective_package_test.py Modified: csw/mgar/gar/v2/lib/python/inspective_package.py =================================================================== --- csw/mgar/gar/v2/lib/python/inspective_package.py 2013-05-13 22:53:53 UTC (rev 21068) +++ csw/mgar/gar/v2/lib/python/inspective_package.py 2013-05-13 22:54:09 UTC (rev 21069) @@ -15,6 +15,7 @@ import shell import mmap import tempfile +import io from elftools.elf.elffile import ELFFile from elftools.elf.enums import ENUM_E_MACHINE @@ -282,12 +283,20 @@ binary_info = {'version definition': [], 'version needed': []} - if not os.fstat(elfdump_output_file.fileno()).st_size: + try: + file_size = os.fstat(elfdump_output_file.fileno()).st_size + except io.UnsupportedOperation: + file_size = len(elfdump_output_file.getvalue()) + if not file_size: binary_info['symbol table'] = [] binaries_elf_info[binary] = binary_info continue - elfdump_output = mmap.mmap(elfdump_output_file.fileno(), 0, prot=mmap.PROT_READ) + try: + fileno = elfdump_output_file.fileno() + elfdump_output = mmap.mmap(fileno, 0, prot=mmap.PROT_READ) + except io.UnsupportedOperation: + elfdump_output = elfdump_output_file cur_section = None for line in iter(elfdump_output.readline, ""): Modified: csw/mgar/gar/v2/lib/python/inspective_package_test.py =================================================================== --- csw/mgar/gar/v2/lib/python/inspective_package_test.py 2013-05-13 22:53:53 UTC (rev 21068) +++ csw/mgar/gar/v2/lib/python/inspective_package_test.py 2013-05-13 22:54:09 UTC (rev 21069) @@ -9,6 +9,8 @@ import magic import os import common_constants +import tempfile +import io LDD_R_OUTPUT_1 = """\tlibc.so.1 => /lib/libc.so.1 \tsymbol not found: check_encoding_conversion_args (/opt/csw/lib/postgresql/8.4/utf8_and_gbk.so) @@ -135,7 +137,7 @@ -class InspectivePackageUnitTest(mox.MoxTestBase): +class InspectivePackageUnitTest(mox.MoxTestBase, unittest.TestCase): def testListBinaries(self): self.mox.StubOutWithMock(os, 'access') @@ -220,6 +222,11 @@ def testGetBinaryElfInfoRoot(self): + self.mox.StubOutWithMock(tempfile, 'TemporaryFile') + fake_file = io.BytesIO() + fake_file.write(ELFDUMP_OUTPUT) + fake_file.seek(0) + tempfile.TemporaryFile().AndReturn(fake_file) fake_binary = 'opt/csw/lib/libssl.so.1.0.0' fake_package_path = '/fake/path/CSWfoo' @@ -235,12 +242,20 @@ args = [common_constants.ELFDUMP_BIN, '-svy', os.path.join(fake_package_path, "root", fake_binary)] - shell.ShellCommand(args, allow_error=True).AndReturn((0, ELFDUMP_OUTPUT, "")) + shell.ShellCommand( + args, + allow_error=True, + stdout=mox.IgnoreArg()).AndReturn((0, "", "")) self.mox.ReplayAll() self.assertEqual(BINARY_ELFINFO, ip.GetBinaryElfInfo()) def testGetBinaryElfInfoReloc(self): + self.mox.StubOutWithMock(tempfile, 'TemporaryFile') + fake_file = io.BytesIO() + fake_file.write(ELFDUMP_OUTPUT) + fake_file.seek(0) + tempfile.TemporaryFile().AndReturn(fake_file) fake_binary = 'lib/libssl.so.1.0.0' fake_package_path = '/fake/path/CSWfoo' @@ -256,7 +271,7 @@ args = [common_constants.ELFDUMP_BIN, '-svy', os.path.join(fake_package_path, "reloc", fake_binary)] - shell.ShellCommand(args, allow_error=True).AndReturn((0, ELFDUMP_OUTPUT, "")) + shell.ShellCommand(args, allow_error=True, stdout=fake_file).AndReturn((0, "", "")) self.mox.ReplayAll() self.assertEqual(BINARY_ELFINFO, ip.GetBinaryElfInfo()) @@ -296,6 +311,12 @@ 'version definition': [], } } + self.maxDiff = None + self.mox.StubOutWithMock(tempfile, 'TemporaryFile') + fake_file = io.BytesIO() + fake_file.write(fake_elfdump_output) + fake_file.seek(0) + tempfile.TemporaryFile().AndReturn(fake_file) ip = inspective_package.InspectivePackage(fake_package_path) self.mox.StubOutWithMock(ip, 'ListBinaries') self.mox.StubOutWithMock(ip, 'GetBasedir') @@ -308,7 +329,10 @@ args = [common_constants.ELFDUMP_BIN, '-svy', os.path.join(fake_package_path, "root", fake_binary)] - shell.ShellCommand(args, allow_error=True).AndReturn((0, fake_elfdump_output, fake_elfdump_errors)) + shell.ShellCommand( + args, + allow_error=True, + stdout=fake_file).AndReturn((0, fake_elfdump_output, fake_elfdump_errors)) self.mox.ReplayAll() self.assertEqual(fake_binary_elfinfo, ip.GetBinaryElfInfo()) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. _______________________________________________ devel mailing list devel@lists.opencsw.org https://lists.opencsw.org/mailman/listinfo/devel