Author: rjollos
Date: Sun Feb  2 12:02:20 2014
New Revision: 1563593

URL: http://svn.apache.org/r1563593
Log:
0.8dev: PEP-0008 changes.

Modified:
    bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/__init__.py
    bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/test_report.py
    bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/test_webui.py
    bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/widgets/__init__.py
    bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/widgets/timeline.py
    bloodhound/trunk/bloodhound_dashboard/setup.py

Modified: bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/__init__.py
URL: 
http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/__init__.py?rev=1563593&r1=1563592&r2=1563593&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/__init__.py 
(original)
+++ bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/__init__.py Sun Feb 
 2 12:02:20 2014
@@ -1,3 +1,4 @@
+# -*- coding: UTF-8 -*-
 
 #  Licensed to the Apache Software Foundation (ASF) under one
 #  or more contributor license agreements.  See the NOTICE file
@@ -16,19 +17,14 @@
 #  specific language governing permissions and limitations
 #  under the License.
 
-r"""Test artifacts.
-
-The test suites have been run using Trac=0.11.1 , Trac=0.11.5 , Trac=0.11.7
-"""
-
 __metaclass__ = type
 
 import sys
 
+import trac.test
 from trac.core import ComponentMeta
 from trac.db.api import _parse_db_str, DatabaseManager
 from trac.mimeview.api import Context
-from trac.test import EnvironmentStub
 from trac.util.compat import set
 
 from bhdashboard.util import trac_version, trac_tags
@@ -37,80 +33,80 @@ from bhdashboard.util import trac_versio
 #    Trac environments used for testing purposes
 #------------------------------------------------------
 
-class EnvironmentStub(EnvironmentStub):
-  r"""Enhanced stub of the trac.env.Environment object for testing.
-  """
-
-  # Dont break lazy evaluation. Otherwise RPC calls misteriously fail.
-  @property
-  def _abs_href(self):
-    return self.abs_href
-
-  def enable_component(self, clsdef):
-    r"""Enable a plugin temporarily at testing time.
+class EnvironmentStub(trac.test.EnvironmentStub):
+    r"""Enhanced stub of the trac.env.Environment object for testing.
     """
-    if trac_version < trac_tags[0]:
-      # `enabled_components` should be enough in this case
-      if clsdef not in self.enabled_components :
-        self.enabled_components.append(clsdef)
-    else:
-      # Use environment configuration otherwise
-      raise NotImplementedError("TODO: Enable components in Trac>=0.13")
 
-  def disable_component(self, clsdef):
-    r"""Disable a plugin temporarily at testing time.
-    """
-    if trac_version < trac_tags[0]:
-      try:
-        self.enabled_components.remove(clsdef)
-      except ValueError :
-        self.log.warning("Component %s was not enabled", clsdef)
-    else:
-      # Use environment configuration otherwise
-      raise NotImplementedError("TODO: Disable components in Trac>=0.13")
+    # Dont break lazy evaluation. Otherwise RPC calls misteriously fail.
+    @property
+    def _abs_href(self):
+        return self.abs_href
 
-  def rip_component(self, cls):
-    r"""Disable a plugin forever and RIP it using the super-laser beam.
-    """
-    self.disable_component(cls)
-    for reg in ComponentMeta._registry.itervalues():
-      try:
-        reg.remove(cls)
-      except ValueError :
-        pass
-
-  if not hasattr(EnvironmentStub, 'reset_db'):
-
-    # Copycat trac.test.EnvironmentStub.reset_db (Trac=0.11.5)
-    def reset_db(self, default_data=None):
-        r"""Remove all data from Trac tables, keeping the tables themselves.
-        :param default_data: after clean-up, initialize with default data
-        :return: True upon success
+    def enable_component(self, clsdef):
+        r"""Enable a plugin temporarily at testing time.
         """
-        from trac import db_default
-
-        db = self.get_db_cnx()
-        db.rollback() # make sure there's no transaction in progress
-        cursor = db.cursor()
+        if trac_version < trac_tags[0]:
+            # `enabled_components` should be enough in this case
+            if clsdef not in self.enabled_components:
+                self.enabled_components.append(clsdef)
+        else:
+            # Use environment configuration otherwise
+            raise NotImplementedError("TODO: Enable components in Trac>=0.13")
 
-        defdata = list(db_default.get_data(db))
+    def disable_component(self, clsdef):
+        r"""Disable a plugin temporarily at testing time.
+        """
+        if trac_version < trac_tags[0]:
+            try:
+                self.enabled_components.remove(clsdef)
+            except ValueError:
+                self.log.warning("Component %s was not enabled", clsdef)
+        else:
+            # Use environment configuration otherwise
+            raise NotImplementedError("TODO: Disable components in Trac>=0.13")
 
-        for table, cols, vals in defdata:
-            cursor.execute("DELETE FROM %s" % (table,) )
+    def rip_component(self, cls):
+        r"""Disable a plugin forever and RIP it using the super-laser beam.
+        """
+        self.disable_component(cls)
+        for reg in ComponentMeta._registry.itervalues():
+            try:
+                reg.remove(cls)
+            except ValueError:
+                pass
+
+    if not hasattr(trac.test.EnvironmentStub, 'reset_db'):
+
+        # Copycat trac.test.EnvironmentStub.reset_db (Trac=0.11.5)
+        def reset_db(self, default_data=None):
+            r"""Remove all data from Trac tables, keeping the tables 
themselves.
+            :param default_data: after clean-up, initialize with default data
+            :return: True upon success
+            """
+            from trac import db_default
+
+            db = self.get_db_cnx()
+            db.rollback() # make sure there's no transaction in progress
+            cursor = db.cursor()
 
