← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:remove-unused-test-helpers into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:remove-unused-test-helpers into launchpad:master.

Commit message:
Remove several unused test helpers

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/394389

Found by Vulture.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:remove-unused-test-helpers into launchpad:master.
diff --git a/lib/lp/bugs/tests/bug.py b/lib/lp/bugs/tests/bug.py
index d47e73d..d28fc93 100644
--- a/lib/lp/bugs/tests/bug.py
+++ b/lib/lp/bugs/tests/bug.py
@@ -18,18 +18,13 @@ from zope.component import getUtility
 from zope.security.proxy import removeSecurityProxy
 
 from lp.app.interfaces.launchpad import ILaunchpadCelebrities
-from lp.bugs.interfaces.bug import (
-    CreateBugParams,
-    IBugSet,
-    )
+from lp.bugs.interfaces.bug import CreateBugParams
 from lp.bugs.interfaces.bugtask import (
     BugTaskStatus,
     IBugTaskSet,
     )
 from lp.bugs.interfaces.bugwatch import IBugWatchSet
-from lp.registry.interfaces.distribution import IDistributionSet
 from lp.registry.interfaces.person import IPersonSet
-from lp.registry.interfaces.product import IProductSet
 from lp.services.beautifulsoup import BeautifulSoup
 from lp.services.config import config
 from lp.testing.pages import (
@@ -160,42 +155,6 @@ def extract_bugtasks(text, show_heat=None):
     return rows
 
 
-def create_task_from_strings(bug, owner, product, watchurl=None):
-    """Create a task, optionally linked to a watch."""
-    bug = getUtility(IBugSet).get(bug)
-    product = getUtility(IProductSet).getByName(product)
-    owner = getUtility(IPersonSet).getByName(owner)
-    task = getUtility(IBugTaskSet).createTask(bug, owner, product)
-    if watchurl:
-        [watch] = getUtility(IBugWatchSet).fromText(watchurl, bug, owner)
-        task.bugwatch = watch
-    return task
-
-
-def create_bug_from_strings(
-    distribution, sourcepackagename, owner, summary, description,
-    status=None):
-    """Create and return a bug."""
-    distroset = getUtility(IDistributionSet)
-    distribution = distroset.getByName(distribution)
-
-    personset = getUtility(IPersonSet)
-    owner = personset.getByName(owner)
-
-    bugset = getUtility(IBugSet)
-    params = CreateBugParams(
-        owner, summary, description, status=status,
-        target=distribution.getSourcePackage(sourcepackagename))
-    return bugset.createBug(params)
-
-
-def update_task_status(task_id, person, status):
-    """Update a bugtask status."""
-    task = getUtility(IBugTaskSet).get(task_id)
-    person = getUtility(IPersonSet).getByName(person)
-    task.transitionToStatus(status, person)
-
-
 def create_old_bug(
     title, days_old, target, status=BugTaskStatus.INCOMPLETE,
     with_message=True, external_bugtracker=None, assignee=None,
diff --git a/lib/lp/buildmaster/tests/test_buildqueue.py b/lib/lp/buildmaster/tests/test_buildqueue.py
index 08ceb55..77ed62a 100644
--- a/lib/lp/buildmaster/tests/test_buildqueue.py
+++ b/lib/lp/buildmaster/tests/test_buildqueue.py
@@ -51,29 +51,6 @@ def find_job(test, name, processor='386'):
     return (None, None)
 
 
-def print_build_setup(builds):
-    """Show the build set-up for a particular test."""
-
-    def processor_name(bq):
-        return ('None' if bq.processor is None else bq.processor.name)
-
-    print("")
-    queue_entries = [build.buildqueue_record for build in builds]
-    queue_entries = sorted(
-        queue_entries, key=lambda qe: qe.job.id, reverse=True)
-    queue_entries = sorted(queue_entries, key=lambda qe: qe.lastscore)
-    for queue_entry in queue_entries:
-        source = None
-        for attr in ('sourcepackagerelease', 'sourcepackagename'):
-            source = getattr(queue_entry.specific_build, attr, None)
-            if source is not None:
-                break
-        print("%5s, %18s, p:%5s, v:%5s e:%s *** s:%5s" % (
-            queue_entry.id, source.name, processor_name(queue_entry),
-            queue_entry.virtualized, queue_entry.estimated_duration,
-            queue_entry.lastscore))
-
-
 class TestBuildCancellation(TestCaseWithFactory):
     """Test cases for cancelling builds."""
 
diff --git a/lib/lp/code/tests/helpers.py b/lib/lp/code/tests/helpers.py
index 4ef843d..fae251a 100644
--- a/lib/lp/code/tests/helpers.py
+++ b/lib/lp/code/tests/helpers.py
@@ -28,13 +28,9 @@ from itertools import count
 
 from breezy.plugins.builder.recipe import RecipeParser
 import fixtures
-import six
 import transaction
 from zope.component import getUtility
-from zope.security.proxy import (
-    isinstance as zisinstance,
-    removeSecurityProxy,
-    )
+from zope.security.proxy import removeSecurityProxy
 
 from lp.app.enums import InformationType
 from lp.code.interfaces.branchhosting import IBranchHostingClient
@@ -164,42 +160,6 @@ def consistent_branch_names():
         yield "branch-%s" % next(index)
 
 
-def make_package_branches(factory, series, sourcepackagename, branch_count,
-                          official_count=0, owner=None, registrant=None):
-    """Make some package branches.
-
-    Make `branch_count` branches, and make `official_count` of those
-    official branches.
-    """
-    if zisinstance(sourcepackagename, six.string_types):
-        sourcepackagename = factory.getOrMakeSourcePackageName(
-            sourcepackagename)
-    # Make the branches created in the past in order.
-    time_gen = time_counter(delta=timedelta(days=-1))
-    branch_names = consistent_branch_names()
-    branches = [
-        factory.makePackageBranch(
-            distroseries=series,
-            sourcepackagename=sourcepackagename,
-            date_created=next(time_gen),
-            name=next(branch_names), owner=owner, registrant=registrant)
-        for i in range(branch_count)]
-
-    official = []
-    # Sort the pocket items so RELEASE is last, and thus first popped.
-    pockets = sorted(PackagePublishingPocket.items, reverse=True)
-    # Since there can be only one link per pocket, max out the number of
-    # official branches at the pocket count.
-    for i in range(min(official_count, len(pockets))):
-        branch = branches.pop()
-        pocket = pockets.pop()
-        SeriesSourcePackageBranchSet.new(
-            series, pocket, sourcepackagename, branch, branch.owner)
-        official.append(branch)
-
-    return series, branches, official
-
-
 def make_official_package_branch(factory, owner=None):
     """Make a branch linked to the pocket of a source package."""
     branch = factory.makePackageBranch(owner=owner)
diff --git a/lib/lp/soyuz/tests/soyuz.py b/lib/lp/soyuz/tests/soyuz.py
index 1fbe3ba..52c9fb7 100644
--- a/lib/lp/soyuz/tests/soyuz.py
+++ b/lib/lp/soyuz/tests/soyuz.py
@@ -9,7 +9,6 @@ __metaclass__ = type
 
 __all__ = [
     'Base64KeyMatches',
-    'SoyuzTestHelper',
     ]
 
 import base64
@@ -20,90 +19,7 @@ from testtools.matchers import (
     )
 from zope.component import getUtility
 
-from lp.registry.interfaces.distribution import IDistributionSet
-from lp.registry.interfaces.person import IPersonSet
-from lp.registry.interfaces.pocket import PackagePublishingPocket
 from lp.services.gpg.interfaces import IGPGHandler
-from lp.soyuz.enums import PackagePublishingStatus
-from lp.soyuz.model.publishing import SourcePackagePublishingHistory
-from lp.testing.sampledata import (
-    BUILDD_ADMIN_USERNAME,
-    UBUNTU_DISTRIBUTION_NAME,
-    )
-
-
-class SoyuzTestHelper:
-    """Helper class to support easier tests in Soyuz component."""
-
-    def __init__(self):
-        self.ubuntu = getUtility(IDistributionSet)[UBUNTU_DISTRIBUTION_NAME]
-        self.cprov_archive = getUtility(
-            IPersonSet).getByName(BUILDD_ADMIN_USERNAME).archive
-
-    @property
-    def sample_publishing_data(self):
-        """Return a list of triples as (status, archive, pocket).
-
-        Returns the following triples (in this order):
-
-         1. ubuntu/PRIMARY, PENDING, RELEASE;
-         2. ubuntu/PRIMARY, PUBLISHED, RELEASE;
-         3. ubuntu/PRIMARY, PENDING, UPDATES;
-         4. ubuntu/PRIMARY, PUBLISHED, PROPOSED;
-         5. ubuntu/cprov PPA, PENDING, RELEASE;
-         6. ubuntu/cprov PPA, PUBLISHED, RELEASE;
-         7. ubuntu/cprov PPA, PENDING, UPDATES;
-         8. ubuntu/cprov PPA, PUBLISHED, PROPOSED;
-        """
-        return [
-            (PackagePublishingStatus.PENDING, self.ubuntu.main_archive,
-             PackagePublishingPocket.RELEASE),
-            (PackagePublishingStatus.PUBLISHED, self.ubuntu.main_archive,
-             PackagePublishingPocket.RELEASE),
-            (PackagePublishingStatus.PENDING, self.ubuntu.main_archive,
-             PackagePublishingPocket.UPDATES),
-            (PackagePublishingStatus.PUBLISHED, self.ubuntu.main_archive,
-             PackagePublishingPocket.PROPOSED),
-            (PackagePublishingStatus.PENDING, self.cprov_archive,
-             PackagePublishingPocket.RELEASE),
-            (PackagePublishingStatus.PUBLISHED, self.cprov_archive,
-             PackagePublishingPocket.RELEASE),
-            (PackagePublishingStatus.PENDING, self.cprov_archive,
-             PackagePublishingPocket.UPDATES),
-            (PackagePublishingStatus.PUBLISHED, self.cprov_archive,
-             PackagePublishingPocket.PROPOSED),
-            ]
-
-    def createPublishingForDistroSeries(self, sourcepackagerelease,
-                                        distroseries):
-        """Return a list of `SourcePackagePublishingHistory`.
-
-        The publishing records are created according to the given
-        `SourcePackageRelease` and `DistroSeries` for all
-        (status, archive, pocket) returned from `sample_publishing_data`.
-        """
-        sample_pub = []
-        for status, archive, pocket in self.sample_publishing_data:
-            pub = SourcePackagePublishingHistory(
-                sourcepackagerelease=sourcepackagerelease,
-                sourcepackagename=sourcepackagerelease.sourcepackagename,
-                distroseries=distroseries,
-                component=sourcepackagerelease.component,
-                section=sourcepackagerelease.section,
-                status=status,
-                archive=archive,
-                pocket=pocket)
-            # Flush the object changes into DB do guarantee stable database
-            # ID order as expected in the callsites.
-            sample_pub.append(pub)
-        return sample_pub
-
-    def checkPubList(self, expected, given):
-        """Check if the given publication list matches the expected one.
-
-        Return True if the lists matches, otherwise False.
-        """
-        return [p.id for p in expected] == [r.id for r in given]
 
 
 class Base64KeyMatches(Matcher):
diff --git a/lib/lp/testing/__init__.py b/lib/lp/testing/__init__.py
index 8fb58eb..b9f7c58 100644
--- a/lib/lp/testing/__init__.py
+++ b/lib/lp/testing/__init__.py
@@ -47,7 +47,6 @@ __all__ = [
     'TestCaseWithFactory',
     'time_counter',
     'unlink_source_packages',
-    'validate_mock_class',
     'verifyObject',
     'with_anonymous_login',
     'with_celebrity_logged_in',
@@ -63,12 +62,6 @@ from datetime import (
     )
 from fnmatch import fnmatchcase
 from functools import partial
-from inspect import (
-    getargspec,
-    getmro,
-    isclass,
-    ismethod,
-    )
 import logging
 import os
 import re
@@ -1430,79 +1423,6 @@ def set_feature_flag(name, value, scope=u'default', priority=1):
     store.flush()
 
 
-def validate_mock_class(mock_class):
-    """Validate method signatures in mock classes derived from real classes.
-
-    We often use mock classes in tests which are derived from real
-    classes.
-
-    This function ensures that methods redefined in the mock
-    class have the same signature as the corresponding methods of
-    the base class.
-
-    >>> class A:
-    ...
-    ...     def method_one(self, a):
-    ...         pass
-
-    >>>
-    >>> class B(A):
-    ...     def method_one(self, a):
-    ...        pass
-    >>> validate_mock_class(B)
-
-    If a class derived from A defines method_one with a different
-    signature, we get an AssertionError.
-
-    >>> class C(A):
-    ...     def method_one(self, a, b):
-    ...        pass
-    >>> validate_mock_class(C)
-    Traceback (most recent call last):
-    ...
-    AssertionError: Different method signature for method_one:...
-
-    Even a parameter name must not be modified.
-
-    >>> class D(A):
-    ...     def method_one(self, b):
-    ...        pass
-    >>> validate_mock_class(D)
-    Traceback (most recent call last):
-    ...
-    AssertionError: Different method signature for method_one:...
-
-    If validate_mock_class() for anything but a class, we get an
-    AssertionError.
-
-    >>> validate_mock_class('a string')
-    Traceback (most recent call last):
-    ...
-    AssertionError: validate_mock_class() must be called for a class
-    """
-    assert isclass(mock_class), (
-        "validate_mock_class() must be called for a class")
-    base_classes = getmro(mock_class)
-    # Don't use inspect.getmembers() here because it fails on __provides__, a
-    # descriptor added by zope.interface as part of its caching strategy. See
-    # http://comments.gmane.org/gmane.comp.python.zope.interface/241.
-    for name in dir(mock_class):
-        if name == '__provides__':
-            continue
-        obj = getattr(mock_class, name)
-        if ismethod(obj):
-            for base_class in base_classes[1:]:
-                if name in base_class.__dict__:
-                    mock_args = getargspec(obj)
-                    real_args = getargspec(base_class.__dict__[name])
-                    if mock_args != real_args:
-                        raise AssertionError(
-                            'Different method signature for %s: %r %r' % (
-                            name, mock_args, real_args))
-                    else:
-                        break
-
-
 def ws_object(launchpad, obj):
     """Convert an object into its webservice version.