← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~jtv/launchpad/test-cruft-soyuz into lp:launchpad/devel

 

Jeroen T. Vermeulen has proposed merging lp:~jtv/launchpad/test-cruft-soyuz into lp:launchpad/devel.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers): code


= Soyuz test cruft =

This gives the Soyuz tests some much-needed love.  Tough love, but still.  To give an impression of how much it was needed, the branch is vastly oversized, for which I apologize with few regrets.

You'll find 3 types of changes here:

1. Removed boilerplate.

Unit tests used to need some boilerplate at the end that is not dead wood.

2. Lint fixes.

As every true Launchpad engineer would, I ran "make lint" over the changes and cleaned up a few problems.  This is the majority of the diff.

3. Reuse fake classes from lp.testing.

I substituted FakeMethod and FakeTransaction for ad-hoc equivalents I found in the tests.  I extended FakeTransaction with a commit count to satisfy one of the use cases.

To test:
{{{
./bin/test -vvc -m lp.soyuz
}}}

Set apart some time for this.


Jeroen
-- 
https://code.launchpad.net/~jtv/launchpad/test-cruft-soyuz/+merge/30407
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jtv/launchpad/test-cruft-soyuz into lp:launchpad/devel.
=== modified file 'lib/lp/soyuz/browser/tests/test_archive_packages.py'
--- lib/lp/soyuz/browser/tests/test_archive_packages.py	2010-06-24 14:16:42 +0000
+++ lib/lp/soyuz/browser/tests/test_archive_packages.py	2010-07-20 14:01:15 +0000
@@ -12,8 +12,6 @@
     'test_suite',
     ]
 
-import unittest
-
 from zope.security.interfaces import Unauthorized
 
 from canonical.testing import LaunchpadFunctionalLayer
@@ -96,6 +94,3 @@
         view = create_initialized_view(self.ppa, "+index")
         menu = ArchiveNavigationMenu(view)
         self.assertTrue(menu.packages().enabled)
-
-def test_suite():
-    return unittest.TestLoader().loadTestsFromName(__name__)

=== modified file 'lib/lp/soyuz/browser/tests/test_breadcrumbs.py'
--- lib/lp/soyuz/browser/tests/test_breadcrumbs.py	2010-04-28 10:26:58 +0000
+++ lib/lp/soyuz/browser/tests/test_breadcrumbs.py	2010-07-20 14:01:15 +0000
@@ -1,10 +1,8 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 __metaclass__ = type
 
-import unittest
-
 from zope.component import getUtility
 
 from canonical.launchpad.webapp.publisher import canonical_url
@@ -65,9 +63,8 @@
 
     def test_personal_archive_subscription(self):
         subscription_url = canonical_url(self.personal_archive_subscription)
-        crumbs = self.getBreadcrumbsForObject(self.personal_archive_subscription)
+        crumbs = self.getBreadcrumbsForObject(
+            self.personal_archive_subscription)
         self.assertEquals(subscription_url, crumbs[-1].url)
-        self.assertEquals("Access to %s" % self.ppa.displayname, crumbs[-1].text)
-
-def test_suite():
-    return unittest.TestLoader().loadTestsFromName(__name__)
+        self.assertEquals(
+            "Access to %s" % self.ppa.displayname, crumbs[-1].text)

=== modified file 'lib/lp/soyuz/browser/tests/test_distrosourcepackagerelease.py'
--- lib/lp/soyuz/browser/tests/test_distrosourcepackagerelease.py	2010-07-06 11:52:17 +0000
+++ lib/lp/soyuz/browser/tests/test_distrosourcepackagerelease.py	2010-07-20 14:01:15 +0000
@@ -7,8 +7,6 @@
 
 __metaclass__ = type
 
-import unittest
-
 from zope.security.proxy import removeSecurityProxy
 
 from canonical.testing import LaunchpadFunctionalLayer
@@ -49,7 +47,3 @@
         view = create_initialized_view(self.dspr, "+index")
         html = view.__call__()
         self.failUnless('test_file.dsc (deleted)' in html)
-
-
-def test_suite():
-    return unittest.TestLoader().loadTestsFromName(__name__)

=== modified file 'lib/lp/soyuz/browser/tests/test_queue.py'
--- lib/lp/soyuz/browser/tests/test_queue.py	2010-03-09 15:33:12 +0000
+++ lib/lp/soyuz/browser/tests/test_queue.py	2010-07-20 14:01:15 +0000
@@ -10,7 +10,6 @@
     ]
 
 import transaction
-import unittest
 from zope.component import getUtility, queryMultiAdapter
 
 from canonical.launchpad.webapp.servers import LaunchpadTestRequest
@@ -185,7 +184,3 @@
         self.assertEquals(
             'NEW',
             getUtility(IPackageUploadSet).get(package_upload_id).status.name)
-
-def test_suite():
-    return unittest.TestLoader().loadTestsFromName(__name__)
-

=== modified file 'lib/lp/soyuz/browser/tests/test_sourcepackagerelease.py'
--- lib/lp/soyuz/browser/tests/test_sourcepackagerelease.py	2010-07-02 17:51:33 +0000
+++ lib/lp/soyuz/browser/tests/test_sourcepackagerelease.py	2010-07-20 14:01:15 +0000
@@ -11,8 +11,6 @@
     'test_suite',
     ]
 
-import unittest
-
 from zope.security.proxy import removeSecurityProxy
 
 from canonical.testing import (
@@ -109,6 +107,3 @@
         view = create_initialized_view(
             self.source_package_release, '+copyright')
         self.assertEqual(expected, view.highlighted_copyright)
-
-def test_suite():
-    return unittest.TestLoader().loadTestsFromName(__name__)

=== modified file 'lib/lp/soyuz/browser/tests/test_sourceslistentries.py'
--- lib/lp/soyuz/browser/tests/test_sourceslistentries.py	2009-09-07 14:54:34 +0000
+++ lib/lp/soyuz/browser/tests/test_sourceslistentries.py	2010-07-20 14:01:15 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 # pylint: disable-msg=F0401
@@ -13,8 +13,6 @@
     'test_suite',
     ]
 
-import unittest
-
 from lp.testing import TestCaseWithFactory
 
 from canonical.launchpad.webapp.servers import LaunchpadTestRequest
@@ -23,6 +21,7 @@
 from lp.soyuz.browser.sourceslist import (
     SourcesListEntries, SourcesListEntriesView)
 
+
 class TestDefaultSelectedSeries(TestCaseWithFactory):
     """Ensure that default selected series set from user-agent."""
 
@@ -166,6 +165,3 @@
         # When there is only one distro series it should always be the
         # default.
         self.failUnless(self.view.default_series == self.series[0])
-
-def test_suite():
-    return unittest.TestLoader().loadTestsFromName(__name__)

=== modified file 'lib/lp/soyuz/scripts/tests/test_archivecruftchecker.py'
--- lib/lp/soyuz/scripts/tests/test_archivecruftchecker.py	2009-08-28 06:39:38 +0000
+++ lib/lp/soyuz/scripts/tests/test_archivecruftchecker.py	2010-07-20 14:01:15 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """ArchiveCruftChecker tests.
@@ -25,6 +25,7 @@
 from canonical.launchpad.scripts.logger import QuietFakeLogger
 from canonical.testing import LaunchpadZopelessLayer
 
+
 # XXX cprov 2006-05-15: {create, remove}TestArchive functions should be
 # moved to the publisher test domain as soon as we have it.
 def createTestArchive():
@@ -60,7 +61,6 @@
         """Clean up test environment and remove the test archive."""
         removeTestArchive()
 
-
     def testInitializeSuccess(self):
         """Test ArchiveCruftChecker initialization process.
 
@@ -86,8 +86,7 @@
         # based on the given 'archive_path'.
         self.assertEqual(
             checker.dist_archive,
-            '/var/tmp/archive/ubuntutest/dists/breezy-autotest'
-            )
+            '/var/tmp/archive/ubuntutest/dists/breezy-autotest')
 
         # The 'components' dictionary contains all components selected
         # for the given distroseries organized as:
@@ -111,7 +110,7 @@
             'restricted',
             'restricted/debian-installer',
             'universe',
-            'universe/debian-installer'
+            'universe/debian-installer',
             ]
         self.assertEqual(sorted(checker.components_and_di), expected)
 