-        db.commit()
+            defdata = list(db_default.get_data(db))
 
-        if default_data:
             for table, cols, vals in defdata:
-                cursor.executemany("INSERT INTO %s (%s) VALUES (%s)"
-                                   % (table, ','.join(cols),
-                                      ','.join(['%s' for c in cols])),
-                                   vals)
-        else:
-            cursor.execute("INSERT INTO system (name, value) "
-                           "VALUES (%s, %s)",
-                           ('database_version', str(db_default.db_version)))
-        db.commit()
+                cursor.execute("DELETE FROM %s" % (table,))
+
+            db.commit()
+
+            if default_data:
+                for table, cols, vals in defdata:
+                    cursor.executemany("INSERT INTO %s (%s) VALUES (%s)"
+                                       % (table, ','.join(cols),
+                                          ','.join(['%s' for c in cols])),
+                                       vals)
+            else:
+                cursor.execute("INSERT INTO system (name, value) "
+                               "VALUES (%s, %s)",
+                               ('database_version', 
str(db_default.db_version)))
+            db.commit()
 
 #------------------------------------------------------
 #    Minimalistic testing framework for Trac
@@ -125,165 +121,169 @@ from bhdashboard.util import dummy_reque
 # Hide this module from tracebacks written into test results.
 __unittest = True
 
+
 class DocTestTracLoader(DocTestLoader):
