Commits

Olemis Lang  committed ae8a9e8 Merge

BH Multiproduct #350 : Incorporating patches for bep_0003_multiproduct branch after r1433322

  • Participants
  • Parent commits e8a5e51, b8b61ed
  • Branches t350_product_components

Comments (0)

Files changed (4)

 #t115/t115_r1429886_product_envs.diff
 #t115/t115_r1429886_product_config.diff
 #t115/t115_r1429886_product_envs_testing.diff
-t115/t115_r1431447_product_envs_bep3_p1.diff
+#t115/t115_r1431447_product_envs_bep3_p1.diff
+t115/t115_r1433322_unittest2_assertRaises_msg.diff
 t350/t350_r1432088_product_component_enable.diff

File t115/t115_r1431447_product_envs_bep3_p1.diff

 # HG changeset patch
-# Parent 00a5e8114cb43b9d28de1ae1ce8030fbe5e7b2b8
+# Parent 9b04a5a324bee6bf4f6b6d044488f9f7868f9e43
 BH Multiproduct #115 : Product environments. Compliance with BEP 3 - part 1
 
-diff -r 00a5e8114cb4 bloodhound_multiproduct/multiproduct/env.py
---- a/bloodhound_multiproduct/multiproduct/env.py	Sun Jan 13 10:19:19 2013 +0000
-+++ b/bloodhound_multiproduct/multiproduct/env.py	Mon Jan 14 01:49:36 2013 -0500
+diff -r 9b04a5a324be bloodhound_multiproduct/multiproduct/env.py
+--- a/bloodhound_multiproduct/multiproduct/env.py	Mon Jan 14 14:05:28 2013 +0000
++++ b/bloodhound_multiproduct/multiproduct/env.py	Tue Jan 15 09:25:35 2013 -0500
 @@ -46,7 +46,7 @@
      def __init__(self, path, create=False, options=[]):
          super(Environment, self).__init__(path, create=create, options=options)
  
      project_icon = Option('project', 'icon', 'common/trac.ico',
          """URL of the icon of the product.""")
-@@ -207,6 +207,12 @@
+@@ -207,6 +207,13 @@
          :param product: product prefix or an instance of
                          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)
  
          if isinstance(product, Product):
-@@ -221,9 +227,9 @@
+@@ -221,9 +228,9 @@
                          product, products)
                  raise LookupError("Missing product %s" % (product,))
  
          self.systeminfo = []
          self._href = self._abs_href = None
  
-@@ -231,16 +237,12 @@
+@@ -231,16 +238,12 @@
  
      # ISystemInfoProvider methods
  
      get_repository = trac.env.Environment.get_repository.im_func
      is_component_enabled = trac.env.Environment.is_component_enabled.im_func
  
-@@ -264,7 +266,7 @@
+@@ -264,7 +267,7 @@
                 ...
          """
          # share connection pool with global environment
  
      @lazy
      def db_exc(self):
-@@ -282,7 +284,7 @@
+@@ -282,7 +285,7 @@
                  ...
          """
          # exception types same as in global environment
  
      def with_transaction(self, db=None):
          """Decorator for transaction functions :deprecated:"""
-@@ -293,7 +295,7 @@
+@@ -293,7 +296,7 @@
  
          See `trac.db.api.get_read_db` for detailed documentation."""
          # database connection is shared with global environment
  
      @property
      def db_query(self):
-@@ -328,7 +330,7 @@
+@@ -328,7 +331,7 @@
            `db_transaction`).
          """
          BloodhoundIterableCursor.set_env(self)
  
      @property
      def db_transaction(self):
-@@ -364,7 +366,7 @@
+@@ -364,7 +367,7 @@
            (`db_query` or `db_transaction`).
          """
          BloodhoundIterableCursor.set_env(self)
  
      def shutdown(self, tid=None):
          """Close the environment."""
-@@ -385,58 +387,30 @@
+@@ -385,58 +388,30 @@
          """
          # TODO: Handle options args
  
          if format:
              format = format.replace('$(', '%(') \
                       .replace('%(path)s', self.path) \
-@@ -449,25 +423,8 @@
+@@ -449,25 +424,8 @@
          self.log.info('-' * 32 + ' environment startup [Trac %s] ' + '-' * 32,
                        get_pkginfo(core).get('version', VERSION))
  
          return False
  
      def upgrade(self, backup=False, backup_dest=None):
