Commits

Olemis Lang  committed 63b905b

BH Multiproduct #115 : Setup inheritance with files listed in 'file' option in 'inherit' section ... (failures=1, errors=2)

Ran 27 tests in 2.457s

  • Participants
  • Parent commits e54fbf0
  • Branches t115_product_env

Comments (0)

Files changed (2)

File t115/t115_r1423431_product_envs_testing.diff

 # HG changeset patch
-# Parent 101ff51010dce6bbb4e2edd2764772d9f3753681
+# Parent c6fafb51b2b92507642309cd9dee8a3978fa4873
 BH Theme #115 : Test cases for product environments
 
-diff -r 101ff51010dc bloodhound_multiproduct/tests/config.py
+diff -r c6fafb51b2b9 bloodhound_multiproduct/tests/config.py
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-+++ b/bloodhound_multiproduct/tests/config.py	Mon Jan 07 01:38:36 2013 -0500
-@@ -0,0 +1,99 @@
++++ b/bloodhound_multiproduct/tests/config.py	Tue Jan 08 00:26:52 2013 -0500
+@@ -0,0 +1,124 @@
 +
 +#  Licensed to the Apache Software Foundation (ASF) under one
 +#  or more contributor license agreements.  See the NOTICE file
 +
 +from ConfigParser import ConfigParser
 +import os.path
++import shutil
 +from StringIO import StringIO
 +import unittest
 +
 +
 +        # Dummy config file, a sibling of trac.ini
 +        self.filename = os.path.join(self.env.path, 'conf', 'product.ini')
++        # Ensure conf sub-folder is created
++        os.mkdir(os.path.dirname(self.filename))
 +
 +        self._upgrade_mp(self.env)
 +        self._setup_test_log(self.env)
 +
 +    def tearDown(self):
 +        Option.registry = self._orig_registry
++        shutil.rmtree(self.env.path)
 +        self.env = None
 +
 +    def _read(self, parents=None, product=None):
 +                    setting._data['value'] = to_unicode(value)
 +                    setting.insert()
 +
++    def _test_with_inherit(self, testcb):
++        """Almost exact copy of `trac.tests.config.ConfigurationTestCase`.
++        Differences explained in inline comments.
++        """
++        # Parent configuration file created in environment's conf sub-folder
++        # PS: This modification would not be necessary if the corresponding
++        #     statement in overriden method would be written the same way
++        #     but the fact that both files have the same parent folder
++        #     is not made obvious in there
++        sitename = os.path.join(os.path.dirname(self.filename), 'trac-site.ini')
++
++        try:
++            with open(sitename, 'w') as sitefile:
++                sitefile.write('[a]\noption = x\n')
++
++            self._write(['[inherit]', 'file = trac-site.ini'])
++            testcb()
++        finally:
++            os.remove(sitename)
++
++
 +def suite():
 +    return unittest.makeSuite(ProductConfigTestCase,'test')
 +
 +if __name__ == '__main__':
 +    unittest.main(defaultTest='suite')
 +
-diff -r 101ff51010dc bloodhound_multiproduct/tests/env.py
+diff -r c6fafb51b2b9 bloodhound_multiproduct/tests/env.py
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-+++ b/bloodhound_multiproduct/tests/env.py	Mon Jan 07 01:38:36 2013 -0500
++++ b/bloodhound_multiproduct/tests/env.py	Tue Jan 08 00:26:52 2013 -0500
 @@ -0,0 +1,139 @@
 +
 +#  Licensed to the Apache Software Foundation (ASF) under one
 +
 +    def _setup_test_env(self, create_folder=True, path=None):
 +        r"""Prepare a new test environment . 
-+        
++
 +        Optionally set its path to a meaningful location (temp folder
 +        if `path` is `None`).
 +        """