-  r"""A generic XUnit loader that allows to load doctests written 
-  to check that Trac plugins behave as expected.
-  """
-  def set_env(self, env):
-    if self.extraglobs is None :
-      self.extraglobs = dict(env=env)
-    else :
-      self.extraglobs['env'] = env
-
-  env = property(lambda self : self.extraglobs.get('env'), set_env, \
-                  doc="""The Trac environment used in doctests.""")
-  del set_env
-
-  def __init__(self, dt_finder=None, globs=None, extraglobs=None, \
-                          load=None, default_data=False, enable=None, \
-                          disable=None, **opts):
-    r"""Initialization. It basically works like `DocTestLoader`'s 
-    initializer but creates also the Trac environment used for 
-    testing purposes. The default behavior is to create an instance 
-    of `EnvironmentStub` class. Subclasses can add more specific 
-    keyword parameters in order to use them to create the 
-    environment. Next it loads (and | or) enables the components 
-    needed by the test suite.
-
-    The following variables are magically available at testing time. 
-    They can be used directly in doctests :
-
-    - req         A dummy request object setup for anonymous access.
-    - auth_req    A dummy request object setup like if user `murphy` was  
-                  accessing the site.
-    - env         the Trac environment used as a stub for testing 
-                  purposes (i.e. `self.env`).
-
-    @param dt_finder        see docs for `DocTestLoader.__init__` 
-                            method.
-    @param globs            see docs for `DocTestLoader.__init__` 
-                            method.
-    @param extraglobs       see docs for `DocTestLoader.__init__` 
-                            method.
-    @param load             a list of packages containing components 
-                            that will be loaded to ensure they are 
-                            available at testing time. It should be 
-                            the top level module in that package 
-                            (e.g. 'trac').
-    @param default_data     If true, populate the database with some 
-                            defaults. This parameter has to be 
-                            handled by `createTracEnv` method.
-    @param enable           a list of UNIX patterns specifying which 
-                            components need to be enabled by default 
-                            at testing time. This parameter should be 
-                            handled by `createTracEnv` method.
-    @param disable          a list of UNIX patterns specifying which 
-                            components need to be disabled by default 
-                            at testing time. Ignored in Trac<=0.11 .
-                            This parameter should be 
-                            handled by `createTracEnv` method.
-    """
-    super(DocTestTracLoader, self).__init__(dt_finder, globs, \
-                                              extraglobs, **opts)
-    if trac_version >= trac_tags[0]:
-        opts['disable'] = disable
-    self.env = self.createTracEnv(default_data, enable, **opts)
-    self.load_components(load is None and self.default_packages or load)
-
-  # Load trac built-in components by default
-  default_packages = ['trac']
-
-  def createTracEnv(self, default_data=False, enable=None, 
-      disable=None, **params):
-    r"""Create the Trac environment used for testing purposes. The 
-    default behavior is to create an instance of `EnvironmentStub` 
-    class. Subclasses can override this decision and add more specific 
-    keyword parameters in order to control environment creation in 
-    more detail. 
-
-    All parameters supplied at initialization time. By default they 
-    are ignored.
-    @param default_data     If True, populate the database with some 
-                            defaults.
-    @param enable           a list of UNIX patterns specifying which 
-                            components need to be enabled by default 
-                            at testing time.
-    @param disable          a list of UNIX patterns specifying which 
-                            components need to be disabled by default 
-                            at testing time. Ignored in Trac<0.13
-    @return                 the environment used for testing purpose.
-    """
-    if trac_version >= trac_tags[0]:
-      kwargs = {'disable' : disable}
-    else :
-      kwargs = {}
-    return EnvironmentStub(default_data, enable, **kwargs)
-
-  def load_components(self, pkgs):
-    r"""Load some packages to ensure that the components they 
-    implement are available at testing time.
-    """
-    from trac.loader import load_components
-    for pkg in pkgs :
-      try :
-        __import__(pkg)
-      except ImportError :
-        pass                        # Skip pkg. What a shame !
-      else :
-        mdl = sys.modules[pkg]
-        load_components(self.env, dirname(dirname(mdl.__file__)))
-
-  class doctestSuiteClass(DocTestSuiteFixture):
-    r"""Prepare the global namespace before running all doctests 
-    in the suite. Reset the Trac environment.
+    r"""A generic XUnit loader that allows to load doctests written
+    to check that Trac plugins behave as expected.
     """
-    username = 'murphy'
 
-    @property
-    def env(self):
-      r"""The Trac environment involved in this test. It is 
-      retrieved using the global namespace ;o).
-      """
-      return self.globalns['env']
-
-    def new_request(self, uname=None, args=None):
-      r"""Create and initialize a new request object.
-      """
-      req = dummy_request(self.env, uname)
-      if args is not None :
-        req.args = args
-      return req
-
-    def setUp(self):
-      r"""Include two (i.e. `req` anonymous and `auth_req` 
-      authenticated) request objects in the global namespace, before 
-      running the doctests. Besides, clean up environment data and 
-      include only default data.
-      """
-      from pprint import pprint
-      from trac.core import ComponentMeta
-
-      globs = self.globalns
-      req = self.new_request(args=dict())
-      auth_req = self.new_request(uname=self.username, args=dict())
-      globs['req'] = req
-      globs['auth_req'] = auth_req
-      # TODO: If the source docstrings belong to a Trac component, 
-      #       then instantiate it and include in the global 
-      #       namespace.
-
-      # Delete data in Trac tables
-      from trac import db_default
-      db = self.env.get_db_cnx()
-      cursor = db.cursor()
-      for table in db_default.schema:
-        if trac_version < trac_tags[0]: # FIXME: Should it be (0, 12) ?
-            cursor.execute("DELETE FROM " + table.name)
+    def set_env(self, env):
+        if self.extraglobs is None:
+            self.extraglobs = dict(env=env)
+        else:
+            self.extraglobs['env'] = env
+
+    env = property(lambda self: self.extraglobs.get('env'), set_env, \
+                   doc="""The Trac environment used in doctests.""")
+    del set_env
+
+    def __init__(self, dt_finder=None, globs=None, extraglobs=None, \
+                 load=None, default_data=False, enable=None, \
+                 disable=None, **opts):
+        r"""Initialization. It basically works like `DocTestLoader`'s
+        initializer but creates also the Trac environment used for
+        testing purposes. The default behavior is to create an instance
+        of `EnvironmentStub` class. Subclasses can add more specific
+        keyword parameters in order to use them to create the
+        environment. Next it loads (and | or) enables the components
+        needed by the test suite.
+
+        The following variables are magically available at testing time.
+        They can be used directly in doctests :
+
+        - req         A dummy request object setup for anonymous access.
+        - auth_req    A dummy request object setup like if user `murphy` was
+                      accessing the site.
+        - env         the Trac environment used as a stub for testing
+                      purposes (i.e. `self.env`).
+
+        @param dt_finder        see docs for `DocTestLoader.__init__`
+                                method.
+        @param globs            see docs for `DocTestLoader.__init__`
+                                method.
+        @param extraglobs       see docs for `DocTestLoader.__init__`
+                                method.
+        @param load             a list of packages containing components
+                                that will be loaded to ensure they are
+                                available at testing time. It should be
+                                the top level module in that package
+                                (e.g. 'trac').
+        @param default_data     If true, populate the database with some
+                                defaults. This parameter has to be
+                                handled by `createTracEnv` method.
+        @param enable           a list of UNIX patterns specifying which
+                                components need to be enabled by default
+                                at testing time. This parameter should be
+                                handled by `createTracEnv` method.
+        @param disable          a list of UNIX patterns specifying which
+                                components need to be disabled by default
+                                at testing time. Ignored in Trac<=0.11 .
+                                This parameter should be
+                                handled by `createTracEnv` method.
+        """
+        super(DocTestTracLoader, self).__init__(dt_finder, globs, \
+                                                extraglobs, **opts)
+        if trac_version >= trac_tags[0]:
+            opts['disable'] = disable
+        self.env = self.createTracEnv(default_data, enable, **opts)
+        self.load_components(load is None and self.default_packages or load)
+
+    # Load trac built-in components by default
+    default_packages = ['trac']
+
+    def createTracEnv(self, default_data=False, enable=None,
+                      disable=None, **params):
+        r"""Create the Trac environment used for testing purposes. The
+        default behavior is to create an instance of `EnvironmentStub`
+        class. Subclasses can override this decision and add more specific
+        keyword parameters in order to control environment creation in
+        more detail.
+
+        All parameters supplied at initialization time. By default they
+        are ignored.
+        @param default_data     If True, populate the database with some
+                                defaults.
+        @param enable           a list of UNIX patterns specifying which
+                                components need to be enabled by default
+                                at testing time.
+        @param disable          a list of UNIX patterns specifying which
+                                components need to be disabled by default
+                                at testing time. Ignored in Trac<0.13
+        @return                 the environment used for testing purpose.
+        """
+        if trac_version >= trac_tags[0]:
+            kwargs = {'disable': disable}
         else:
-            cursor.execute("DROP TABLE " + table.name)
-      db.commit()
+            kwargs = {}
+        return EnvironmentStub(default_data, enable, **kwargs)
+
+    def load_components(self, pkgs):
+        r"""Load some packages to ensure that the components they
+        implement are available at testing time.
+        """
+        from trac.loader import load_components
+
+        for pkg in pkgs:
+            try:
+                __import__(pkg)
+            except ImportError:
+                pass                        # Skip pkg. What a shame !
+            else:
+                mdl = sys.modules[pkg]
+                load_components(self.env, dirname(dirname(mdl.__file__)))
+
+    class doctestSuiteClass(DocTestSuiteFixture):
+        r"""Prepare the global namespace before running all doctests
+        in the suite. Reset the Trac environment.
+        """
+        username = 'murphy'
 
-      self.env.reset_db(default_data=True)
+        @property
+        def env(self):
+            r"""The Trac environment involved in this test. It is
+            retrieved using the global namespace ;o).
+            """
+            return self.globalns['env']
+
+        def new_request(self, uname=None, args=None):
+            r"""Create and initialize a new request object.
+            """
+            req = dummy_request(self.env, uname)
+            if args is not None:
+                req.args = args
+            return req
+
+        def setUp(self):
+            r"""Include two (i.e. `req` anonymous and `auth_req`
+            authenticated) request objects in the global namespace, before
+            running the doctests. Besides, clean up environment data and
+            include only default data.
+            """
+            from pprint import pprint
+            from trac.core import ComponentMeta
+
+            globs = self.globalns
+            req = self.new_request(args=dict())
+            auth_req = self.new_request(uname=self.username, args=dict())
+            globs['req'] = req
+            globs['auth_req'] = auth_req
+            # TODO: If the source docstrings belong to a Trac component,
+            #       then instantiate it and include in the global
+            #       namespace.
+
+            # Delete data in Trac tables
+            from trac import db_default
+
+            db = self.env.get_db_cnx()
+            cursor = db.cursor()
+            for table in db_default.schema:
+                if trac_version < trac_tags[0]: # FIXME: Should it be (0, 12) ?
+                    cursor.execute("DELETE FROM " + table.name)
+                else:
+                    cursor.execute("DROP TABLE " + table.name)
+            db.commit()
+
+            self.env.reset_db(default_data=True)
 
 #------------------------------------------------------
 #    Test artifacts used to test widget providers
@@ -291,97 +291,101 @@ class DocTestTracLoader(DocTestLoader):
 
 from bhdashboard.api import InvalidIdentifier
 
+
 class DocTestWidgetLoader(DocTestTracLoader):
-  r"""Load doctests used to test Trac RPC handlers.
-  """
-  class doctestSuiteClass(DocTestTracLoader.doctestSuiteClass):
-    r"""Include the appropriate RPC handler in global namespace 
-    before running all test cases in the suite.
+    r"""Load doctests used to test Trac RPC handlers.
     """
 