@@ -125,8 +124,7 @@
 
         self.assertEqual(
             checker.dist_archive,
-            '/var/tmp/archive/ubuntutest/dists/breezy-autotest-security'
-            )
+            '/var/tmp/archive/ubuntutest/dists/breezy-autotest-security')
 
     def testInitializeFailure(self):
         """ArchiveCruftCheck initialization failures.
@@ -149,7 +147,3 @@
             self.log, distribution_name='ubuntu', suite='breezy-autotest',
             archive_path=self.archive_path)
         self.assertRaises(ArchiveCruftCheckerError, checker.initialize)
-
-
-def test_suite():
-    return unittest.TestLoader().loadTestsFromName(__name__)

=== modified file 'lib/lp/soyuz/scripts/tests/test_buildd_cronscripts.py'
--- lib/lp/soyuz/scripts/tests/test_buildd_cronscripts.py	2010-05-20 14:28:51 +0000
+++ lib/lp/soyuz/scripts/tests/test_buildd_cronscripts.py	2010-07-20 14:01:15 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """cronscripts/buildd-* tests."""
@@ -149,12 +149,12 @@
         qb = self.getQueueBuilder(distribution='boing')
         self.assertRaises(LaunchpadScriptFailure, qb.calculateDistroseries)
 
-        qb = self.getQueueBuilder(suites=('hoary-test',))
+        qb = self.getQueueBuilder(suites=('hoary-test', ))
         self.assertRaises(LaunchpadScriptFailure, qb.calculateDistroseries)
 
         # A single valid suite argument results in a list with one
         # distroseries (pockets are completely ignored).
-        qb = self.getQueueBuilder(suites=('warty-security',))
+        qb = self.getQueueBuilder(suites=('warty-security', ))
         self.assertEqual(
             ['warty'],
             [distroseries.name
@@ -179,7 +179,7 @@
         # Restricting the build creation to another distroseries
         # does not create any builds.
         source = self.getSourceWithoutBuilds()
-        queue_builder = self.getQueueBuilder(suites=('warty',))
+        queue_builder = self.getQueueBuilder(suites=('warty', ))
         queue_builder.main()
         self.assertEqual(0, len(source.getBuilds()))
 
@@ -187,7 +187,7 @@
         # A build is created when queue-builder is restricted to the
         # distroseries where the testing source is published
         source = self.getSourceWithoutBuilds()
-        queue_builder = self.getQueueBuilder(suites=('hoary',))
+        queue_builder = self.getQueueBuilder(suites=('hoary', ))
         queue_builder.main()
         self.assertEqual(1, len(source.getBuilds()))
 
@@ -303,7 +303,3 @@
             self.getPendingBuilds().count())
         self.assertEqual(depwait_build.status.name, 'NEEDSBUILD')
         self.assertEqual(depwait_build.buildqueue_record.lastscore, 1755)
-
-
-def test_suite():
-    return unittest.TestLoader().loadTestsFromName(__name__)

=== modified file 'lib/lp/soyuz/scripts/tests/test_changeoverride.py'
--- lib/lp/soyuz/scripts/tests/test_changeoverride.py	2009-08-28 07:34:44 +0000
+++ lib/lp/soyuz/scripts/tests/test_changeoverride.py	2010-07-20 14:01:15 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """`ChangeOverride` script class tests."""
@@ -517,7 +517,3 @@
             SoyuzScriptError, changer.processBinaryChange, 'biscuit')
         self.assertRaises(
             SoyuzScriptError, changer.processChildrenChange, 'cookie')
-
-
-def test_suite():
-    return unittest.TestLoader().loadTestsFromName(__name__)

=== modified file 'lib/lp/soyuz/scripts/tests/test_chrootmanager.py'
--- lib/lp/soyuz/scripts/tests/test_chrootmanager.py	2009-06-25 04:06:00 +0000
+++ lib/lp/soyuz/scripts/tests/test_chrootmanager.py	2010-07-20 14:01:15 +0000
@@ -1,11 +1,11 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """ChrootManager facilities tests."""
 
 __metaclass__ = type
 
-from unittest import TestCase, TestLoader
+from unittest import TestCase
 import os
 import re
 import tempfile
@@ -157,7 +157,3 @@
 
         self.assertRaises(
             ChrootManagerError, chroot_manager.add)
-
-
-def test_suite():
-    return TestLoader().loadTestsFromName(__name__)

=== modified file 'lib/lp/soyuz/scripts/tests/test_copypackage.py'
--- lib/lp/soyuz/scripts/tests/test_copypackage.py	2010-05-26 08:54:17 +0000
+++ lib/lp/soyuz/scripts/tests/test_copypackage.py	2010-07-20 14:01:15 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 __metaclass__ = type
@@ -1352,8 +1352,7 @@
         self.assertEqual(
             sorted(copied_ids), sorted(pending_ids),
             "The copy did not succeed.\nExpected IDs: %s\nFound IDs: %s" % (
-                sorted(copied_ids), sorted(pending_ids))
-            )
+                sorted(copied_ids), sorted(pending_ids)))
 
     def testCopyBetweenDistroSeries(self):
         """Check the copy operation between distroseries."""
@@ -2275,7 +2274,7 @@
             "--ppa", "joe",
             "--ppa-name", "ppa",
             "-s", "%s" % ppa_source.distroseries.name + "-security",
-            "foo"
+            "foo",
             ]
 
         script = UnembargoSecurityPackage(
@@ -2324,7 +2323,7 @@
         test_args = [
             "--ppa", "cprov",
             "-s", "warty-backports",
-            "foo"
+            "foo",
             ]
 
         script = UnembargoSecurityPackage(
@@ -2641,7 +2640,3 @@
             None,
             checker.checkCopy(test2_source, warty,
             PackagePublishingPocket.RELEASE))
-
-
-def test_suite():
-    return unittest.TestLoader().loadTestsFromName(__name__)

=== modified file 'lib/lp/soyuz/scripts/tests/test_expire_archive_files.py'
--- lib/lp/soyuz/scripts/tests/test_expire_archive_files.py	2010-03-10 11:13:55 +0000
+++ lib/lp/soyuz/scripts/tests/test_expire_archive_files.py	2010-07-20 14:01:15 +0000
@@ -1,11 +1,10 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Test the expire-archive-files.py script. """
 
 from datetime import datetime, timedelta
 import pytz
-import unittest
 
 from zope.component import getUtility
 
@@ -99,9 +98,10 @@
 
 class ArchiveExpiryCommonTests(object):
     """Common source/binary expiration test cases.
-    
+
     These will be shared irrespective of archive type (ppa/partner).
     """