File t115/t115_r1427886_product_config.diff

 
 diff -r beed3d3bb95c bloodhound_dashboard/bhdashboard/model.py
 --- a/bloodhound_dashboard/bhdashboard/model.py	Mon Jan 07 13:44:27 2013 -0500
-+++ b/bloodhound_dashboard/bhdashboard/model.py	Mon Jan 07 22:58:47 2013 -0500
++++ b/bloodhound_dashboard/bhdashboard/model.py	Tue Jan 08 00:27:16 2013 -0500
 @@ -117,8 +117,9 @@
                  self._update_from_row(row)
                  break
              data = dict([(fields[i], row[i]) for i in range(len(fields))])
 diff -r beed3d3bb95c bloodhound_multiproduct/multiproduct/api.py
 --- a/bloodhound_multiproduct/multiproduct/api.py	Mon Jan 07 13:44:27 2013 -0500
-+++ b/bloodhound_multiproduct/multiproduct/api.py	Mon Jan 07 22:58:47 2013 -0500
++++ b/bloodhound_multiproduct/multiproduct/api.py	Tue Jan 08 00:27:16 2013 -0500
 @@ -31,9 +31,9 @@
  from trac.util.translation import _, N_
  from trac.web.chrome import ITemplateProvider
      def get_version(self):
 diff -r beed3d3bb95c bloodhound_multiproduct/multiproduct/config.py
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-+++ b/bloodhound_multiproduct/multiproduct/config.py	Mon Jan 07 22:58:47 2013 -0500
-@@ -0,0 +1,291 @@
++++ b/bloodhound_multiproduct/multiproduct/config.py	Tue Jan 08 00:27:16 2013 -0500
+@@ -0,0 +1,311 @@
 +
 +#  Licensed to the Apache Software Foundation (ASF) under one
 +#  or more contributor license agreements.  See the NOTICE file
 +        be added to parents list.
 +        """
 +        self.env = env
-+        self.parents = (parents or [])
 +        self.product = to_unicode(product)
 +        self._sections = {}
++        self._setup_parents(parents)
 +
 +    def __getitem__(self, name):
 +        """Return the configuration section with the specified name.
 +                        value = None
 +                    self.set(section, name, value)
 +
++    # Helper methods
++
++    def _setup_parents(self, parents=None):
++        """Inherit configuration from parent `Configuration` instances.
++        If there's a value set to 'file' option in 'inherit' section then
++        it will be considered as a list of paths to .ini files
++        that will be added to parents list as well.
++        """
++        from trac import config
++        self.parents = (parents or [])
++        for filename in self.get('inherit', 'file').split(','):
++            filename = Section._normalize_path(filename, self.env)
++            self.parents.append(config.Configuration(filename))
++
 +class Section(Section):
 +    """Proxy for a specific configuration section.
 +
 +        path = self.get(key, default)
 +        if not path:
 +            return default
-+        if not os.path.isabs(path):
-+            path = os.path.join(self.env.path, 'conf', path)
-+        return os.path.normcase(os.path.realpath(path))
++        return self._normalize_path(path, self.env)
 +
 +    def remove(self, key):
 +        """Delete a key from this section.
 +                setting.value = value
 +                setting.update()
 +
++    # Helper methods
++
++    @staticmethod
++    def _normalize_path(path, env):
++        if not os.path.isabs(path):
++            path = os.path.join(env.path, 'conf', path)
++        return os.path.normcase(os.path.realpath(path))
++
 diff -r beed3d3bb95c bloodhound_multiproduct/multiproduct/model.py
 --- a/bloodhound_multiproduct/multiproduct/model.py	Mon Jan 07 13:44:27 2013 -0500
-+++ b/bloodhound_multiproduct/multiproduct/model.py	Mon Jan 07 22:58:47 2013 -0500
++++ b/bloodhound_multiproduct/multiproduct/model.py	Tue Jan 08 00:27:16 2013 -0500
 @@ -18,6 +18,7 @@
  
  """Models to support multi-product"""