-    def ns_from_name(self):
-      r"""Extract the target namespace under test using the name
-      of the DocTest instance manipulated by the suite.
-      """
-      try :
-        return self._dt.name.split(':', 1)[0].split('|', 1)[-1]
-      except :
-        return None
-
-    def partial_setup(self):
-      r"""Perform partial setup due to some minor failure (e.g. 
-      namespace missing in test name).
-      """
-      globs = self.globalns
-      globs['widget'] = globs['ctx'] = globs['auth_ctx'] = None
-
-    def setup_widget(self, widgetns):
-      r"""(Insert | update) the IWidgetProvider in the global 
-      namespace.
-
-      @param widgetns             widget name.
-      @throws RuntimeError        if a widget with requested name cannot 
-                                  be found.
-      """
-      globs = self.globalns
-      globs['ctx'] = Context.from_request(globs['req'])
-      globs['auth_ctx'] = Context.from_request(globs['auth_req'])
-      for wp in self.dbsys.providers :
-        if widgetns in set(wp.get_widgets()) :
-          globs['widget'] = wp
-          break
-      else :
-        raise InvalidIdentifier('Cannot load widget provider for %s' % 
widgetns)
-
-    def setUp(self):
-      r"""Include the appropriate widget provider in global namespace 
-      before running all test cases in the suite. In this case three
-      objects are added to the global namespace :
-
-        - `widget`       the component implementing the widget under test
-        - `ctx`          context used to render the widget for 
-                         anonymous user
-        - `auth_ctx`     context used to render the widget for 
-                         authenticated user
-      """
-      # Fail here if BloodhoundDashboardPlugin is not available. Thus 
-      # this fact will be reported as a failure and subsequent test 
-      # cases will be run anyway.
-      from bhdashboard.api import DashboardSystem
-      self.dbsys = DashboardSystem(self.env)
-
-      # Add request objects
-      DocTestTracLoader.doctestSuiteClass.setUp(self)
-
-      widgetns = self.ns_from_name()
-      if widgetns is None :
-        # TODO: If doctests belong to a widget provider class then 
-        #       instantiate it. In the mean time ...
-        self.partial_setup()
-      else :
-        try :
-          self.setup_widget(widgetns)
-        except InvalidIdentifier:
-          self.partial_setup()
+    class doctestSuiteClass(DocTestTracLoader.doctestSuiteClass):
+        r"""Include the appropriate RPC handler in global namespace
+        before running all test cases in the suite.
+        """
 
