Commits

Olemis Lang committed a9251cb

BH Multiproduct #350 : Renaming patch to reflect that it works against r1433322

  • Participants
  • Parent commits b0a8d5d
  • Branches t350_product_components

Comments (0)

Files changed (3)

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

t350/t350_r1432088_product_component_enable.diff

-# HG changeset patch
-# Parent 7b68c7018f934601265c914e05af4f23c9a3ae86
-BH Multiproduct #350 : Product-specific component rules (enable / disable)
-
-diff -r 7b68c7018f93 bloodhound_multiproduct/multiproduct/env.py
---- a/bloodhound_multiproduct/multiproduct/env.py	Tue Jan 15 13:56:46 2013 -0500
-+++ b/bloodhound_multiproduct/multiproduct/env.py	Tue Jan 15 17:07:36 2013 -0500
-@@ -31,6 +31,7 @@
- 
- import trac.env
- 
-+from multiproduct.config import Configuration
- from multiproduct.model import Product
- from multiproduct.dbcursor import BloodhoundIterableCursor
- 
-@@ -93,7 +94,7 @@
-         get_log_dir, backup
-         """
-         try:
--            if attrnm == 'parent':
-+            if attrnm in ('parent', '_rules'):
-                 raise AttributeError
-             return getattr(self.parent, attrnm)
-         except AttributeError:
-@@ -245,7 +246,23 @@
-     enable_component = trac.env.Environment.enable_component.im_func
-     get_known_users = trac.env.Environment.get_known_users.im_func
-     get_repository = trac.env.Environment.get_repository.im_func
--    is_component_enabled = trac.env.Environment.is_component_enabled.im_func
-+
-+    is_component_enabled_local = trac.env.Environment.is_component_enabled.im_func
-+
-+    def is_component_enabled(self, cls):
-+        """Implemented to only allow activation of components already 
-+        activated in the global environment that are in turn not disabled in
-+        the configuration.
-+
-+        This is called by the `ComponentManager` base class when a
-+        component is about to be activated. If this method returns
-+        `False`, the component does not get activated. If it returns
-+        `None`, the component only gets activated if it is located in
-+        the `plugins` directory of the environment.
-+        """
-+        if not self.parent.is_component_enabled(cls):
-+            return False
-+        return self.is_component_enabled_local(cls)
- 
-     def get_db_cnx(self):
-         """Return a database connection from the connection pool
-@@ -391,8 +408,8 @@
-     def setup_config(self):
-         """Load the configuration object.
-         """
--        # FIXME: Install product-specific configuration object
--        self.config = self.parent.config
-+        # FIXME: Inherit global environment setting ?
-+        self.config = Configuration(self.parent, self.product.prefix)
-         self.setup_log()
- 
-     def setup_log(self):
-diff -r 7b68c7018f93 bloodhound_multiproduct/tests/config.py
---- a/bloodhound_multiproduct/tests/config.py	Tue Jan 15 13:56:46 2013 -0500
-+++ b/bloodhound_multiproduct/tests/config.py	Tue Jan 15 17:07:36 2013 -0500
-@@ -189,9 +189,9 @@
-         self._test_with_inherit(testcb)
- 
- 
--def suite():
-+def test_suite():
-     return unittest.makeSuite(ProductConfigTestCase,'test')
- 
- if __name__ == '__main__':
--    unittest.main(defaultTest='suite')
-+    unittest.main(defaultTest='test_suite')
- 
-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 17:07:36 2013 -0500
-@@ -34,6 +34,7 @@
-     from unittest.case import _AssertRaisesContext
- 
- from trac.config import Option
-+from trac.core import Component
- from trac.env import Environment
- from trac.test import EnvironmentStub
- from trac.tests.env import EnvironmentTestCase
-@@ -209,6 +210,7 @@
-         self.product_env = ProductEnvironment(self.env, self.default_product)
- 
-     def test_attr_forward_parent(self):
-+        """Testing env.__getattr__"""
-         class EnvironmentAttrSandbox(EnvironmentStub):
-             """Limit the impact of class edits so as to avoid race conditions
-             """
-@@ -258,7 +260,7 @@
- 
-         for attrnm in 'component_activated _component_rules ' \
-                 'enable_component get_known_users get_repository ' \
--                'is_component_enabled _component_name'.split():
-+                '_component_name'.split():
-             original = getattr(Environment, attrnm)
-             if isinstance(original, MethodType):
-                 translation = getattr(self.product_env, attrnm)
-@@ -272,6 +274,7 @@
-                         "'%s' property differs in product env" % (attrnm,))
- 
-     def test_typecheck(self):
-+        """Testing env.__init__"""
-         self._load_product_from_data(self.env, 'tp2')
-         with self.assertRaises(TypeError) as cm_test:
-             new_env = ProductEnvironment(self.product_env, 'tp2')
-@@ -282,6 +285,57 @@
-                 "(got multiproduct.env.ProductEnvironment instance instead)"
-         self.assertEqual(msg, expected_msg)
- 
-+    def test_component_enable(self):
-+        """Testing env.is_component_enabled"""
-+        class C(Component):
-+            pass
-+        # Let's pretend this was declared elsewhere
-+        C.__module__ = 'dummy_module'
-+
-+        global_env = self.env
-+        product_env = self.product_env
-+        
-+        def clear_component_rules(env):
-+            del env._rules
-+            env.enabled.clear()
-+
-+        # C initially disabled in both envs
-+        self.assertFalse(global_env.is_component_enabled(C))
-+        self.assertFalse(product_env.is_component_enabled_local(C))
-+        self.assertIs(global_env[C], None)
-+        self.assertIs(product_env[C], None)
-+
-+        clear_component_rules(global_env)
-+        clear_component_rules(product_env)
-+
-+        # C enabled in product env but not in global env
-+        product_env.enable_component(C)
-+        self.assertFalse(global_env.is_component_enabled(C))
-+        self.assertTrue(product_env.is_component_enabled_local(C))
-+        self.assertIs(global_env[C], None)
-+        self.assertIs(product_env[C], None)
-+
-+        clear_component_rules(global_env)
-+        clear_component_rules(product_env)
-+
-+        # C enabled in both envs
-+        product_env.enable_component(C)
-+        global_env.enable_component(C)
-+        self.assertTrue(global_env.is_component_enabled(C))
-+        self.assertTrue(product_env.is_component_enabled_local(C))
-+        self.assertIsNot(global_env[C], None)
-+        self.assertIsNot(product_env[C], None)
-+
-+        clear_component_rules(global_env)
-+        clear_component_rules(product_env)
-+
-+        # C enabled in global env but not in product env
-+        global_env.enable_component(C)
-+        self.assertTrue(global_env.is_component_enabled(C))
-+        self.assertFalse(product_env.is_component_enabled_local(C))
-+        self.assertIsNot(global_env[C], None)
-+        self.assertIs(product_env[C], None)
-+
-     def tearDown(self):
-         # Release reference to transient environment mock object
-         self.env = None

