incubator-bloodhound-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g..@apache.org
Subject svn commit: r1301696 - in /incubator/bloodhound/trunk/trac/trac: ticket/query.py util/introspection.py util/tests/introspection.py
Date Fri, 16 Mar 2012 18:52:53 GMT
Author: gjm
Date: Fri Mar 16 18:52:52 2012
New Revision: 1301696

URL: http://svn.apache.org/viewvc?rev=1301696&view=rev
Log:
provide functions to determine if a component is overridden by a subclass - uses this to determine
whether a ReportModule is active

Added:
    incubator/bloodhound/trunk/trac/trac/util/introspection.py   (with props)
    incubator/bloodhound/trunk/trac/trac/util/tests/introspection.py   (with props)
Modified:
    incubator/bloodhound/trunk/trac/trac/ticket/query.py

Modified: incubator/bloodhound/trunk/trac/trac/ticket/query.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/trunk/trac/trac/ticket/query.py?rev=1301696&r1=1301695&r2=1301696&view=diff
==============================================================================
--- incubator/bloodhound/trunk/trac/trac/ticket/query.py (original)
+++ incubator/bloodhound/trunk/trac/trac/ticket/query.py Fri Mar 16 18:52:52 2012
@@ -39,6 +39,7 @@ from trac.util.datefmt import format_dat
 from trac.util.presentation import Paginator
 from trac.util.text import empty, shorten_line, quote_query_string
 from trac.util.translation import _, tag_, cleandoc_
+from trac.util.introspection import get_enabled_component_subclass
 from trac.web import arg_list_to_args, parse_arg_list, IRequestHandler
 from trac.web.href import Href
 from trac.web.chrome import (INavigationContributor, Chrome,
@@ -865,7 +866,7 @@ class QueryModule(Component):
     def get_navigation_items(self, req):
         from trac.ticket.report import ReportModule
         if 'TICKET_VIEW' in req.perm and \
-                not self.env.is_component_enabled(ReportModule):
+                get_enabled_component_subclass(self.env, ReportModule) is None:
             yield ('mainnav', 'tickets',
                    tag.a(_('View Tickets'), href=req.href.query()))
 

Added: incubator/bloodhound/trunk/trac/trac/util/introspection.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/trunk/trac/trac/util/introspection.py?rev=1301696&view=auto
==============================================================================
--- incubator/bloodhound/trunk/trac/trac/util/introspection.py (added)
+++ incubator/bloodhound/trunk/trac/trac/util/introspection.py Fri Mar 16 18:52:52 2012
@@ -0,0 +1,35 @@
+
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing,
+#  software distributed under the License is distributed on an
+#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#  KIND, either express or implied.  See the License for the
+#  specific language governing permissions and limitations
+#  under the License.
+
+"""Helper functions for introspection functionality"""
+
+def subclasses(cls):
+    """recursively get subclasses of a class"""
+    for sub in cls.__subclasses__():
+        for subsub in subclasses(sub):
+            yield subsub
+        yield sub
+
+def get_enabled_component_subclass(env, cls):
+    """if the cls is not enabled, attempts to find a subclass which is"""
+    if env.is_component_enabled(cls):
+        return cls
+    for subcls in subclasses(cls):
+        if env.is_component_enabled(subcls):
+            return subcls
+    return None

Propchange: incubator/bloodhound/trunk/trac/trac/util/introspection.py
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/bloodhound/trunk/trac/trac/util/tests/introspection.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/trunk/trac/trac/util/tests/introspection.py?rev=1301696&view=auto
==============================================================================
--- incubator/bloodhound/trunk/trac/trac/util/tests/introspection.py (added)
+++ incubator/bloodhound/trunk/trac/trac/util/tests/introspection.py Fri Mar 16 18:52:52 2012
@@ -0,0 +1,47 @@
+
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing,
+#  software distributed under the License is distributed on an
+#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#  KIND, either express or implied.  See the License for the
+#  specific language governing permissions and limitations
+#  under the License.
+
+import unittest
+from trac.util.subclasses import subclasses
+
+class BaseClass(object):
+    """Common base class for tests"""
+class SubClass(BaseClass):
+    """Common sub class of BaseClass for tests"""
+
+class SubClassTestCase(unittest.TestCase):
+    def test_discover_subclass(self):
+        subs = list(subclasses(BaseClass))
+        self.assertEqual(len(subs), 1)
+        self.assertIs(subs[0], SubClass)
+
+    def test_discover_subsubclass(self):
+        class SubSubClass(SubClass):
+            """Sub class of SubClass"""
+        subs = list(subclasses(BaseClass))
+        self.assertEqual(len(subs), 2)
+        self.assertIn(SubClass, subs)
+        self.assertIn(SubSubClass, subs)
+
+def suite():
+    suite = unittest.TestSuite()
+    suite.addTest(unittest.makeSuite(SubClassTestCase, 'test'))
+    return suite
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='suite')

Propchange: incubator/bloodhound/trunk/trac/trac/util/tests/introspection.py
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message