-  # Load trac built-in components and RPC handlers by default
-  default_packages = ['trac']
+        def ns_from_name(self):
+            r"""Extract the target namespace under test using the name
+            of the DocTest instance manipulated by the suite.
+            """
+            try:
+                return self._dt.name.split(':', 1)[0].split('|', 1)[-1]
+            except:
+                return None
+
+        def partial_setup(self):
+            r"""Perform partial setup due to some minor failure (e.g.
+            namespace missing in test name).
+            """
+            globs = self.globalns
+            globs['widget'] = globs['ctx'] = globs['auth_ctx'] = None
+
+        def setup_widget(self, widgetns):
+            r"""(Insert | update) the IWidgetProvider in the global
+            namespace.
+
+            @param widgetns             widget name.
+            @throws RuntimeError        if a widget with requested name cannot
+                                        be found.
+            """
+            globs = self.globalns
+            globs['ctx'] = Context.from_request(globs['req'])
+            globs['auth_ctx'] = Context.from_request(globs['auth_req'])
+            for wp in self.dbsys.providers:
+                if widgetns in set(wp.get_widgets()):
+                    globs['widget'] = wp
+                    break
+            else:
+                raise InvalidIdentifier(
+                    'Cannot load widget provider for %s' % widgetns)
+
+        def setUp(self):
+            r"""Include the appropriate widget provider in global namespace
+            before running all test cases in the suite. In this case three
+            objects are added to the global namespace :
+
+              - `widget`       the component implementing the widget under test
+              - `ctx`          context used to render the widget for
+                               anonymous user
+              - `auth_ctx`     context used to render the widget for
+                               authenticated user
+            """
+            # Fail here if BloodhoundDashboardPlugin is not available. Thus
+            # this fact will be reported as a failure and subsequent test
+            # cases will be run anyway.
+            from bhdashboard.api import DashboardSystem
+
+            self.dbsys = DashboardSystem(self.env)
+
+            # Add request objects
+            DocTestTracLoader.doctestSuiteClass.setUp(self)
+
+            widgetns = self.ns_from_name()
+            if widgetns is None:
+                # TODO: If doctests belong to a widget provider class then
+                #       instantiate it. In the mean time ...
+                self.partial_setup()
+            else:
+                try:
+                    self.setup_widget(widgetns)
+                except InvalidIdentifier:
+                    self.partial_setup()
+
+    # Load trac built-in components and RPC handlers by default
+    default_packages = ['trac']
 
 #------------------------------------------------------
 #    Helper functions used in test cases
 #------------------------------------------------------
 
 def clear_perm_cache(_env, _req):
-  r"""Ensure that cache policies will not prevent test cases from 
-  altering user permissions right away.
-  """
-  from trac.perm import PermissionSystem, DefaultPermissionPolicy
-
-  _req.perm._cache.clear()            # Clear permission cache
-  for policy in PermissionSystem(_env).policies :
-    if isinstance(policy, DefaultPermissionPolicy):
-      policy.permission_cache.clear() # Clear policy cache
-      break
+    r"""Ensure that cache policies will not prevent test cases from
+    altering user permissions right away.
+    """
+    from trac.perm import PermissionSystem, DefaultPermissionPolicy
+
+    _req.perm._cache.clear()            # Clear permission cache
+    for policy in PermissionSystem(_env).policies:
+        if isinstance(policy, DefaultPermissionPolicy):
+            policy.permission_cache.clear() # Clear policy cache
+            break
 
 #------------------------------------------------------
 #    Global test data
@@ -390,23 +394,23 @@ def clear_perm_cache(_env, _req):
 from ConfigParser import RawConfigParser
 from pkg_resources import resource_stream
 
+
 def load_test_data(key):
-  r"""Load data used for testing purposes. Currently such data is 
-  stored in .INI files inside `data` directory.
+    r"""Load data used for testing purposes. Currently such data is
+    stored in .INI files inside `data` directory.
 
-  @param key          currently the path to the file containing the 
-                      data, relative to `data` folder. 
-  """
-  fo = resource_stream(__name__, 'data/%s.ini' % key)
-  try :
-    p = RawConfigParser()
-    p.readfp(fo)
-    for section in p.sections():
-      yield section, dict(p.items(section))
-  finally :
-    fo.close()
+    @param key          currently the path to the file containing the
+                        data, relative to `data` folder.
+    """
+    fo = resource_stream(__name__, 'data/%s.ini' % key)
+    try:
+        p = RawConfigParser()
+        p.readfp(fo)
+        for section in p.sections():
+            yield section, dict(p.items(section))
+    finally:
+        fo.close()
 
 # The set of tickets used by test cases.
 ticket_data = [(attrs.pop('summary'), attrs.pop('description'), attrs) \
-                for _, attrs in sorted(load_test_data('ticket_data'))]
-
+               for _, attrs in sorted(load_test_data('ticket_data'))]