+
     def testNoExpirationWithNoDateremoved(self):
         """Test that no expiring happens if no dateremoved set."""
         pkg1 = self.stp.getPubSource(
@@ -216,7 +216,7 @@
 
 class TestPPAExpiry(ArchiveExpiryTestBase, ArchiveExpiryCommonTests):
     """Test the expire-archive-files.py script.
-    
+
     Here we make use of the common test cases defined in the base class but
     also add tests specific to PPAs (excluding particular PPAs from expiry
     based on a "black list" or on the fact that PPA is private).
@@ -262,7 +262,3 @@
             purpose=ArchivePurpose.PARTNER)
         self.archive2 = self.factory.makeArchive(
             purpose=ArchivePurpose.PARTNER)
-
-
-def test_suite():
-    return unittest.TestLoader().loadTestsFromName(__name__)

=== modified file 'lib/lp/soyuz/scripts/tests/test_gina.py'
--- lib/lp/soyuz/scripts/tests/test_gina.py	2010-07-14 14:11:15 +0000
+++ lib/lp/soyuz/scripts/tests/test_gina.py	2010-07-20 14:01:15 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 import unittest
@@ -12,4 +12,3 @@
     suite = unittest.TestSuite()
     suite.addTest(DocTestSuite(lp.soyuz.scripts.gina.handlers))
     return suite
-

=== modified file 'lib/lp/soyuz/scripts/tests/test_lpquerydistro.py'
--- lib/lp/soyuz/scripts/tests/test_lpquerydistro.py	2009-12-13 11:55:40 +0000
+++ lib/lp/soyuz/scripts/tests/test_lpquerydistro.py	2010-07-20 14:01:15 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 __metaclass__ = type
@@ -65,7 +65,7 @@
         Check that:
          * return code is ONE,
          * standard output is empty
-         * standard error contains the additional information about the failure.
+         * standard error contains additional information about the failure.
         """
         returncode, out, err = self.runLpQueryDistro(
             extra_args=[])
@@ -103,7 +103,7 @@
         Check if:
          * return code is ONE,
          * standard output is empty
-         * standard error contains the additional information about the failure.
+         * standard error contains additional information about the failure.
         """
         returncode, out, err = self.runLpQueryDistro(
             extra_args=['-s', 'hoary', 'current'])
@@ -257,7 +257,3 @@
         self.assertEqual(helper.nominated_arch_indep, 'i386')
         self.assertEqual(helper.pocket_suffixes,
                          '-backports -proposed -security -updates')
-
-
-def test_suite():
-    return unittest.TestLoader().loadTestsFromName(__name__)

=== modified file 'lib/lp/soyuz/scripts/tests/test_obsoletedistroseries.py'
--- lib/lp/soyuz/scripts/tests/test_obsoletedistroseries.py	2010-01-31 19:36:27 +0000
+++ lib/lp/soyuz/scripts/tests/test_obsoletedistroseries.py	2010-07-20 14:01:15 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 __metaclass__ = type
@@ -21,6 +21,7 @@
 from lp.registry.interfaces.distribution import IDistributionSet
 from lp.registry.interfaces.series import SeriesStatus
 from lp.soyuz.interfaces.publishing import PackagePublishingStatus
+from lp.testing.fakemethod import FakeMethod
 from canonical.testing import LaunchpadZopelessLayer
 
 
@@ -82,8 +83,10 @@
         Allow tests to use a set of default options and pass an
         inactive logger to ObsoleteDistroseries.
         """
-        test_args = ['-s', suite,
-                     '-d', distribution,]
+        test_args = [
+            '-s', suite,
+            '-d', distribution,
+            ]
 
         if confirm_all:
             test_args.append('-y')
@@ -92,9 +95,7 @@
             name='obsolete-distroseries', test_args=test_args)
         # Swallow all log messages.
         obsoleter.logger = FakeLogger()
-        def message(self, prefix, *stuff, **kw):
-            pass
-        obsoleter.logger.message = message
+        obsoleter.logger.message = FakeMethod()
         obsoleter.setupLocation()
         return obsoleter
 
@@ -208,7 +209,3 @@
             binary = BinaryPackagePublishingHistory.get(id)
             self.assertTrue(
                 binary.status != PackagePublishingStatus.OBSOLETE)
-
-
-def test_suite():
-    return unittest.TestLoader().loadTestsFromName(__name__)

=== modified file 'lib/lp/soyuz/scripts/tests/test_overrides_checker.py'
--- lib/lp/soyuz/scripts/tests/test_overrides_checker.py	2009-06-25 04:06:00 +0000
+++ lib/lp/soyuz/scripts/tests/test_overrides_checker.py	2010-07-20 14:01:15 +0000
@@ -1,11 +1,11 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """archive-override-check tool base class tests."""
 
 __metaclass__ = type
 
-from unittest import TestCase, TestLoader
+from unittest import TestCase
 from lp.soyuz.scripts.ftpmaster import (
     PubBinaryDetails, PubSourceChecker, PubBinaryContent)
 
@@ -29,7 +29,7 @@
             1, len(self.binary_details.priorities['foo-dev']))
         # not correct value was set yet
         self.assertEqual(
-            False, self.binary_details.correct_priorities.has_key('foo-dev'))
+            False, 'foo-dev' in self.binary_details.correct_priorities)
         # set correct values
         self.binary_details.setCorrectValues()
         # now we have the correct value in place
@@ -151,7 +151,6 @@
             "\t\tW: Priority mismatch: EXTRA != REQUIRED",
             checker.renderReport())
 
-
     def test_multi_binary_priority_success(self):
         """Probe multiple binaries with correct priorities.
 
@@ -169,7 +168,3 @@
         checker.check()
 
         self.assertEqual(None, checker.renderReport())
-
-
-def test_suite():
-    return TestLoader().loadTestsFromName(__name__)

=== modified file 'lib/lp/soyuz/scripts/tests/test_populatearchive.py'
--- lib/lp/soyuz/scripts/tests/test_populatearchive.py	2010-07-15 21:30:26 +0000
+++ lib/lp/soyuz/scripts/tests/test_populatearchive.py	2010-07-20 14:01:15 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 __metaclass__ = type
@@ -8,7 +8,6 @@
 import subprocess
 import sys
 import time
-import unittest
 
 from zope.component import getUtility
 from zope.security.proxy import removeSecurityProxy
@@ -29,6 +28,7 @@
 from lp.soyuz.scripts.populate_archive import ArchivePopulator
 from lp.soyuz.tests.test_publishing import SoyuzTestPublisher
 from lp.testing import TestCaseWithFactory
+from lp.testing.faketransaction import FakeTransaction
 
 
 def get_spn(build):
@@ -179,11 +179,6 @@
             the script
         :param output_substr: this must be part of the script's output
         """
-        class FakeZopeTransactionManager:
-            def commit(self):
-                pass
-            def begin(self):
-                pass
 
         if copy_archive_name is None:
             now = int(time.time())
@@ -211,7 +206,7 @@
         script_args = [
             '--from-distribution', distro_name, '--from-suite', suite,
             '--to-distribution', distro_name, '--to-suite', suite,
-            '--to-archive', archive_name, '--to-user', user
+            '--to-archive', archive_name, '--to-user', user,
             ]
 
         # Empty reason string indicates that the '--reason' command line
@@ -233,7 +228,7 @@
             test_args=script_args)
 
         script.logger = BufferLogger()
-        script.txn = FakeZopeTransactionManager()
+        script.txn = FakeTransaction()
 
         if exception_type is not None:
             self.assertRaisesWithContent(
@@ -393,9 +388,10 @@
             # The set of packages that were superseded in the target archive.
             obsolete=set(['alsa-utils 1.0.9a-4ubuntu1 in hoary']),
             # The set of packages that are new/fresher in the source archive.
-            new=set(['alsa-utils 2.0 in hoary',
-                     'new-in-second-round 1.0 in hoary'])
-            )
+            new=set([
+                'alsa-utils 2.0 in hoary',
+                'new-in-second-round 1.0 in hoary',
+                ]))
 
         # Now populate a 3rd copy archive from the first ubuntu/hoary
         # snapshot.
@@ -423,9 +419,10 @@
             # The set of packages that were superseded in the target archive.
             obsolete=set(['alsa-utils 1.0.9a-4ubuntu1 in hoary']),
             # The set of packages that are new/fresher in the source archive.
