[csw-devel] SF.net SVN: gar:[12087] csw/mgar/gar/v2

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Mon Dec 27 13:22:17 CET 2010


Revision: 12087
          http://gar.svn.sourceforge.net/gar/?rev=12087&view=rev
Author:   wahwah
Date:     2010-12-27 12:22:17 +0000 (Mon, 27 Dec 2010)

Log Message:
-----------
checkpkg: A unit test for ListBinaries

Also moving a file-inspecting function to the InspectivePackage class.

Modified Paths:
--------------
    csw/mgar/gar/v2/lib/python/inspective_package.py
    csw/mgar/gar/v2/lib/python/package.py
    csw/mgar/gar/v2/tests/run_tests.py

Added Paths:
-----------
    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	2010-12-27 11:02:09 UTC (rev 12086)
+++ csw/mgar/gar/v2/lib/python/inspective_package.py	2010-12-27 12:22:17 UTC (rev 12087)
@@ -33,8 +33,6 @@
       self.CheckPkgpathExists()
       self.files_metadata = []
       files_root = os.path.join(self.directory, "root")
-      if not os.path.exists(files_root):
-        return self.files_metadata
       all_files = self.GetAllFilePaths()
       def StripRe(x, strip_re):
         return re.sub(strip_re, "", x)
@@ -105,7 +103,18 @@
       self.binaries.sort()
     return self.binaries
 
+  def GetAllFilePaths(self):
+    """Returns a list of all paths from the package."""
+    if not self.file_paths:
+      self.CheckPkgpathExists()
+      remove_prefix = "%s/" % self.pkgpath
+      self.file_paths = []
+      for root, dirs, files in os.walk(os.path.join(self.pkgpath, "root")):
+        full_paths = [os.path.join(root, f) for f in files]
+        self.file_paths.extend([f.replace(remove_prefix, "") for f in full_paths])
+    return self.file_paths
 
+
 class FileMagic(object):
   """Libmagic sometimes returns None, which I think is a bug.
   Trying to come up with a way to work around that.  It might not even be

Added: csw/mgar/gar/v2/lib/python/inspective_package_test.py
===================================================================
--- csw/mgar/gar/v2/lib/python/inspective_package_test.py	                        (rev 0)
+++ csw/mgar/gar/v2/lib/python/inspective_package_test.py	2010-12-27 12:22:17 UTC (rev 12087)
@@ -0,0 +1,48 @@
+#!/usr/bin/env python2.6
+
+import unittest
+import inspective_package
+import mox
+import hachoir_parser
+import magic
+import os
+
+class InspectivePackageUnitTest(mox.MoxTestBase):
+
+  def testOne(self):
+    self.mox.StubOutWithMock(hachoir_parser, 'createParser',
+        use_mock_anything=True)
+    hachoir_parser_mock = self.mox.CreateMockAnything()
+    hachoir_parser.createParser(
+        u'/fake/path/CSWfoo/root/foo-file').AndReturn(hachoir_parser_mock)
+    machine_mock = self.mox.CreateMockAnything()
+    machine_mock.value = 2
+    hachoir_parser_mock.__getitem__('/header/machine').AndReturn(machine_mock)
+    endian_mock = self.mox.CreateMockAnything()
+    endian_mock.display = 'fake-endian'
+    hachoir_parser_mock.__getitem__('/header/endian').AndReturn(endian_mock)
+    magic_cookie_mock = self.mox.CreateMockAnything()
+    self.mox.StubOutWithMock(magic, 'open')
+    magic.open(0).AndReturn(magic_cookie_mock)
+    magic_cookie_mock.load()
+    magic_cookie_mock.setflags(magic.MAGIC_MIME)
+    magic_cookie_mock.file(
+        u'/fake/path/CSWfoo/root/foo-file').AndReturn(
+            "application/x-executable")
+    self.mox.StubOutWithMock(os.path, 'isdir')
+    self.mox.StubOutWithMock(os, 'walk')
+    os.path.isdir("/fake/path/CSWfoo").AndReturn(True)
+    os.path.isdir("/fake/path/CSWfoo").AndReturn(True)
+    os.path.isdir("/fake/path/CSWfoo").AndReturn(True)
+    os.walk("/fake/path/CSWfoo/root").AndReturn(
+        [
+          ("/fake/path/CSWfoo/root", [], ["foo-file"]),
+        ]
+    )
+    self.mox.ReplayAll()
+    ip = inspective_package.InspectivePackage("/fake/path/CSWfoo")
+    self.assertEqual(["foo-file"], ip.ListBinaries())
+
+
+if __name__ == '__main__':
+	unittest.main()


Property changes on: csw/mgar/gar/v2/lib/python/inspective_package_test.py
___________________________________________________________________
Added: svn:executable
   + *

Modified: csw/mgar/gar/v2/lib/python/package.py
===================================================================
--- csw/mgar/gar/v2/lib/python/package.py	2010-12-27 11:02:09 UTC (rev 12086)
+++ csw/mgar/gar/v2/lib/python/package.py	2010-12-27 12:22:17 UTC (rev 12087)
@@ -360,17 +360,6 @@
       raise PackageError("%s does not exist or is not a directory"
                          % self.directory)
 
-  def GetAllFilePaths(self):
-    """Returns a list of all paths from the package."""
-    if not self.file_paths:
-      self.CheckPkgpathExists()
-      remove_prefix = "%s/" % self.pkgpath
-      self.file_paths = []
-      for root, dirs, files in os.walk(os.path.join(self.pkgpath, "root")):
-        full_paths = [os.path.join(root, f) for f in files]
-        self.file_paths.extend([f.replace(remove_prefix, "") for f in full_paths])
-    return self.file_paths
-
   def _GetOverridesStream(self, file_path):
     # This might potentially cause a file descriptor leak, but I'm not going to
     # worry about that at this stage.

Modified: csw/mgar/gar/v2/tests/run_tests.py
===================================================================
--- csw/mgar/gar/v2/tests/run_tests.py	2010-12-27 11:02:09 UTC (rev 12086)
+++ csw/mgar/gar/v2/tests/run_tests.py	2010-12-27 12:22:17 UTC (rev 12087)
@@ -15,6 +15,7 @@
 from checkpkg_lib_test       import *
 from checkpkg_test           import *
 from dependency_checks_test  import *
+from inspective_package_test import *
 from ldd_emul_test           import *
 from models_test             import *
 from opencsw_test            import *


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.


More information about the devel mailing list