Modified: bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/test_report.py
URL: 
http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/test_report.py?rev=1563593&r1=1563592&r2=1563593&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/test_report.py 
(original)
+++ bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/test_report.py Sun 
Feb  2 12:02:20 2014
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 # -*- coding: UTF-8 -*-
 
 #  Licensed to the Apache Software Foundation (ASF) under one
@@ -55,35 +54,37 @@ the test name be written like `|widget_n
 #    Test artifacts
 #------------------------------------------------------
 
-from bhdashboard.tests import trac_version, trac_tags
+import sys
+
+from bhdashboard.tests import trac_version
+
 
 def test_suite():
-  from doctest import NORMALIZE_WHITESPACE, ELLIPSIS, REPORT_UDIFF
-  from dutest import MultiTestLoader
-  from unittest import defaultTestLoader
-
-  from bhdashboard.tests import DocTestWidgetLoader, ticket_data
-
-  magic_vars = dict(ticket_data=ticket_data)
-  if trac_version < (0, 13): # FIXME: Should it be (0, 12) ?
-    kwargs = {'enable': ['trac.[a-uw-z]*', 'tracrpc.*', 'bhdashboard.*']}
-  else:
-    kwargs = {
+    from doctest import NORMALIZE_WHITESPACE, ELLIPSIS, REPORT_UDIFF
+    from dutest import MultiTestLoader
+    from unittest import defaultTestLoader
+
+    from bhdashboard.tests import DocTestWidgetLoader, ticket_data
+
+    magic_vars = dict(ticket_data=ticket_data)
+    if trac_version < (0, 13):  # FIXME: Should it be (0, 12) ?
+        kwargs = {'enable': ['trac.[a-uw-z]*', 'tracrpc.*', 'bhdashboard.*']}
+    else:
+        kwargs = {
             'enable': ['trac.*', 'tracrpc.*', 'bhdashboard.*'],
             'disable': ['trac.versioncontrol.*']
         }
 
-  l = MultiTestLoader(
-        [defaultTestLoader, \
-          DocTestWidgetLoader(extraglobs=magic_vars, \
-                            default_data=True, \
-                            optionflags=ELLIPSIS | REPORT_UDIFF | \
-                                        NORMALIZE_WHITESPACE, \
-                            **kwargs) \
+    l = MultiTestLoader(
+        [defaultTestLoader,
+         DocTestWidgetLoader(extraglobs=magic_vars,
+                             default_data=True,
+                             optionflags=ELLIPSIS | REPORT_UDIFF |
+                                         NORMALIZE_WHITESPACE,
+                             **kwargs)
         ])
 
-  import sys
-  return l.loadTestsFromModule(sys.modules[__name__])
+    return l.loadTestsFromModule(sys.modules[__name__])
 
 #------------------------------------------------------
 #    Helper functions
@@ -95,53 +96,59 @@ from pprint import pprint
 
 from bhdashboard.tests import clear_perm_cache
 
+
 def print_report_metadata(report_desc):
-  for attrnm in ('id', 'title', 'description', 'query'):
-    print attrnm.capitalize()
-    print '-' * len(attrnm)
-    print report_desc[attrnm]
+    for attrnm in ('id', 'title', 'description', 'query'):
+        print attrnm.capitalize()
+        print '-' * len(attrnm)
+        print report_desc[attrnm]
+
 
 def print_report_columns(cols):
-  for coldsc in cols:
-    print 'Column:', coldsc[0], 'Type:', coldsc[1] or '_', \
-          'Label:', 
-    try :
-      print coldsc[2] or '_'
-    except IndexError :
-      print '_'
+    for coldsc in cols:
+        print 'Column:', coldsc[0], 'Type:', coldsc[1] or '_', \
+            'Label:',
+        try:
+            print coldsc[2] or '_'
+        except IndexError:
+            print '_'
+
 
 def print_report_result(cols, data):
-  for i, row in enumerate(data):
-    print '= Row', i, '='
-    for coldsc in cols:
-      colnm = coldsc[0]
-      print 'Column:', colnm, 'Value:', row.get(colnm) or None, ''
+    for i, row in enumerate(data):
+        print '= Row', i, '='
+        for coldsc in cols:
+            colnm = coldsc[0]
+            print 'Column:', colnm, 'Value:', row.get(colnm) or None, ''
+
 
-TICKET_ATTRS = ('summary', 'description', 'priority', \
-                'milestone', 'type', 'owner', 'status', \
+TICKET_ATTRS = ('summary', 'description', 'priority',
+                'milestone', 'type', 'owner', 'status',
                 'component', 'version')
 
-def prepare_ticket_workflow(tcktrpc, ticket_data, auth_req):
-  r"""Set ticket status considering the actions defined in standard 
-  ticket workflow. Needed for TracRpc>=1.0.6
-  """
-  from time import sleep
-
-  TICKET_ACTIONS = {'accepted': 'accept', 'closed' : 'resolve',
-                    'assigned': 'reassign'}
-  sleep(1)
-  for idx, (_, __, td) in enumerate(ticket_data) :
-    action = TICKET_ACTIONS.get(td.get('status'))
-    if action is not None :
-      aux_attrs = {'action' : action}
-      aux_attrs.update(td)
-      tcktrpc.update(auth_req, idx + 1, "", aux_attrs)
-  sleep(1)
-  for idx, (_, __, td) in enumerate(ticket_data) :
-    tcktrpc.update(auth_req, idx + 1, "", td)
+
+def prepare_ticket_workflow(tktrpc, ticket_data, auth_req):
+    r"""Set ticket status considering the actions defined in standard
+    ticket workflow. Needed for TracRpc>=1.0.6
+    """
+    from time import sleep
+
+    TICKET_ACTIONS = {'accepted': 'accept', 'closed': 'resolve',
+                      'assigned': 'reassign'}
+    sleep(1)
+    for idx, (_, __, td) in enumerate(ticket_data):
+        action = TICKET_ACTIONS.get(td.get('status'))
+        if action is not None:
+            aux_attrs = {'action': action}
+            aux_attrs.update(td)
+            tktrpc.update(auth_req, idx + 1, "", aux_attrs)
+    sleep(1)
+    for idx, (_, __, td) in enumerate(ticket_data):
+        tktrpc.update(auth_req, idx + 1, "", td)
+
 
 __test__ = {
-    'Initialization: Report widgets' : r"""
+    'Initialization: Report widgets': r"""
       >>> from trac.core import ComponentMeta
       >>> from bhdashboard.api import IWidgetProvider
       >>> from bhdashboard.widgets.report import *
@@ -149,7 +156,7 @@ __test__ = {
       >>> [wpcls in allcls for wpcls in (TicketReportWidget,)]
       [True]
       """,
-    '|TicketReport: Metadata' : r"""
+    '|TicketReport: Metadata': r"""
       >>> list(widget.get_widgets())
       ['TicketReport']
       >>> params = widget.get_widget_params('TicketReport')
@@ -162,7 +169,7 @@ __test__ = {
                   'type': <type 'int'>},
        'user': {'desc': 'Render the report for a given user.'}}
       """,
-    '|TicketReport: Render My Tickets report' : r"""
+    '|TicketReport: Render My Tickets report': r"""
 
       Add tickets
 
@@ -630,7 +637,7 @@ __test__ = {
       ...     )
       ...
       """,
-    '|TicketReport: Render a subset of My Tickets report' : r"""
+    '|TicketReport: Render a subset of My Tickets report': r"""
 
       Add tickets
 
@@ -998,7 +1005,7 @@ __test__ = {
        'title': <Element "a">},
        <...Context <Resource u'report:7'>>)
       """,
-    '|TicketReport: Invalid widget name' : r"""
+    '|TicketReport: Invalid widget name': r"""
       >>> widget.render_widget('OlkswSk', ctx, {
       ...     'args' : {'id' : 1, 'limit' : 8}
       ...   })
@@ -1007,7 +1014,7 @@ __test__ = {
         ...
       InvalidIdentifier: Widget name MUST match any of TicketReport
       """,
-    '|TicketReport: Invalid report ID in arguments' : r"""
+    '|TicketReport: Invalid report ID in arguments': r"""
       >>> widget.render_widget('TicketReport', ctx, {
       ...     'args' : {'id' : 99999}
       ...   })
@@ -1016,7 +1023,7 @@ __test__ = {
         ...
       InvalidIdentifier: Report 99999 does not exist.
       """,
-    '|TicketReport: Missing required arguments' : r"""
+    '|TicketReport: Missing required arguments': r"""
       >>> widget.render_widget('TicketReport', ctx, {
       ...     'args' : {}
       ...   })
@@ -1033,7 +1040,7 @@ __test__ = {
         ...
       InvalidWidgetArgument: Invalid argument `id`. Required parameter expected
       """,
-    '|TicketReport: Invalid widget parameter' : r"""
+    '|TicketReport: Invalid widget parameter': r"""
 
       Add tickets
 
@@ -1401,8 +1408,7 @@ __test__ = {
         'title': <Element "a">},
        <...Context <Resource u'report:7'>>)
       """,
-    '|TicketReport: Invalid report definition' : r"""
+    '|TicketReport: Invalid report definition': r"""
       >>> raise NotImplementedError()
       """,
-  }
-
+}

Modified: bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/test_webui.py
URL: 
http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/test_webui.py?rev=1563593&r1=1563592&r2=1563593&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/test_webui.py 
(original)
+++ bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/test_webui.py Sun 
Feb  2 12:02:20 2014
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 # -*- coding: UTF-8 -*-
 
 #  Licensed to the Apache Software Foundation (ASF) under one
@@ -52,35 +51,37 @@ the test name be written like `|widget_n
 #    Test artifacts
 #------------------------------------------------------
 
