Olemis Lang avatar Olemis Lang committed 84aeac2

BH Multiproduct #676 : TypeError is not raised anymore in test_typecheck

Comments (0)

Files changed (3)

+t676/t676_r1526822_product_env_typecheck.diff
+t676/t676_r1526822_product_env_typecheck.tests.diff

t676/t676_r1526822_product_env_typecheck.diff

+# HG changeset patch
+# Parent ec411de59e615822e81165f21992a449f0df4136
+BH Multiproduct #676 : Instances of ProductEnvironment allowed in class calls
+
+diff -r ec411de59e61 bloodhound_multiproduct/multiproduct/env.py
+--- a/bloodhound_multiproduct/multiproduct/env.py	Fri Sep 27 07:59:57 2013 +0000
++++ b/bloodhound_multiproduct/multiproduct/env.py	Sat Sep 28 17:32:43 2013 -0500
+@@ -362,6 +362,25 @@
+     
+     class __metaclass__(ComponentMeta):
+ 
++        def select_global_env(f):
++            # Keep the signature of __call__ method
++            def __call__(self, *args, **kwargs):
++                """Instantiate environment according to product prefix or name
++    
++                @throws LookupError if no product matches neither prefix nor name 
++                """
++                if args:
++                    env = args[0]
++                    args = args[1:]
++                else:
++                    env = kwargs.pop('env', None)
++                if isinstance(env, ProductEnvironment):
++                    global_env = env.parent
++                else:
++                    global_env = env
++                return f(self, global_env, *args, **kwargs)
++            return __call__
++
+         def product_env_keymap(args, kwds, kwd_mark):
+             # Remove meta-reference to self (i.e. product env class)
+             args = args[1:]
+@@ -377,14 +396,15 @@
+                     kwds['product'] = product.prefix
+             return default_keymap(args, kwds, kwd_mark)
+ 
++        @select_global_env
+         @lru_cache(maxsize=100, keymap=product_env_keymap)
+         def __call__(self, *args, **kwargs):
+-            """Return an existing instance of there is a hit 
++            """Return an existing instance if there is a hit 
+             in the global LRU cache, otherwise create a new instance.
+             """
+             return ComponentMeta.__call__(self, *args, **kwargs)
+ 
+-        del product_env_keymap
++        del product_env_keymap, select_global_env
+ 
+     implements(trac.env.ISystemInfoProvider, IPermissionRequestor)
+ 

t676/t676_r1526822_product_env_typecheck.tests.diff

+# HG changeset patch
+# Parent 05b443a03c34b5e3ff105bcc03396e447015d9a0
+BH Multiproduct #676 : Test cases for product env type checks
+
+diff -r 05b443a03c34 bloodhound_multiproduct/tests/env.py
+--- a/bloodhound_multiproduct/tests/env.py	Sat Sep 28 17:32:43 2013 -0500
++++ b/bloodhound_multiproduct/tests/env.py	Sat Sep 28 17:41:38 2013 -0500
+@@ -388,15 +388,8 @@
+     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')
+-
+-        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)
++        env2 = ProductEnvironment(self.product_env, 'tp2')
++        self.assertIs(env2, ProductEnvironment(self.env, 'tp2'))
+ 
+     def test_component_enable(self):
+         """Testing env.is_component_enabled"""
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.