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

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Mon Mar 28 03:09:24 CEST 2011


Revision: 13969
          http://gar.svn.sourceforge.net/gar/?rev=13969&view=rev
Author:   wahwah
Date:     2011-03-28 01:09:24 +0000 (Mon, 28 Mar 2011)

Log Message:
-----------
checkpkg: Fix a bug doubled errors when re-running

It's funny that I once spent about two hours looking for that bug, and
gave up.  This time I simply saw it, there, in the code.

The problem was that the Run() method of the CheckManager2 class was
unconditionally calling a function with was registering checking
functions.  On the second run of checkpkg, all checks were registered
twice, on the third run -- three times, and so on.

The fix is to keep the state, and only register checks once.

This patch re-enables the unit test and fixes the bug.

Signed-off-by: Maciej Blizinski <maciej at opencsw.org>

Modified Paths:
--------------
    csw/mgar/gar/v2/lib/python/checkpkg_lib.py
    csw/mgar/gar/v2/lib/python/checkpkg_lib_test.py

Modified: csw/mgar/gar/v2/lib/python/checkpkg_lib.py
===================================================================
--- csw/mgar/gar/v2/lib/python/checkpkg_lib.py	2011-03-28 01:08:49 UTC (rev 13968)
+++ csw/mgar/gar/v2/lib/python/checkpkg_lib.py	2011-03-28 01:09:24 UTC (rev 13969)
@@ -492,6 +492,11 @@
   Its purpose is to reduce the amount of boilerplate code and allow for easier
   unit test writing.
   """
+
+  def __init__(self, *args, **kwargs):
+    super(CheckpkgManager2, self).__init__(*args, **kwargs)
+    self.checks_registered = False
+
   def _RegisterIndividualCheck(self, function):
     self.individual_checks.append(function)
 
@@ -501,6 +506,9 @@
   def _AutoregisterChecks(self):
     """Autodetects all defined checks."""
     logging.debug("CheckpkgManager2._AutoregisterChecks()")
+    if self.checks_registered:
+      logging.debug("Checks already registered.")
+      return
     checkpkg_module = package_checks
     members = dir(checkpkg_module)
     for member_name in members:
@@ -513,6 +521,7 @@
         elif member_name.startswith("SetCheck"):
           logging.debug("Registering set check %s", repr(member_name))
           self._RegisterSetCheck(member)
+    self.checks_registered = True
 
   def _ReportDependencies(self, checkpkg_interface, needed_files, needed_pkgs,
       messenger, declared_deps_by_pkgname):

Modified: csw/mgar/gar/v2/lib/python/checkpkg_lib_test.py
===================================================================
--- csw/mgar/gar/v2/lib/python/checkpkg_lib_test.py	2011-03-28 01:08:49 UTC (rev 13968)
+++ csw/mgar/gar/v2/lib/python/checkpkg_lib_test.py	2011-03-28 01:09:24 UTC (rev 13969)
@@ -351,7 +351,7 @@
     # Verifying that there are some reported error tags.
     self.assertTrue(list(models.CheckpkgErrorTag.select()))
 
-  def disabled_testReRunCheckpkg(self):
+  def testReRunCheckpkg(self):
     """Error tags should not accumulate.
 
     FIXME(maciej): Figure out what's wrong with this one: It errors out.


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