-            new=set(['alsa-utils 2.0 in hoary',
-                     'new-in-second-round 1.0 in hoary'])
-            )
+            new=set([
+                'alsa-utils 2.0 in hoary',
+                'new-in-second-round 1.0 in hoary',
+                ]))
 
     def testUnknownOriginArchive(self):
         """Try copy archive population with a unknown origin archive.
@@ -558,6 +555,7 @@
 
     def testBuildsPendingAndSuspended(self):
         """All builds in the new copy archive are pending and suspended."""
+
         def build_in_wrong_state(build):
             """True if the given build is not (pending and suspended)."""
             return not (
@@ -584,7 +582,7 @@
         #   - binary build: pending
         #   - job: suspended
         builds_in_wrong_state = filter(build_in_wrong_state, builds)
-        self.assertEqual (
+        self.assertEqual(
             [], builds_in_wrong_state,
             "The binary builds generated for the target copy archive "
             "should all be pending and suspended. However, at least one of "
@@ -698,6 +696,3 @@
         # Make sure the source to be copied are the ones we expect (this
         # should break in case of a sample data change/corruption).
         self.assertEqual(src_names, self.expected_src_names)
-
-def test_suite():
-    return unittest.TestLoader().loadTestsFromName(__name__)

=== modified file 'lib/lp/soyuz/scripts/tests/test_ppa_apache_log_parser.py'
--- lib/lp/soyuz/scripts/tests/test_ppa_apache_log_parser.py	2010-03-16 09:52:53 +0000
+++ lib/lp/soyuz/scripts/tests/test_ppa_apache_log_parser.py	2010-07-20 14:01:15 +0000
@@ -3,7 +3,6 @@
 
 from datetime import date
 import subprocess
-import unittest
 
 from zope.component import getUtility
 
@@ -128,7 +127,3 @@
                 [(result.binary_package_release, result.archive, result.day,
                   result.country, result.count) for result in results],
                  key=lambda r: (r[0].id, r[2], r[3].name if r[3] else None)))
-
-
-def test_suite():
-    return unittest.TestLoader().loadTestsFromName(__name__)

=== modified file 'lib/lp/soyuz/scripts/tests/test_ppakeygenerator.py'
--- lib/lp/soyuz/scripts/tests/test_ppakeygenerator.py	2009-06-25 04:06:00 +0000
+++ lib/lp/soyuz/scripts/tests/test_ppakeygenerator.py	2010-07-20 14:01:15 +0000
@@ -1,12 +1,10 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """`PPAKeyGenerator` script class tests."""
 
 __metaclass__ = type
 
-import unittest
-
 from zope.component import getUtility
 
 from lp.soyuz.interfaces.archive import IArchiveSet
@@ -16,32 +14,13 @@
 from lp.services.scripts.base import LaunchpadScriptFailure
 from lp.soyuz.scripts.ppakeygenerator import PPAKeyGenerator
 from lp.testing import TestCase
+from lp.testing.faketransaction import FakeTransaction
 from canonical.testing import LaunchpadZopelessLayer
 
 
 class TestPPAKeyGenerator(TestCase):
     layer = LaunchpadZopelessLayer
 
-    def _getFakeZTM(self):
-        """Return an instrumented `ZopeTransactionManager`-like object.
-
-        I does nothing apart counting the number of commits issued.
-
-        The result is stored in the 'number_of_commits'.
-        """
-        self.number_of_commits = 0
-
-        def commit_called():
-            self.number_of_commits += 1
-
-        class FakeZTM:
-            def commit(self):
-                commit_called()
-            def begin(self):
-                pass
-
-        return FakeZTM()
-
     def _fixArchiveForKeyGeneration(self, archive):
         """Override the given archive distribution to 'ubuntutest'.
 
@@ -51,12 +30,12 @@
         ubuntutest = getUtility(IDistributionSet).getByName('ubuntutest')
         archive.distribution = ubuntutest
 
-    def _getKeyGenerator(self, ppa_owner_name=None):
+    def _getKeyGenerator(self, ppa_owner_name=None, txn=None):
         """Return a `PPAKeyGenerator` instance.
 
-        Monkey-patch the script object transaction manager (see
-        `_getFakeZTM`) and also to use a alternative (fake and lighter)
-        procedure to generate keys for each PPA.
+        Monkey-patch the script object with a fake transaction manager
+        and also make it use an alternative (fake and lighter) procedure
+        to generate keys for each PPA.
         """
         test_args = []
 
@@ -66,7 +45,9 @@
         key_generator = PPAKeyGenerator(
             name='ppa-generate-keys', test_args=test_args)
 
-        key_generator.txn = self._getFakeZTM()
+        if txn is None:
+            txn = FakeTransaction()
+        key_generator.txn = txn
 
         def fake_key_generation(archive):
             a_key = getUtility(IGPGKeySet).get(1)
@@ -102,7 +83,7 @@
         self.assertRaisesWithContent(
             LaunchpadScriptFailure,
             ("PPA for Celso Providelo already has a signing_key (%s)" %
-             cprov.archive.signing_key.fingerprint) ,
+             cprov.archive.signing_key.fingerprint),
             key_generator.main)
 
     def testGenerateKeyForASinglePPA(self):
@@ -116,11 +97,12 @@
 
         self.assertTrue(cprov.archive.signing_key is None)
 
-        key_generator = self._getKeyGenerator(ppa_owner_name='cprov')
+        txn = FakeTransaction()
+        key_generator = self._getKeyGenerator(ppa_owner_name='cprov', txn=txn)
         key_generator.main()
 
         self.assertTrue(cprov.archive.signing_key is not None)
-        self.assertEquals(self.number_of_commits, 1)
+        self.assertEquals(txn.commit_count, 1)
 
     def testGenerateKeyForAllPPA(self):
         """Signing key generation for all PPAs.
@@ -134,14 +116,11 @@
             self._fixArchiveForKeyGeneration(archive)
             self.assertTrue(archive.signing_key is None)
 
-        key_generator = self._getKeyGenerator()
+        txn = FakeTransaction()
+        key_generator = self._getKeyGenerator(txn=txn)
         key_generator.main()
 
         for archive in archives:
             self.assertTrue(archive.signing_key is not None)
 
-        self.assertEquals(self.number_of_commits, len(archives))
-
-
-def test_suite():
-    return unittest.TestLoader().loadTestsFromName(__name__)
+        self.assertEquals(txn.commit_count, len(archives))

=== modified file 'lib/lp/soyuz/scripts/tests/test_ppareport.py'
--- lib/lp/soyuz/scripts/tests/test_ppareport.py	2009-08-13 19:03:36 +0000
+++ lib/lp/soyuz/scripts/tests/test_ppareport.py	2010-07-20 14:01:15 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Tests for `PPAReportScript.` """
@@ -16,6 +16,7 @@
 from canonical.testing import LaunchpadZopelessLayer
 from lp.services.scripts.base import LaunchpadScriptFailure
 from lp.soyuz.scripts.ppareport import PPAReportScript
+from lp.testing.fakemethod import FakeMethod
 
 
 class TestPPAReport(unittest.TestCase):
@@ -68,13 +69,12 @@
         # Override the output handlers if no 'output' option was passed
         # via command-line.
         if output is None:
+
             def set_test_output():
                 reporter.output = StringIO()
             reporter.setOutput = set_test_output
 
-            def close_test_output():
-                pass
-            reporter.closeOutput = close_test_output
+            reporter.closeOutput = FakeMethod()
 
         return reporter
 
@@ -137,8 +137,7 @@
             reporter.output.getvalue().splitlines(), [
                 '= PPAs over 80.00% of their quota =',
                 '',
-                ]
-            )
+                ])
 
         # Quota threshold can be specified.
         reporter = self.getReporter(quota_threshold=.01)
@@ -150,8 +149,7 @@
                 'http://launchpad.dev/~cprov/+archive/ppa | 1024 | 9',
                 'http://launchpad.dev/~mark/+archive/ppa | 1024 | 9',
                 '',
-                ]
-            )
+                ])
 
     def testUserEmails(self):
         # UserEmails report lists user name, user displayname and user
@@ -166,8 +164,7 @@
                 'cprov | Celso Providelo | celso.providelo@xxxxxxxxxxxxx',
                 'mark | Mark Shuttleworth | mark@xxxxxxxxxxx',
                 '',
-                ]
-            )
+                ])
 
         # UserEmails report can be generated for a single PPA.
         reporter = self.getReporter(ppa_owner='cprov')
@@ -178,8 +175,7 @@
                 '= PPA user emails =',
                 'cprov | Celso Providelo | celso.providelo@xxxxxxxxxxxxx',
                 '',
-                ]
-            )
+                ])
 
     def testOrphanRepos(self):
         # OrphanRepos report lists all directories in the PPA root that
@@ -192,8 +188,7 @@
             reporter.output.getvalue().splitlines(), [
                 '= Orphan PPA repositories =',
                 '',
-                ]
-            )
+                ])
         # We create a 'orphan' repository.
         orphan_repo = os.path.join(
             config.personalpackagearchive.root, 'orphan')
@@ -208,8 +203,7 @@
                 '= Orphan PPA repositories =',
                 '/var/tmp/ppa.test/orphan',
                 '',
-                ]
-            )
+                ])
         # Remove the orphan directory.
         shutil.rmtree(orphan_repo)
 
@@ -226,8 +220,7 @@
                 '/var/tmp/ppa.test/cprov',
                 '/var/tmp/ppa.test/mark',
                 '',
-                ]
-            )
+                ])
         # We create both active PPA repositories.
         owner_names = [ppa.owner.name for ppa in reporter.ppas]
         created_repos = []
@@ -245,8 +238,7 @@
             reporter.output.getvalue().splitlines(), [
                 '= Missing PPA repositories =',
                 '',
-                ]
-            )
+                ])
 
         # Remove the created repositories.
         for repo_path in created_repos:
