incubator-bloodhound-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1433881 - in /incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct: multiproduct/env.py tests/env.py
Date Wed, 16 Jan 2013 10:21:44 GMT
Author: jure
Date: Wed Jan 16 10:21:44 2013
New Revision: 1433881

URL: http://svn.apache.org/viewvc?rev=1433881&view=rev
Log:
#115 patch t115_r1433322_unittest2_assertRaises_msg.diff applied (from olemis)


Modified:
    incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/env.py
    incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/tests/env.py

Modified: incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/env.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/env.py?rev=1433881&r1=1433880&r2=1433881&view=diff
==============================================================================
--- incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/env.py
(original)
+++ incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/env.py
Wed Jan 16 10:21:44 2013
@@ -244,10 +244,11 @@ class ProductEnvironment(Component, Comp
                         multiproduct.model.Product
         """
         if not isinstance(env, trac.env.Environment):
+            cls = self.__class__
             raise TypeError("Initializer must be called with " \
                 "trac.env.Environment instance as first argument " \
                 "(got %s instance instead)" % 
-                        (self._component_name(env.__class__),) )
+                         (cls.__module__ + '.' + cls.__name__, ))
 
         ComponentManager.__init__(self)
 

Modified: incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/tests/env.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/tests/env.py?rev=1433881&r1=1433880&r2=1433881&view=diff
==============================================================================
--- incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/tests/env.py
(original)
+++ incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/tests/env.py
Wed Jan 16 10:21:44 2013
@@ -18,19 +18,20 @@
 
 """Tests for Apache(TM) Bloodhound's product environments"""
 
+from inspect import stack
 import os.path
 import shutil
+from sqlite3 import OperationalError
 import sys
 import tempfile
-
-from sqlite3 import OperationalError
-
 from types import MethodType
 
 if sys.version_info < (2, 7):
     import unittest2 as unittest
+    from unittest2.case import _AssertRaisesContext
 else:
     import unittest
+    from unittest.case import _AssertRaisesContext
 
 from trac.config import Option
 from trac.env import Environment
@@ -50,6 +51,55 @@ class MultiproductTestCase(unittest.Test
     to create product-specific subclasses.
     """
 
+    # unittest2 extensions
+
+    exceptFailureMessage = None
+
+    class _AssertRaisesLoggingContext(_AssertRaisesContext):
+        """Add logging capabilities to assertRaises
+        """
+        def __init__(self, expected, test_case, expected_regexp=None):
+            _AssertRaisesContext.__init__(
+                    self, expected, test_case, expected_regexp)
+            self.test_case = test_case
+
+        @staticmethod
+        def _tb_locals(tb):
+            if tb is None:
+                # Inspect interpreter stack two levels up
+                ns = stack()[2][0].f_locals.copy()
+            else:
+                # Traceback already in context
+                ns = tb.tb_frame.f_locals.copy()
+            ns.pop('__builtins__', None)
+            return ns
+
+        def __exit__(self, exc_type, exc_value, tb):
+            try:
+                return _AssertRaisesContext.__exit__(self, 
+                    exc_type, exc_value, tb)
+            except self.failureException, exc:
+                msg = self.test_case.exceptFailureMessage 
+                if msg is not None:
+                    standardMsg = str(exc)
+                    msg = msg % self._tb_locals(tb)
+                    msg = self.test_case._formatMessage(msg, standardMsg)
+                    raise self.failureException(msg)
+                else:
+                    raise
+            finally:
+                # Clear message placeholder
+                self.test_case.exceptFailureMessage = None
+
+    def assertRaises(self, excClass, callableObj=None, *args, **kwargs):
+        """Adds logging capabilities on top of unittest2 implementation.
+        """
+        if callableObj is None:
+            return self._AssertRaisesLoggingContext(excClass, self)
+        else:
+            return unittest.TestCase.assertRaises(
+                    self, excClass, callableObj, *args, **kwargs)
+
     # Product data
 
     default_product = 'tp1'
@@ -196,6 +246,7 @@ class ProductEnvApiTestCase(Multiproduct
                     setattr(self.env.__class__, attrnm, 
                         property_mock(attrnm, self.env))
 
+                    self.exceptFailureMessage = 'Property %(attrnm)s'
                     with self.assertRaises(AttrSuccess) as cm_test_attr:
                         getattr(self.product_env, attrnm)
                 else:
@@ -225,11 +276,11 @@ class ProductEnvApiTestCase(Multiproduct
         with self.assertRaises(TypeError) as cm_test:
             new_env = ProductEnvironment(self.product_env, 'tp2')
 
-        #msg = str(cm_test.exception)
-        #expected_msg = "Initializer must be called with " \
-        #        "trac.env.Environment instance as first argument " \
-        #        "(got multiproduct.env.ProductEnvironment instance instead)"
-        #self.assertEqual(msg, expected_msg)
+        msg = str(cm_test.exception)
+        expected_msg = "Initializer must be called with " \
+                "trac.env.Environment instance as first argument " \
+                "(got multiproduct.env.ProductEnvironment instance instead)"
+        self.assertEqual(msg, expected_msg)
 
     def tearDown(self):
         # Release reference to transient environment mock object



Mime
View raw message