t350/t350_r1433322_product_component_enable.diff

+# HG changeset patch
+# Parent 7b68c7018f934601265c914e05af4f23c9a3ae86
+BH Multiproduct #350 : Product-specific component rules (enable / disable)
+
+diff -r 7b68c7018f93 bloodhound_multiproduct/multiproduct/env.py
+--- a/bloodhound_multiproduct/multiproduct/env.py	Tue Jan 15 13:56:46 2013 -0500
++++ b/bloodhound_multiproduct/multiproduct/env.py	Tue Jan 15 17:07:36 2013 -0500
+@@ -31,6 +31,7 @@
+ 
+ import trac.env
+ 
++from multiproduct.config import Configuration
+ from multiproduct.model import Product
+ from multiproduct.dbcursor import BloodhoundIterableCursor
+ 
+@@ -93,7 +94,7 @@
+         get_log_dir, backup
+         """
+         try:
+-            if attrnm == 'parent':
++            if attrnm in ('parent', '_rules'):
+                 raise AttributeError
+             return getattr(self.parent, attrnm)
+         except AttributeError:
+@@ -245,7 +246,23 @@
+     enable_component = trac.env.Environment.enable_component.im_func
+     get_known_users = trac.env.Environment.get_known_users.im_func
+     get_repository = trac.env.Environment.get_repository.im_func
+-    is_component_enabled = trac.env.Environment.is_component_enabled.im_func
++
++    is_component_enabled_local = trac.env.Environment.is_component_enabled.im_func
++
++    def is_component_enabled(self, cls):
++        """Implemented to only allow activation of components already 
++        activated in the global environment that are in turn not disabled in
++        the configuration.
++
++        This is called by the `ComponentManager` base class when a
++        component is about to be activated. If this method returns
++        `False`, the component does not get activated. If it returns
++        `None`, the component only gets activated if it is located in
++        the `plugins` directory of the environment.
++        """
++        if not self.parent.is_component_enabled(cls):
++            return False
++        return self.is_component_enabled_local(cls)
+ 
+     def get_db_cnx(self):
+         """Return a database connection from the connection pool
+@@ -391,8 +408,8 @@
+     def setup_config(self):
+         """Load the configuration object.
+         """
+-        # FIXME: Install product-specific configuration object
+-        self.config = self.parent.config
++        # FIXME: Inherit global environment setting ?
++        self.config = Configuration(self.parent, self.product.prefix)
+         self.setup_log()
+ 
+     def setup_log(self):
+diff -r 7b68c7018f93 bloodhound_multiproduct/tests/config.py
+--- a/bloodhound_multiproduct/tests/config.py	Tue Jan 15 13:56:46 2013 -0500
++++ b/bloodhound_multiproduct/tests/config.py	Tue Jan 15 17:07:36 2013 -0500
+@@ -189,9 +189,9 @@
+         self._test_with_inherit(testcb)
+ 
+ 
+-def suite():
++def test_suite():
+     return unittest.makeSuite(ProductConfigTestCase,'test')
+ 
+ if __name__ == '__main__':
+-    unittest.main(defaultTest='suite')
++    unittest.main(defaultTest='test_suite')
+ 
+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 17:07:36 2013 -0500
+@@ -34,6 +34,7 @@
+     from unittest.case import _AssertRaisesContext
+ 
+ from trac.config import Option
++from trac.core import Component
+ from trac.env import Environment
+ from trac.test import EnvironmentStub
+ from trac.tests.env import EnvironmentTestCase
+@@ -209,6 +210,7 @@
+         self.product_env = ProductEnvironment(self.env, self.default_product)
+ 
+     def test_attr_forward_parent(self):
++        """Testing env.__getattr__"""
+         class EnvironmentAttrSandbox(EnvironmentStub):
+             """Limit the impact of class edits so as to avoid race conditions
+             """
+@@ -258,7 +260,7 @@
+ 
+         for attrnm in 'component_activated _component_rules ' \
+                 'enable_component get_known_users get_repository ' \
+-                'is_component_enabled _component_name'.split():
++                '_component_name'.split():
+             original = getattr(Environment, attrnm)
+             if isinstance(original, MethodType):
+                 translation = getattr(self.product_env, attrnm)
+@@ -272,6 +274,7 @@
+                         "'%s' property differs in product env" % (attrnm,))
+ 
+     def test_typecheck(self):
++        """Testing env.__init__"""
+         self._load_product_from_data(self.env, 'tp2')
+         with self.assertRaises(TypeError) as cm_test:
+             new_env = ProductEnvironment(self.product_env, 'tp2')
+@@ -282,6 +285,57 @@
+                 "(got multiproduct.env.ProductEnvironment instance instead)"
+         self.assertEqual(msg, expected_msg)
+ 
++    def test_component_enable(self):
++        """Testing env.is_component_enabled"""
++        class C(Component):
++            pass
++        # Let's pretend this was declared elsewhere
++        C.__module__ = 'dummy_module'
++
++        global_env = self.env
++        product_env = self.product_env
++        
++        def clear_component_rules(env):
++            del env._rules
++            env.enabled.clear()
++
++        # C initially disabled in both envs
++        self.assertFalse(global_env.is_component_enabled(C))
++        self.assertFalse(product_env.is_component_enabled_local(C))
++        self.assertIs(global_env[C], None)
++        self.assertIs(product_env[C], None)
++
++        clear_component_rules(global_env)
++        clear_component_rules(product_env)
++
++        # C enabled in product env but not in global env
++        product_env.enable_component(C)
++        self.assertFalse(global_env.is_component_enabled(C))
++        self.assertTrue(product_env.is_component_enabled_local(C))
++        self.assertIs(global_env[C], None)
++        self.assertIs(product_env[C], None)
++
++        clear_component_rules(global_env)
++        clear_component_rules(product_env)
++
++        # C enabled in both envs
++        product_env.enable_component(C)
++        global_env.enable_component(C)
++        self.assertTrue(global_env.is_component_enabled(C))
++        self.assertTrue(product_env.is_component_enabled_local(C))
++        self.assertIsNot(global_env[C], None)
++        self.assertIsNot(product_env[C], None)
++
++        clear_component_rules(global_env)
++        clear_component_rules(product_env)
++
++        # C enabled in global env but not in product env
++        global_env.enable_component(C)
++        self.assertTrue(global_env.is_component_enabled(C))
++        self.assertFalse(product_env.is_component_enabled_local(C))
++        self.assertIsNot(global_env[C], None)
++        self.assertIs(product_env[C], None)
++
+     def tearDown(self):
+         # Release reference to transient environment mock object
+         self.env = None