-diff -r 00a5e8114cb4 bloodhound_multiproduct/tests/env.py
---- a/bloodhound_multiproduct/tests/env.py	Sun Jan 13 10:19:19 2013 +0000
-+++ b/bloodhound_multiproduct/tests/env.py	Mon Jan 14 01:49:36 2013 -0500
-@@ -20,9 +20,17 @@
+diff -r 9b04a5a324be bloodhound_multiproduct/tests/env.py
+--- a/bloodhound_multiproduct/tests/env.py	Mon Jan 14 14:05:28 2013 +0000
++++ b/bloodhound_multiproduct/tests/env.py	Tue Jan 15 09:25:35 2013 -0500
+@@ -18,11 +18,22 @@
  
+ """Tests for Apache(TM) Bloodhound's product environments"""
+ 
++from inspect import stack
  import os.path
  import shutil
 +import sys
  
 +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
  from trac.test import EnvironmentStub
  from trac.tests.env import EnvironmentTestCase
  
-@@ -100,6 +108,14 @@
+@@ -39,6 +50,55 @@
+     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=None, *args, **kwargs)
++
+     # Product data
+ 
+     default_product = 'tp1'
+@@ -100,6 +160,14 @@
              # table remains but database version is deleted
              pass
  
  class ProductEnvTestCase(EnvironmentTestCase, MultiproductTestCase):
      r"""Test cases for Trac environments rewritten for product environments
      """
-@@ -131,9 +147,98 @@
+@@ -131,9 +199,99 @@
  
          EnvironmentTestCase.tearDown(self)
  
 +                    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:
 +        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
 -    unittest.main(defaultTest='suite')
 +    unittest.main(defaultTest='test_suite')
  
-diff -r 00a5e8114cb4 bloodhound_theme/setup.py
---- a/bloodhound_theme/setup.py	Sun Jan 13 10:19:19 2013 +0000
-+++ b/bloodhound_theme/setup.py	Mon Jan 14 01:49:36 2013 -0500
+diff -r 9b04a5a324be bloodhound_theme/setup.py
+--- a/bloodhound_theme/setup.py	Mon Jan 14 14:05:28 2013 +0000
++++ b/bloodhound_theme/setup.py	Tue Jan 15 09:25:35 2013 -0500
 @@ -19,6 +19,7 @@
  #  under the License.
  

File t115/t115_r1433322_unittest2_assertRaises_msg.diff

+# HG changeset patch
+# Parent 3386dd0e88c375eae35d911970cfa178f49aace7
+BH Multiproduct #115 : Test cases improved. Logging capabilities in assertRaises
+
+diff -r 3386dd0e88c3 bloodhound_multiproduct/multiproduct/env.py
+--- a/bloodhound_multiproduct/multiproduct/env.py	Tue Jan 15 09:32:53 2013 +0000
++++ b/bloodhound_multiproduct/multiproduct/env.py	Tue Jan 15 10:01:21 2013 -0500
+@@ -208,10 +208,11 @@
+                         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)
+ 
+diff -r 3386dd0e88c3 bloodhound_multiproduct/tests/env.py
+--- a/bloodhound_multiproduct/tests/env.py	Tue Jan 15 09:32:53 2013 +0000
++++ b/bloodhound_multiproduct/tests/env.py	Tue Jan 15 10:01:21 2013 -0500
+@@ -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 @@
+     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=None, *args, **kwargs)
++
+     # Product data
+ 
+     default_product = 'tp1'
+@@ -196,6 +246,7 @@
+                     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 @@
+         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

File t350/t350_r1432088_product_component_enable.diff

 # HG changeset patch
-# Parent 0ce445d6efc5f22823d02def8b5988e90d145246
+# Parent 7b68c7018f934601265c914e05af4f23c9a3ae86
 BH Multiproduct #350 : Product-specific component rules (enable / disable)
 
-diff -r 0ce445d6efc5 bloodhound_multiproduct/tests/env.py
---- a/bloodhound_multiproduct/tests/env.py	Mon Jan 14 19:07:09 2013 -0500
-+++ b/bloodhound_multiproduct/tests/env.py	Mon Jan 14 19:19:04 2013 -0500
-@@ -228,6 +228,28 @@
-         #        "(got multiproduct.env.ProductEnvironment instance instead)"
-         #self.assertEqual(msg, expected_msg)
+diff -r 7b68c7018f93 bloodhound_multiproduct/tests/env.py
+--- a/bloodhound_multiproduct/tests/env.py	Tue Jan 15 13:56:46 2013 -0500
++++ b/bloodhound_multiproduct/tests/env.py	Tue Jan 15 16:04:53 2013 -0500
+@@ -282,6 +282,28 @@
+                 "(got multiproduct.env.ProductEnvironment instance instead)"
+         self.assertEqual(msg, expected_msg)
  
 +    def test_component_enable(self):
 +        class C(Component):