+import sys
+
 from bhdashboard.tests import trac_version, trac_tags
 
+
 def test_suite():
-  from doctest import NORMALIZE_WHITESPACE, ELLIPSIS, REPORT_UDIFF
-  from dutest import MultiTestLoader
-  from unittest import defaultTestLoader
-
-  from bhdashboard.tests import DocTestTracLoader, ticket_data
-
-  magic_vars = dict(ticket_data=ticket_data)
-  if trac_version < (0, 13): # FIXME: Should it be (0, 12) ?
-    kwargs = {'enable': ['trac.[a-uw-z]*', 'tracrpc.*', 'bhdashboard.*']}
-  else:
-    kwargs = {
+    from doctest import NORMALIZE_WHITESPACE, ELLIPSIS, REPORT_UDIFF
+    from dutest import MultiTestLoader
+    from unittest import defaultTestLoader
+
+    from bhdashboard.tests import DocTestTracLoader, ticket_data
+
+    magic_vars = dict(ticket_data=ticket_data)
+    if trac_version < (0, 13):  # FIXME: Should it be (0, 12) ?
+        kwargs = {'enable': ['trac.[a-uw-z]*', 'tracrpc.*', 'bhdashboard.*']}
+    else:
+        kwargs = {
             'enable': ['trac.*', 'tracrpc.*', 'bhdashboard.*'],
             'disable': ['trac.versioncontrol.*']
         }
 
-  l = MultiTestLoader(
-        [defaultTestLoader, \
-          DocTestTracLoader(extraglobs=magic_vars, \
-                            default_data=True, \
-                            optionflags=ELLIPSIS | REPORT_UDIFF | \
-                                        NORMALIZE_WHITESPACE, \
-                            **kwargs) \
+    l = MultiTestLoader(
+        [defaultTestLoader,
+         DocTestTracLoader(extraglobs=magic_vars,
+                           default_data=True,
+                           optionflags=ELLIPSIS | REPORT_UDIFF |
+                                       NORMALIZE_WHITESPACE,
+                           **kwargs)
         ])
 
-  import sys
-  return l.loadTestsFromModule(sys.modules[__name__])
+    return l.loadTestsFromModule(sys.modules[__name__])
 
 #------------------------------------------------------
 #    Helper functions
@@ -92,24 +93,25 @@ from pprint import pprint
 
 from bhdashboard.tests import clear_perm_cache
 
+
 def prepare_ticket_workflow(tcktrpc, ticket_data, auth_req):
-  r"""Set ticket status considering the actions defined in standard 
-  ticket workflow. Needed for TracRpc>=1.0.6
-  """
-  from time import sleep
-
-  TICKET_ACTIONS = {'accepted': 'accept', 'closed' : 'resolve',
-                    'assigned': 'reassign'}
-  sleep(1)
-  for idx, (_, __, td) in enumerate(ticket_data) :
-    action = TICKET_ACTIONS.get(td.get('status'))
-    if action is not None :
-      aux_attrs = {'action' : action}
-      aux_attrs.update(td)
-      tcktrpc.update(auth_req, idx + 1, "", aux_attrs)
-  sleep(1)
-  for idx, (_, __, td) in enumerate(ticket_data) :
-    tcktrpc.update(auth_req, idx + 1, "", td)
+    r"""Set ticket status considering the actions defined in standard
+    ticket workflow. Needed for TracRpc>=1.0.6
+    """
+    from time import sleep
+
+    TICKET_ACTIONS = {'accepted': 'accept', 'closed': 'resolve',
+                      'assigned': 'reassign'}
+    sleep(1)
+    for idx, (_, __, td) in enumerate(ticket_data):
+        action = TICKET_ACTIONS.get(td.get('status'))
+        if action is not None:
+            aux_attrs = {'action': action}
+            aux_attrs.update(td)
+            tcktrpc.update(auth_req, idx + 1, "", aux_attrs)
+    sleep(1)
+    for idx, (_, __, td) in enumerate(ticket_data):
+        tcktrpc.update(auth_req, idx + 1, "", td)
 
 from bhdashboard.web_ui import DashboardModule
 
@@ -127,5 +129,4 @@ __test__ = {
       [{'content': <genshi.core.Stream object at ...>, 
       'title': <Element "a">}]
       """,
-  }
-
+}

Modified: 
bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/widgets/__init__.py
URL: 
http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/widgets/__init__.py?rev=1563593&r1=1563592&r2=1563593&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/widgets/__init__.py 
(original)
+++ bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/widgets/__init__.py 
Sun Feb  2 12:02:20 2014
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 # -*- coding: UTF-8 -*-
 
 #  Licensed to the Apache Software Foundation (ASF) under one

Modified: 
bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/widgets/timeline.py
URL: 
http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/widgets/timeline.py?rev=1563593&r1=1563592&r2=1563593&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/widgets/timeline.py 
(original)
+++ bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/widgets/timeline.py 
Sun Feb  2 12:02:20 2014
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 # -*- coding: UTF-8 -*-
 
 #  Licensed to the Apache Software Foundation (ASF) under one
@@ -17,7 +16,9 @@
 #  KIND, either express or implied.  See the License for the
 #  specific language governing permissions and limitations
 #  under the License.
+
 import unittest
+
 from bhdashboard.widgets.timeline import TicketFieldTimelineFilter
 from trac.test import EnvironmentStub, Mock
 from trac.ticket import Ticket
@@ -28,7 +29,7 @@ class TicketFieldTimelineFilterTests(uni
         self.env = EnvironmentStub()
         t1 = self._insert_and_load_ticket("foo")
         self.filter = TicketFieldTimelineFilter(self.env)
-        self.context = context = Mock(resource=t1.resource)
+        self.context = Mock(resource=t1.resource)
 
     def tearDown(self):
         self.env.reset_db()

Modified: bloodhound/trunk/bloodhound_dashboard/setup.py
URL: 
http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_dashboard/setup.py?rev=1563593&r1=1563592&r2=1563593&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_dashboard/setup.py (original)
+++ bloodhound/trunk/bloodhound_dashboard/setup.py Sun Feb  2 12:02:20 2014
@@ -149,4 +149,3 @@ setup(
     classifiers = cats,
     long_description= DESC
     )
-


Reply via email to