[csw-devel] SF.net SVN: gar:[8919] csw/mgar/gar/v2/lib/python

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Mon Mar 1 15:34:09 CET 2010


Revision: 8919
          http://gar.svn.sourceforge.net/gar/?rev=8919&view=rev
Author:   wahwah
Date:     2010-03-01 14:34:08 +0000 (Mon, 01 Mar 2010)

Log Message:
-----------
mGAR v2: checkpkg, better handling of bad catalognames.

Modified Paths:
--------------
    csw/mgar/gar/v2/lib/python/package_checks.py
    csw/mgar/gar/v2/lib/python/package_checks_old.py
    csw/mgar/gar/v2/lib/python/package_checks_test.py

Modified: csw/mgar/gar/v2/lib/python/package_checks.py
===================================================================
--- csw/mgar/gar/v2/lib/python/package_checks.py	2010-03-01 13:59:31 UTC (rev 8918)
+++ csw/mgar/gar/v2/lib/python/package_checks.py	2010-03-01 14:34:08 UTC (rev 8919)
@@ -12,6 +12,7 @@
 #   error_mgr.ReportError("something-is-wrong")
 
 import re
+import checkpkg
 
 PATHS_ALLOWED_ONLY_IN = {
     "CSWcommon": ["/opt",
@@ -64,6 +65,24 @@
     new_depends.add(pkgname)
 
 
+def CheckDescription(pkg_data, error_mgr, logger):
+  pkginfo = pkg_data["pkginfo"]
+  desc = checkpkg.ExtractDescription(pkginfo)
+  if not desc:
+    error_mgr.ReportError("pkginfo-description-missing")
+  else:
+    if len(desc) > MAX_DESCRIPTION_LENGTH:
+      error_mgr.ReportError("pkginfo-description-too-long")
+
+
+def CheckCatalogname(pkg_data, error_mgr, logger):
+  pkginfo = pkg_data["pkginfo"]
+  catalogname = pkginfo["NAME"].split(" ")[0]
+  catalogname_re = r"^(\w+)$"
+  if not re.match(catalogname_re, catalogname):
+    error_mgr.ReportError("pkginfo-bad-catalogname")
+
+
 def SetCheckDependencies(pkgs_data, error_mgr, logger):
   """Dependencies must be either installed in the system, or in the set."""
   pass

Modified: csw/mgar/gar/v2/lib/python/package_checks_old.py
===================================================================
--- csw/mgar/gar/v2/lib/python/package_checks_old.py	2010-03-01 13:59:31 UTC (rev 8918)
+++ csw/mgar/gar/v2/lib/python/package_checks_old.py	2010-03-01 14:34:08 UTC (rev 8919)
@@ -24,7 +24,7 @@
     errors.append(checkpkg.CheckpkgTag(
       pkg_data["basic_stats"]["pkgname"],
       "catalogname-not-lowercase"))
-  if not re.match(r"^\w+$", catalogname):
+  if not re.match(r"^[\w_]+$", catalogname):
     errors.append(checkpkg.CheckpkgTag(
       pkg_data["basic_stats"]["pkgname"],
       "catalogname-is-not-a-simple-word"))
@@ -99,13 +99,6 @@
   if not "VERSION" in pkginfo or not pkginfo["VERSION"]:
     errors.append(checkpkg.CheckpkgTag(
       pkgname, "pkginfo-version-field-missing"))
-  desc = checkpkg.ExtractDescription(pkginfo)
-  if not desc:
-    errors.append(checkpkg.CheckpkgTag(
-      pkgname, "description-missing"))
-  if len(desc) > MAX_DESCRIPTION_LENGTH:
-    errors.append(checkpkg.CheckpkgTag(
-      pkgname, "description-too-long"))
   # maintname=`sed -n 's/^VENDOR=.*for CSW by //p' $TMPFILE`
   maintname = checkpkg.ExtractMaintainerName(pkginfo)
   if not maintname:

Modified: csw/mgar/gar/v2/lib/python/package_checks_test.py
===================================================================
--- csw/mgar/gar/v2/lib/python/package_checks_test.py	2010-03-01 13:59:31 UTC (rev 8918)
+++ csw/mgar/gar/v2/lib/python/package_checks_test.py	2010-03-01 14:34:08 UTC (rev 8919)
@@ -13,28 +13,48 @@
 BASE_DIR = os.path.dirname(__file__)
 TESTDATA_DIR = os.path.join(BASE_DIR, "testdata")
 CHECKPKG_STATS_DIR = os.path.join(TESTDATA_DIR, "stats")
-DEFAULT_MD5 = "461a24f02dd5020b4aa014b76f3ec2cc"
 
-class CheckpkgUnitTest(unittest.TestCase):
-  """Write a helper function using mox."""
+class CheckpkgUnitTestHelper(object):
+  """Wraps common components of checkpkg tests."""
+  MD5 = "461a24f02dd5020b4aa014b76f3ec2cc"
 
   def setUp(self):
-    self.pkg_stats = checkpkg.PackageStats(None,
-                                           CHECKPKG_STATS_DIR,
-                                           DEFAULT_MD5)
+    # This is slow. Let's speed it up somehow.  Move away from yaml and create
+    # a Python module with the data.
+    self.pkg_stats = checkpkg.PackageStats(None, CHECKPKG_STATS_DIR, self.MD5)
     self.pkg_data = self.pkg_stats.GetAllStats()
     self.mocker = mox.Mox()
 
-  def testMultipleDepends(self):
-    logger_mock = self.mocker.CreateMock(logging.Logger)
-    error_mgr_mock = self.mocker.CreateMock(
+  def testDefault(self):
+    self.logger_mock = self.mocker.CreateMock(logging.Logger)
+    self.error_mgr_mock = self.mocker.CreateMock(
         checkpkg.CheckpkgManager2.IndividualErrorGatherer)
-    self.pkg_data["depends"].append(("CSWcommon", "This is surplus")) # this
-    error_mgr_mock.ReportError('dependency-listed-more-than-once', 'CSWcommon') # this
+    self.CheckpkgTest()
     self.mocker.ReplayAll()
-    pc.CheckMultipleDepends(self.pkg_data, error_mgr_mock, logger_mock) # name or variable
+    getattr(pc, self.FUNCTION_NAME)(self.pkg_data, self.error_mgr_mock, self.logger_mock)
     self.mocker.VerifyAll()
 
 
+class TestMultipleDepends(CheckpkgUnitTestHelper, unittest.TestCase):
+  FUNCTION_NAME = 'CheckMultipleDepends'
+  def CheckpkgTest(self):
+    self.pkg_data["depends"].append(("CSWcommon", "This is surplus"))
+    self.error_mgr_mock.ReportError('dependency-listed-more-than-once',
+                                    'CSWcommon')
+
+class TestDescription(CheckpkgUnitTestHelper, unittest.TestCase):
+  FUNCTION_NAME = 'CheckDescription'
+  def CheckpkgTest(self):
+    self.pkg_data["pkginfo"]["NAME"] = 'foo'
+    self.error_mgr_mock.ReportError('pkginfo-description-missing')
+
+
+class TestCheckCatalogname(CheckpkgUnitTestHelper, unittest.TestCase):
+  FUNCTION_NAME = 'CheckCatalogname'
+  def CheckpkgTest(self):
+    self.pkg_data["pkginfo"]["NAME"] = 'foo-bar - This catalog name is bad'
+    self.error_mgr_mock.ReportError('pkginfo-bad-catalogname')
+
+
 if __name__ == '__main__':
 	unittest.main()


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