@@ -261,13 +253,12 @@
             gen_missing_repos=True, output=output_path)
         reporter.main()
         self.assertEquals(
-            open(output_path).read().splitlines(),[
+            open(output_path).read().splitlines(), [
                 '= Missing PPA repositories =',
                 '/var/tmp/ppa.test/cprov',
                 '/var/tmp/ppa.test/mark',
                 '',
-                ]
-            )
+                ])
         # Remove the report file.
         os.remove(output_path)
 
@@ -288,8 +279,7 @@
                 '/var/tmp/ppa.test/cprov',
                 '/var/tmp/ppa.test/mark',
                 '',
-                ]
-            )
+                ])
         # Another run for generating user emails report
         reporter = self.getReporter(gen_user_emails=True)
         reporter.main()
@@ -299,9 +289,4 @@
                 'cprov | Celso Providelo | celso.providelo@xxxxxxxxxxxxx',
                 'mark | Mark Shuttleworth | mark@xxxxxxxxxxx',
                 '',
-                ]
-            )
-
-
-def test_suite():
-    return unittest.TestLoader().loadTestsFromName(__name__)
+                ])

=== modified file 'lib/lp/soyuz/scripts/tests/test_processdeathrow.py'
--- lib/lp/soyuz/scripts/tests/test_processdeathrow.py	2009-11-15 19:52:54 +0000
+++ lib/lp/soyuz/scripts/tests/test_processdeathrow.py	2010-07-20 14:01:15 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Functional tests for process-death-row.py script.
@@ -17,7 +17,7 @@
 import subprocess
 import sys
 from tempfile import mkdtemp
-from unittest import TestCase, TestLoader
+from unittest import TestCase
 
 from zope.component import getUtility
 from zope.security.proxy import removeSecurityProxy
@@ -204,7 +204,3 @@
         self.probePublishingStatus(
             self.ppa_pubrec_ids, PackagePublishingStatus.SUPERSEDED)
         self.probeRemoved(self.ppa_pubrec_ids)
-
-
-def test_suite():
-    return TestLoader().loadTestsFromName(__name__)

=== modified file 'lib/lp/soyuz/scripts/tests/test_processpendingpackagediffs.py'
--- lib/lp/soyuz/scripts/tests/test_processpendingpackagediffs.py	2010-02-04 17:08:01 +0000
+++ lib/lp/soyuz/scripts/tests/test_processpendingpackagediffs.py	2010-07-20 14:01:15 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 __metaclass__ = type
@@ -6,9 +6,6 @@
 import os
 import subprocess
 import sys
-import unittest
-
-from zope.component import getUtility
 
 from canonical.config import config
 from canonical.launchpad.scripts import QuietFakeLogger
@@ -107,6 +104,3 @@
         # The next run process the remaining one.
         diff_processor.main()
         self.assertEqual(self.getPendingDiffs().count(), 0)
-
-def test_suite():
-    return unittest.TestLoader().loadTestsFromName(__name__)

=== modified file 'lib/lp/soyuz/scripts/tests/test_processupload.py'
--- lib/lp/soyuz/scripts/tests/test_processupload.py	2010-04-23 22:47:35 +0000
+++ lib/lp/soyuz/scripts/tests/test_processupload.py	2010-07-20 14:01:15 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 __metaclass__ = type
@@ -58,7 +58,7 @@
         # No scriptactivity should exist before it's run.
         activity = getUtility(
             IScriptActivitySet).getLastActivity('process-upload')
-        self.assertTrue(activity is None,  "'activity' should be None")
+        self.assertTrue(activity is None, "'activity' should be None")
 
         returncode, out, err = self.runProcessUpload()
         self.assertEqual(0, returncode)
@@ -86,20 +86,16 @@
         locker.acquire()
 
         returncode, out, err = self.runProcessUpload(
-            extra_args=['-C', 'insecure']
-            )
+            extra_args=['-C', 'insecure'])
 
         # the process-upload call terminated with ERROR and
         # proper log message
         self.assertEqual(1, returncode)
