← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:move-instrument-method-helpers into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:move-instrument-method-helpers into launchpad:master.

Commit message:
Move instrument_method to lp.registry.tests.test_prf_hose

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

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

instrument_method and InstrumentedMethodObserver were originally written for the codeimport tests, and happened to also be used by the product release finder tests.  At this point only the product release finder tests still use these helpers, so move them there.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:move-instrument-method-helpers into launchpad:master.
diff --git a/lib/lp/codehosting/codeimport/tests/helpers.py b/lib/lp/codehosting/codeimport/tests/helpers.py
deleted file mode 100644
index 8c07f02..0000000
--- a/lib/lp/codehosting/codeimport/tests/helpers.py
+++ /dev/null
@@ -1,65 +0,0 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
-# GNU Affero General Public License version 3 (see the file LICENSE).
-
-"""Helpers for lp.codehosting.codeimport tests."""
-
-from __future__ import absolute_import, print_function
-
-__metaclass__ = type
-
-__all__ = [
-    'instrument_method', 'InstrumentedMethodObserver']
-
-
-def instrument_method(observer, obj, name):
-    """Wrap the named method of obj in an InstrumentedMethod object.
-
-    The InstrumentedMethod object will send events to the provided observer.
-    """
-    func = getattr(obj, name)
-    instrumented_func = _InstrumentedMethod(observer, name, func)
-    setattr(obj, name, instrumented_func)
-
-
-class _InstrumentedMethod:
-    """Wrapper for a callable, that sends event to an observer."""
-
-    def __init__(self, observer, name, func):
-        self.observer = observer
-        self.name = name
-        self.callable = func
-
-    def __call__(self, *args, **kwargs):
-        self.observer.called(self.name, args, kwargs)
-        try:
-            value = self.callable(*args, **kwargs)
-        except Exception as exc:
-            self.observer.raised(self.name, exc)
-            raise
-        else:
-            self.observer.returned(self.name, value)
-            return value
-
-
-class InstrumentedMethodObserver:
-    """Observer for InstrumentedMethod."""
-
-    def __init__(self, called=None, returned=None, raised=None):
-        if called is not None:
-            self.called = called
-        if returned is not None:
-            self.returned = returned
-        if raised is not None:
-            self.raised = raised
-
-    def called(self, name, args, kwargs):
-        """Called before an instrumented method."""
-        pass
-
-    def returned(self, name, value):
-        """Called after an instrumented method returned."""
-        pass
-
-    def raised(self, name, exc):
-        """Called when an instrumented method raises."""
-        pass
diff --git a/lib/lp/registry/tests/test_prf_hose.py b/lib/lp/registry/tests/test_prf_hose.py
index 600d11e..c679cc8 100644
--- a/lib/lp/registry/tests/test_prf_hose.py
+++ b/lib/lp/registry/tests/test_prf_hose.py
@@ -8,13 +8,63 @@ import shutil
 import tempfile
 import unittest
 
-from lp.codehosting.codeimport.tests.helpers import (
-    instrument_method,
-    InstrumentedMethodObserver,
-    )
 from lp.testing import reset_logging
 
 
+def instrument_method(observer, obj, name):
+    """Wrap the named method of obj in an InstrumentedMethod object.
+
+    The InstrumentedMethod object will send events to the provided observer.
+    """
+    func = getattr(obj, name)
+    instrumented_func = _InstrumentedMethod(observer, name, func)
+    setattr(obj, name, instrumented_func)
+
+
+class _InstrumentedMethod:
+    """Wrapper for a callable, that sends event to an observer."""
+
+    def __init__(self, observer, name, func):
+        self.observer = observer
+        self.name = name
+        self.callable = func
+
+    def __call__(self, *args, **kwargs):
+        self.observer.called(self.name, args, kwargs)
+        try:
+            value = self.callable(*args, **kwargs)
+        except Exception as exc:
+            self.observer.raised(self.name, exc)
+            raise
+        else:
+            self.observer.returned(self.name, value)
+            return value
+
+
+class InstrumentedMethodObserver:
+    """Observer for InstrumentedMethod."""
+
+    def __init__(self, called=None, returned=None, raised=None):
+        if called is not None:
+            self.called = called
+        if returned is not None:
+            self.returned = returned
+        if raised is not None:
+            self.raised = raised
+
+    def called(self, name, args, kwargs):
+        """Called before an instrumented method."""
+        pass
+
+    def returned(self, name, value):
+        """Called after an instrumented method returned."""
+        pass
+
+    def raised(self, name, exc):
+        """Called when an instrumented method raises."""
+        pass
+
+
 class Hose_Logging(unittest.TestCase):
     def testCreatesDefaultLogger(self):
         """Hose creates a default logger."""