-        self.assertEqual(
-            ['INFO    Creating lockfile: /var/lock/process-upload-insecure.lock',
-             'DEBUG   Lockfile /var/lock/process-upload-insecure.lock in use'
+        self.assertEqual([
+            ('INFO    Creating lockfile: '
+             '/var/lock/process-upload-insecure.lock'),
+            'DEBUG   Lockfile /var/lock/process-upload-insecure.lock in use',
              ], err.splitlines())
 
         # release the locally acquired lockfile
         locker.release()
-
-
-def test_suite():
-    return unittest.TestLoader().loadTestsFromName(__name__)

=== modified file 'lib/lp/soyuz/tests/test_archive.py'
--- lib/lp/soyuz/tests/test_archive.py	2010-07-12 13:32:53 +0000
+++ lib/lp/soyuz/tests/test_archive.py	2010-07-20 14:01:15 +0000
@@ -1,11 +1,10 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Test Archive features."""
 
 from datetime import date, datetime, timedelta
 import pytz
-import unittest
 
 from zope.component import getUtility
 from zope.security.interfaces import Unauthorized
@@ -63,7 +62,7 @@
         # upload dates.
         self.gedit_nightly_src_hist = self.publisher.getPubSource(
             sourcename="gedit", archive=self.archives['gedit-nightly'],
-            date_uploaded=datetime(2010, 12 ,1, tzinfo=pytz.UTC),
+            date_uploaded=datetime(2010, 12, 1, tzinfo=pytz.UTC),
             status=PackagePublishingStatus.PUBLISHED)
         self.gedit_beta_src_hist = self.publisher.getPubSource(
             sourcename="gedit", archive=self.archives['gedit-beta'],
@@ -109,8 +108,7 @@
                           "Expected publication from %s but was instead "
                           "from %s." % (
                               self.archives['gedit-beta'].displayname,
-                              results[0].archive.displayname
-                              ))
+                              results[0].archive.displayname))
 
     def testReturnsOnlyPublishedPublications(self):
         # Publications that are not published will not be returned.
@@ -135,14 +133,12 @@
             archive=self.archives['ubuntu-main'],
             distroseries=warty,
             date_uploaded=datetime(2010, 12, 30, tzinfo=pytz.UTC),
-            status=PackagePublishingStatus.PUBLISHED,
-            )
+            status=PackagePublishingStatus.PUBLISHED)
 
         # Only the 3 results for ubuntutest are returned when requested:
         results = self.archive_set.getPublicationsInArchives(
             self.gedit_name, self.archives.values(),
-            distribution=self.distribution
-            )
+            distribution=self.distribution)
         num_results = results.count()
         self.assertEquals(3, num_results, "Expected 3 publications but "
                                           "got %s" % num_results)
@@ -151,8 +147,7 @@
         # one we created:
         results = self.archive_set.getPublicationsInArchives(
             self.gedit_name, self.archives.values(),
-            distribution=ubuntu
-            )
+            distribution=ubuntu)
         num_results = results.count()
         self.assertEquals(1, num_results, "Expected 1 publication but "
                                           "got %s" % num_results)
@@ -577,13 +572,13 @@
 
 
 class TestArchiveCanUpload(TestCaseWithFactory):
-    """Test the various methods that verify whether uploads are allowed to 
+    """Test the various methods that verify whether uploads are allowed to
     happen."""
 
     layer = LaunchpadZopelessLayer
 
     def test_checkArchivePermission_by_PPA_owner(self):
-        # Uploading to a PPA should be allowed for a user that is the owner 
+        # Uploading to a PPA should be allowed for a user that is the owner
         owner = self.factory.makePerson(name="somebody")
         archive = self.factory.makeArchive(owner=owner)
         self.assertEquals(True, archive.checkArchivePermission(owner))
@@ -594,12 +589,12 @@
     def test_checkArchivePermission_distro_archive(self):
         # Regular users can not upload to ubuntu
         ubuntu = getUtility(IDistributionSet).getByName('ubuntu')
-        archive = self.factory.makeArchive(purpose=ArchivePurpose.PRIMARY, 
+        archive = self.factory.makeArchive(purpose=ArchivePurpose.PRIMARY,
                                            distribution=ubuntu)
         main = getUtility(IComponentSet)["main"]
         # A regular user doesn't have access
         somebody = self.factory.makePerson(name="somebody")
-        self.assertEquals(False, 
+        self.assertEquals(False,
             archive.checkArchivePermission(somebody, main))
         # An ubuntu core developer does have access
         kamion = getUtility(IPersonSet).getByName('kamion')
@@ -608,7 +603,7 @@
     def test_checkArchivePermission_ppa(self):
         ubuntu = getUtility(IDistributionSet).getByName('ubuntu')
         owner = self.factory.makePerson(name="eigenaar")
-        archive = self.factory.makeArchive(purpose=ArchivePurpose.PPA, 
+        archive = self.factory.makeArchive(purpose=ArchivePurpose.PPA,
                                            distribution=ubuntu,
                                            owner=owner)
         somebody = self.factory.makePerson(name="somebody")
@@ -620,17 +615,17 @@
     def test_checkUpload_partner_invalid_pocket(self):
         # Partner archives only have release and proposed pockets
         archive = self.factory.makeArchive(purpose=ArchivePurpose.PARTNER)
-        self.assertIsInstance(archive.checkUpload(self.factory.makePerson(), 
+        self.assertIsInstance(archive.checkUpload(self.factory.makePerson(),
                                 self.factory.makeDistroSeries(),
                                 self.factory.makeSourcePackageName(),
                                 self.factory.makeComponent(),
                                 PackagePublishingPocket.UPDATES),
                                 InvalidPocketForPartnerArchive)
- 
+
     def test_checkUpload_ppa_invalid_pocket(self):
         # PPA archives only have release pockets
         archive = self.factory.makeArchive(purpose=ArchivePurpose.PPA)
-        self.assertIsInstance(archive.checkUpload(self.factory.makePerson(), 
+        self.assertIsInstance(archive.checkUpload(self.factory.makePerson(),
                                 self.factory.makeDistroSeries(),
                                 self.factory.makeSourcePackageName(),
                                 self.factory.makeComponent(),
@@ -755,7 +750,7 @@
         self.arm = getUtility(IProcessorFamilySet).getByName('arm')
 
     def test_main_archive_can_use_restricted(self):
-        # Main archives for distributions can always use restricted 
+        # Main archives for distributions can always use restricted
         # architectures.
         distro = self.factory.makeDistribution()
         self.assertContentEqual([self.arm],
@@ -766,8 +761,10 @@
         distro = self.factory.makeDistribution()
         # Restricting to all restricted architectures is fine
         distro.main_archive.enabled_restricted_families = [self.arm]
+
         def restrict():
             distro.main_archive.enabled_restricted_families = []
+
         self.assertRaises(CannotRestrictArchitectures, restrict)
 
     def test_default(self):
@@ -802,7 +799,8 @@
         self.assertEquals(1, allowed_restricted_families.count())
         self.assertEquals(self.arm,
             allowed_restricted_families[0].processorfamily)
-        self.assertEquals([self.arm], self.archive.enabled_restricted_families)
+        self.assertEquals(
+            [self.arm], self.archive.enabled_restricted_families)
         self.archive.enabled_restricted_families = []
         self.assertEquals(0,
             self.archive_arch_set.getByArchive(
@@ -835,6 +833,7 @@
         token = self.private_ppa.getAuthToken(self.joe)
         self.assertEqual(token.archive_url, url)
 
+
 class TestArchivePrivacySwitching(TestCaseWithFactory):
 
     layer = LaunchpadZopelessLayer
@@ -1099,8 +1098,3 @@
         login("commercial-member@xxxxxxxxxxxxx")
         self.setCommercial(self.archive, True)
         self.assertTrue(self.archive.commercial)
-        
-
-
-def test_suite():
-    return unittest.TestLoader().loadTestsFromName(__name__)

=== modified file 'lib/lp/soyuz/tests/test_archive_agent.py'
--- lib/lp/soyuz/tests/test_archive_agent.py	2010-07-13 10:57:31 +0000
+++ lib/lp/soyuz/tests/test_archive_agent.py	2010-07-20 14:01:15 +0000
@@ -60,4 +60,3 @@
         url = self.ppa.archive_url.split('http://')[1]
         new_url = "http://joe:%s@%s"; % (authtoken, url)
         self.assertEqual(sources, new_url)
-

=== modified file 'lib/lp/soyuz/tests/test_archive_privacy.py'
--- lib/lp/soyuz/tests/test_archive_privacy.py	2010-06-21 10:02:54 +0000
+++ lib/lp/soyuz/tests/test_archive_privacy.py	2010-07-20 14:01:15 +0000
@@ -37,4 +37,3 @@
         login_person(self.joe)
         p3a = getUtility(IArchiveSet).get(self.private_ppa.id)
         self.assertEqual(self._getDescription(p3a), "Foo")
-

=== modified file 'lib/lp/soyuz/tests/test_archive_subscriptions.py'
--- lib/lp/soyuz/tests/test_archive_subscriptions.py	2010-06-28 14:39:35 +0000
+++ lib/lp/soyuz/tests/test_archive_subscriptions.py	2010-07-20 14:01:15 +0000
@@ -1,10 +1,8 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Test Archive features."""
 
-import unittest
-
 from zope.security.interfaces import Unauthorized
 
 from canonical.testing import DatabaseFunctionalLayer
@@ -36,7 +34,6 @@
         # a private team's PPA after they have been given a subscription.
         # This is essentially allowing access for the subscriber to see
         # the private team.
-
         def get_name():
             return self.archive.owner.name
 
@@ -51,7 +48,3 @@
         # When a subscription exists, it's fine.
         login_person(self.subscriber)
         self.assertEqual(self.archive.owner.name, "subscribertest")
-
-
-def test_suite():
-    return unittest.TestLoader().loadTestsFromName(__name__)

=== modified file 'lib/lp/soyuz/tests/test_archivearch.py'
--- lib/lp/soyuz/tests/test_archivearch.py	2010-07-05 11:00:54 +0000
+++ lib/lp/soyuz/tests/test_archivearch.py	2010-07-20 14:01:15 +0000
@@ -3,8 +3,6 @@
 
 """Test ArchiveArch features."""
 
-import unittest
-
 from zope.component import getUtility
 
 from canonical.testing import LaunchpadZopelessLayer
@@ -16,6 +14,7 @@
 from lp.soyuz.interfaces.archivearch import IArchiveArchSet
 from lp.soyuz.interfaces.processor import IProcessorFamilySet
 
+
 class TestArchiveArch(TestCaseWithFactory):
 
     layer = LaunchpadZopelessLayer
@@ -53,7 +52,7 @@
         results = dict(
             (row[0].name, row[1] is not None) for row in result_set)
         self.assertEquals(
-            {'arm' : False, 'cell-proc' : True, 'omap' : False},
+            {'arm': False, 'cell-proc': True, 'omap': False},
             results)
 
     def test_getRestrictedFamilies_archive_only(self):
@@ -66,7 +65,7 @@
         results = dict(
             (row[0].name, row[1] is not None) for row in result_set)
         self.assertEquals(
-            {'arm' : False, 'cell-proc' : True, 'omap' : False},
+            {'arm': False, 'cell-proc': True, 'omap': False},
             results)
 
     def test_getByArchive_no_other_archives(self):
@@ -78,7 +77,3 @@
         self.assertEquals(1, len(result_set))
         self.assertEquals(self.ppa, result_set[0].archive)
         self.assertEquals(self.cell_proc, result_set[0].processorfamily)
-
-
-def test_suite():
-    return unittest.TestLoader().loadTestsFromName(__name__)

=== modified file 'lib/lp/soyuz/tests/test_binarypackagebuild.py'
--- lib/lp/soyuz/tests/test_binarypackagebuild.py	2010-06-21 07:26:51 +0000
+++ lib/lp/soyuz/tests/test_binarypackagebuild.py	2010-07-20 14:01:15 +0000
@@ -1,11 +1,10 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Test Build features."""
 
 from datetime import datetime, timedelta
 import pytz
-import unittest
 
 from storm.store import Store
 from zope.component import getUtility
@@ -91,7 +90,6 @@
         previous_build.date_started = None
         self.assertEqual(60, self.build.estimateDuration().seconds)
 
-
     def addFakeBuildLog(self):
         lfa = self.factory.makeLibraryFileAlias('mybuildlog.txt')
         removeSecurityProxy(self.build).log = lfa
@@ -161,8 +159,8 @@
     def _setupSimpleDepwaitContext(self):
         """Use `SoyuzTestPublisher` to setup a simple depwait context.
 
-        Return an `IBinaryPackageBuild` in MANUALDEWAIT state and depending on a
-        binary that exists and is reachable.
+        Return an `IBinaryPackageBuild` in MANUALDEWAIT state and depending
+        on a binary that exists and is reachable.
         """
         test_publisher = SoyuzTestPublisher()
         test_publisher.prepareBreezyAutotest()
@@ -221,7 +219,6 @@
                 BinaryPackageBuild.id == depwait_build_id).count(),
             1)
 
-
     def testUpdateDependenciesWorks(self):
         # Calling `IBinaryPackageBuild.updateDependencies` makes the build
         # record ready for dispatch.
@@ -429,7 +426,3 @@
 class TestHandleStatusForBinaryPackageBuild(
     MakeBinaryPackageBuildMixin, TestHandleStatusMixin, TestCaseWithFactory):
     """IBuildBase.handleStatus works with binary builds."""
-
-
-def test_suite():
-    return unittest.TestLoader().loadTestsFromName(__name__)

=== modified file 'lib/lp/soyuz/tests/test_distroseriesbinarypackage.py'
--- lib/lp/soyuz/tests/test_distroseriesbinarypackage.py	2010-05-28 17:28:57 +0000
+++ lib/lp/soyuz/tests/test_distroseriesbinarypackage.py	2010-07-20 14:01:15 +0000
@@ -9,7 +9,6 @@
     'test_suite',
     ]
 
-import unittest
 import transaction
 
 from lp.soyuz.model.distroseriesbinarypackage import (
@@ -63,7 +62,3 @@
 
         self.failUnlessEqual(
             'Foo is the best', self.distroseries_binary_package.summary)
-
-
-def test_suite():
-    return unittest.TestLoader().loadTestsFromName(__name__)

=== modified file 'lib/lp/soyuz/tests/test_hasbuildrecords.py'
--- lib/lp/soyuz/tests/test_hasbuildrecords.py	2010-06-17 09:53:24 +0000
+++ lib/lp/soyuz/tests/test_hasbuildrecords.py	2010-07-20 14:01:15 +0000
@@ -1,10 +1,8 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Test implementations of the IHasBuildRecords interface."""
 
-import unittest
-
 from zope.component import getUtility
 from zope.security.proxy import removeSecurityProxy
 
@@ -67,6 +65,7 @@
 
 class TestDistroSeriesHasBuildRecords(TestHasBuildRecordsInterface):
     """Test the DistroSeries implementation of IHasBuildRecords."""
+
     def setUp(self):
         super(TestDistroSeriesHasBuildRecords, self).setUp()
 
@@ -75,6 +74,7 @@
 
 class TestDistroArchSeriesHasBuildRecords(TestHasBuildRecordsInterface):
     """Test the DistroArchSeries implementation of IHasBuildRecords."""
+
     def setUp(self):
         super(TestDistroArchSeriesHasBuildRecords, self).setUp()
 
@@ -83,6 +83,7 @@
 
 class TestArchiveHasBuildRecords(TestHasBuildRecordsInterface):
     """Test the Archive implementation of IHasBuildRecords."""
+
     def setUp(self):
         super(TestArchiveHasBuildRecords, self).setUp()
 
@@ -117,6 +118,7 @@
 
 class TestBuilderHasBuildRecords(TestHasBuildRecordsInterface):
     """Test the Builder implementation of IHasBuildRecords."""
+
     def setUp(self):
         super(TestBuilderHasBuildRecords, self).setUp()
 
@@ -171,8 +173,10 @@
             IncompatibleArguments, self.context.getBuildRecords,
             binary_only=False, name="anything")
 
+
 class TestSourcePackageHasBuildRecords(TestHasBuildRecordsInterface):
     """Test the SourcePackage implementation of IHasBuildRecords."""
+
     def setUp(self):
         super(TestSourcePackageHasBuildRecords, self).setUp()
 
@@ -187,7 +191,3 @@
         for build in self.builds[1:3]:
             spr = build.source_package_release
             removeSecurityProxy(spr).sourcepackagename = gedit_name
-
-
-def test_suite():
-    return unittest.TestLoader().loadTestsFromName(__name__)

=== modified file 'lib/lp/soyuz/tests/test_packagediff.py'
--- lib/lp/soyuz/tests/test_packagediff.py	2010-02-04 17:08:01 +0000
+++ lib/lp/soyuz/tests/test_packagediff.py	2010-07-20 14:01:15 +0000
@@ -6,7 +6,6 @@
 __metaclass__ = type
 
 from datetime import datetime
-import unittest
 
 from zope.component import getUtility
 from zope.security.proxy import removeSecurityProxy
@@ -86,7 +85,3 @@
         diff.performDiff()
         # The diff succeeds as expected.
         self.assertEqual(PackageDiffStatus.COMPLETED, diff.status)
-
-
-def test_suite():
-    return unittest.TestLoader().loadTestsFromName(__name__)

=== modified file 'lib/lp/soyuz/tests/test_packageupload.py'
--- lib/lp/soyuz/tests/test_packageupload.py	2010-05-10 16:21:10 +0000
+++ lib/lp/soyuz/tests/test_packageupload.py	2010-07-20 14:01:15 +0000
@@ -1,11 +1,10 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Test Build features."""
 
 import os
 import shutil
-import unittest
 
 from zope.component import getUtility
 
@@ -333,7 +332,3 @@
         # the partner archive.
         pub = package_upload.realiseUpload()[0]
         self.assertEqual("partner", pub.archive.name)
-
-
-def test_suite():
-    return unittest.TestLoader().loadTestsFromName(__name__)

=== modified file 'lib/lp/soyuz/tests/test_publish_archive_indexes.py'
--- lib/lp/soyuz/tests/test_publish_archive_indexes.py	2009-10-08 08:24:03 +0000
+++ lib/lp/soyuz/tests/test_publish_archive_indexes.py	2010-07-20 14:01:15 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Test native archive index generation for Soyuz."""
@@ -10,6 +10,7 @@
 
 from lp.soyuz.tests.test_publishing import TestNativePublishingBase
 
+
 class TestNativeArchiveIndexes(TestNativePublishingBase):
 
     def setUp(self):
@@ -57,11 +58,11 @@
         See also testSourceStanza, it must present something similar for
         binary packages.
         """
-        pub_binary = self.getPubBinaries(
+        pub_binaries = self.getPubBinaries(
             depends='biscuit', recommends='foo-dev', suggests='pyfoo',
             conflicts='old-foo', replaces='old-foo', provides='foo-master',
-            pre_depends='master-foo', enhances='foo-super', breaks='old-foo'
-            )[0]
+            pre_depends='master-foo', enhances='foo-super', breaks='old-foo')
+        pub_binary = pub_binaries[0]
         self.assertEqual(
             [u'Package: foo-bin',
              u'Source: foo',
@@ -135,7 +136,7 @@
              u' .',
              u' .',
              u' .',
-             u' %s' % ('x' * 100)
+             u' %s' % ('x' * 100),
              ],
             pub_binary.getIndexStanza().splitlines())
 
@@ -175,6 +176,7 @@
     """Tests for ensuring the native archive indexes that we publish
     can be parsed correctly by apt_get.ParseTagFiles.
     """
+
     def setUp(self):
         """Setup global attributes."""
         TestNativePublishingBase.setUp(self)
@@ -299,6 +301,7 @@
 
 
 class TestIndexStanzaFieldsHelper(unittest.TestCase):
+
     def testIndexStanzaFields(self):
         """Check how this auxiliary class works...
 
@@ -307,6 +310,7 @@
 
         Provides an method to format the option in a ready-to-use string.
         """
+        # Avoid circular imports.
         from lp.soyuz.model.publishing import IndexStanzaFields
 
         fields = IndexStanzaFields()
@@ -338,7 +342,3 @@
 
         self.assertEqual(
             ['one: um', 'Files:<no_sep>'], fields.makeOutput().splitlines())
-
-
-def test_suite():
-    return unittest.TestLoader().loadTestsFromName(__name__)

=== modified file 'lib/lp/soyuz/tests/test_publishing.py'
--- lib/lp/soyuz/tests/test_publishing.py	2010-07-20 09:16:14 +0000
+++ lib/lp/soyuz/tests/test_publishing.py	2010-07-20 14:01:15 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Test native publication workflow for Soyuz. """
@@ -44,6 +44,7 @@
 from canonical.launchpad.scripts import FakeLogger
 from lp.testing import TestCaseWithFactory
 from lp.testing.factory import LaunchpadObjectFactory
+from lp.testing.fakemethod import FakeMethod
 
 
 class SoyuzTestPublisher:
@@ -135,7 +136,7 @@
                          changes_file_name="foo_666_source.changes",
                          changes_file_content="fake changes file content",
                          upload_status=PackageUploadStatus.DONE):
-        signing_key =  self.person.gpg_keys[0]
+        signing_key = self.person.gpg_keys[0]
         package_upload = distroseries.createQueueEntry(
             pocket, changes_file_name, changes_file_content, archive,
             signing_key)
@@ -470,9 +471,8 @@
         self.pool_dir = self.config.poolroot
         self.temp_dir = self.config.temproot
         self.logger = FakeLogger()
-        def message(self, prefix, *stuff, **kw):
-            pass
-        self.logger.message = message
+
+        self.logger.message = FakeMethod()
         self.disk_pool = DiskPool(self.pool_dir, self.temp_dir, self.logger)
 
     def tearDown(self):
@@ -598,7 +598,7 @@
         pub_source.publish(self.disk_pool, self.logger)
         self.layer.commit()
         self.assertEqual(
-            pub_source.status,PackagePublishingStatus.PENDING)
+            pub_source.status, PackagePublishingStatus.PENDING)
         self.assertEqual(open(foo_dsc_path).read().strip(), 'Hello world')
 
     def testPublishingDifferentContents(self):
@@ -777,7 +777,7 @@
         try:
             copies = tuple(copied)
         except TypeError:
-            copies = (copied,)
+            copies = (copied, )
 
         for copy in copies:
             self.assertEquals(copy.component, pub_record.component)
@@ -887,7 +887,8 @@
         """Return a mock source package publishing record for the archive
         and architecture used in this testcase.
 
-        :param architecturehintlist: Architecture hint list (e.g. "i386 amd64")
+        :param architecturehintlist: Architecture hint list
+            (e.g. "i386 amd64")
         """
         return super(BuildRecordCreationTests, self).getPubSource(
             archive=self.archive, distroseries=self.distroseries,
@@ -927,8 +928,8 @@
         self.assertEquals(self.sparc_distroarch, builds[0].distro_arch_series)
 
     def test_createMissingBuilds_restricts_explicitlist(self):
-        """createMissingBuilds() should limit builds targeted at a
-        variety of architectures architecture to those allowed for the archive.
+        """createMissingBuilds() limits builds targeted at a variety of
+        architectures architecture to those allowed for the archive.
         """
         pubrec = self.getPubSource(architecturehintlist='sparc i386 avr')
         builds = pubrec.createMissingBuilds()
@@ -1012,7 +1013,3 @@
         record = self.publishing_set.getByIdAndArchive(
             binary_publishing.id, wrong_archive, source=False)
         self.assertEqual(None, record)
-
-
-def test_suite():
-    return unittest.TestLoader().loadTestsFromName(__name__)

=== modified file 'lib/lp/soyuz/tests/test_publishing_models.py'
--- lib/lp/soyuz/tests/test_publishing_models.py	2010-05-05 14:50:42 +0000
+++ lib/lp/soyuz/tests/test_publishing_models.py	2010-07-20 14:01:15 +0000
@@ -1,10 +1,8 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Test model and set utilities used for publishing."""
 
-import unittest
-
 from zope.component import getUtility
 from zope.security.proxy import removeSecurityProxy
 
@@ -86,9 +84,6 @@
         self.assertEqual(urls, [
             'http://localhost:58000/94/gedit_666_source.changes',
             'http://localhost:58000/96/firefox_666_source.changes',
-            'http://localhost:58000/98/getting-things-gnome_666_source.changes'
+            ('http://localhost:58000/98/'
+             'getting-things-gnome_666_source.changes'),
             ])
-
-
-def test_suite():
-    return unittest.TestLoader().loadTestsFromName(__name__)

=== modified file 'lib/lp/soyuz/tests/test_publishing_top_level_api.py'
--- lib/lp/soyuz/tests/test_publishing_top_level_api.py	2009-12-13 11:55:40 +0000
+++ lib/lp/soyuz/tests/test_publishing_top_level_api.py	2010-07-20 14:01:15 +0000
@@ -1,10 +1,8 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Test top-level publication API in Soyuz."""
 
-from unittest import TestLoader
-
 from lp.soyuz.tests.test_publishing import TestNativePublishingBase
 
 from lp.registry.interfaces.series import SeriesStatus
@@ -118,7 +116,7 @@
 
         # source and binary PUBLISHED on disk.
         foo_dsc = "%s/main/f/foo/foo_666.dsc" % self.pool_dir
-        self.assertEqual(open(foo_dsc).read().strip(),'Hello')
+        self.assertEqual(open(foo_dsc).read().strip(), 'Hello')
         foo_deb = "%s/main/f/foo/foo-bin_666_all.deb" % self.pool_dir
         self.assertEqual(open(foo_deb).read().strip(), 'World')
 
@@ -207,8 +205,9 @@
     def testPublicationLookUpForUnstableDistroSeries(self):
         """Source publishing record lookup for a unstable DistroSeries.
 
-        Check if the ICanPublishPackages.getPendingPublications() works properly
-        for a DistroSeries when it is still in development, 'unreleased'.
+        Check if the ICanPublishPackages.getPendingPublications() works
+        properly for a DistroSeries when it is still in development,
+        'unreleased'.
         """
         pub_pending_release, pub_published_release, pub_pending_updates = (
             self._createDefaulSourcePublications())
@@ -241,9 +240,9 @@
     def testPublicationLookUpForStableDistroSeries(self):
         """Source publishing record lookup for a stable/released DistroSeries.
 
-        Check if the ICanPublishPackages.getPendingPublications() works properly
-        for a DistroSeries when it is not in development anymore, i.e.,
-        'released'.
+        Check if the ICanPublishPackages.getPendingPublications() works
+        properly for a DistroSeries when it is not in development anymore,
+        i.e., 'released'.
         """
         pub_pending_release, pub_published_release, pub_pending_updates = (
             self._createDefaulSourcePublications())
@@ -276,8 +275,8 @@
     def testPublicationLookUpForFrozenDistroSeries(self):
         """Source publishing record lookup for a frozen DistroSeries.
 
-        Check if the ICanPublishPackages.getPendingPubliations() works properly
-        for a DistroSeries when it is in FROZEN state.
+        Check if the ICanPublishPackages.getPendingPubliations() works
+        properly for a DistroSeries when it is in FROZEN state.
         """
         pub_pending_release, pub_published_release, pub_pending_updates = (
             self._createDefaulSourcePublications())
@@ -313,9 +312,9 @@
     def testPublicationLookUpForUnstableDistroArchSeries(self):
         """Binary publishing record lookup for a unstable DistroArchSeries.
 
-        Check if the ICanPublishPackages.getPendingPublications() works properly
-        for a DistroArchSeries when it is still in DEVELOPMENT, i.e.,
-        'unstable'.
+        Check if the ICanPublishPackages.getPendingPublications() works
+        properly for a DistroArchSeries when it is still in DEVELOPMENT,
+        i.e., 'unstable'.
         """
         pub_pending_release, pub_published_release, pub_pending_updates = (
             self._createDefaulBinaryPublications())
@@ -421,7 +420,3 @@
         self.checkBinaryLookupForPocket(
             PackagePublishingPocket.RELEASE, is_careful=True,
             expected_result=[pub_published_release, pub_pending_release])
-
-
-def test_suite():
-    return TestLoader().loadTestsFromName(__name__)

=== modified file 'lib/lp/testing/faketransaction.py'
--- lib/lp/testing/faketransaction.py	2010-02-23 23:26:15 +0000
+++ lib/lp/testing/faketransaction.py	2010-07-20 14:01:15 +0000
@@ -15,6 +15,8 @@
 
     Set `log_calls` to True to enable printing of commits and aborts.
     """
+    commit_count = 0
+
     def __init__(self, log_calls=False):
         self.log_calls = log_calls
 
@@ -28,6 +30,7 @@
 
     def commit(self):
         """Pretend to commit."""
+        self.commit_count += 1
         self._log("COMMIT")
 
     def abort(self):