incubator-bloodhound-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1449046 - in /incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct: multiproduct/config.py multiproduct/env.py tests/wiki/formatter.py
Date Fri, 22 Feb 2013 14:02:25 GMT
Author: jure
Date: Fri Feb 22 14:02:25 2013
New Revision: 1449046

URL: http://svn.apache.org/r1449046
Log:
#355, wiki formatters test cases, patch t355_r1446579_trac_test_wiki_formatter.diff applied
(from Olemis)


Added:
    incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/tests/wiki/formatter.py
Modified:
    incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/config.py
    incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/env.py

Modified: incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/config.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/config.py?rev=1449046&r1=1449045&r2=1449046&view=diff
==============================================================================
--- incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/config.py
(original)
+++ incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/config.py
Fri Feb 22 14:02:25 2013
@@ -141,6 +141,10 @@ class Section(Section):
     """
     __slots__ = ['config', 'name', 'overridden', '_cache']
 
+    @staticmethod
+    def optionxform(optionstr):
+        return to_unicode(optionstr.lower());
+
     def __init__(self, config, name):
         self.config = config
         self.name = to_unicode(name)
@@ -156,7 +160,7 @@ class Section(Section):
         return self.config.product
 
     def contains(self, key, defaults=True):
-        key = to_unicode(key)
+        key = self.optionxform(key)
         if ProductSetting.exists(self.env, self.product, self.name, key):
             return True
         for parent in self.config.parents:
@@ -176,18 +180,19 @@ class Section(Section):
         name_str = self.name
         for setting in ProductSetting.select(self.env,
                 where={'product':self.product, 'section':name_str}):
-            option = to_unicode(setting.option)
-            options.add(option.lower())
+            option = self.optionxform(setting.option)
+            options.add(option)
             yield option
         for parent in self.config.parents:
             for option in parent[self.name].iterate(defaults=False):
-                loption = option.lower()
+                loption = self.optionxform(option)
                 if loption not in options:
                     options.add(loption)
                     yield option
         if defaults:
             for section, option in Option.get_registry(compmgr).keys():
-                if section == self.name and option.lower() not in options:
+                if section == self.name and \
+                        self.optionxform(option) not in options:
                     yield option
 
     __iter__ = iterate
@@ -201,6 +206,7 @@ class Section(Section):
 
         Valid default input is a string. Returns a string.
         """
+        key = self.optionxform(key)
         cached = self._cache.get(key, _use_default)
         if cached is not _use_default:
             return cached
@@ -252,7 +258,7 @@ class Section(Section):
 
         Like for `set()`, the changes won't persist until `save()` gets called.
         """
-        key_str = to_unicode(key)
+        key_str = self.optionxform(key)
         option_key = {
                 'product' : self.product, 
                 'section' : self.name,
@@ -272,7 +278,7 @@ class Section(Section):
 
         These changes will be persistent right away.
         """
-        key_str = to_unicode(key)
+        key_str = self.optionxform(key)
         value_str = to_unicode(value)
         self._cache.pop(key_str, None)
         option_key = {

Modified: incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/env.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/env.py?rev=1449046&r1=1449045&r2=1449046&view=diff
==============================================================================
--- incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/env.py
(original)
+++ incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/env.py
Fri Feb 22 14:02:25 2013
@@ -605,14 +605,14 @@ class ProductEnvironment(Component, Comp
         # FIXME: True or False ?
         return True
 
-    @property
+    @lazy
     def href(self):
         """The application root path"""
         if not self._href:
             self._href = Href(urlsplit(self.abs_href.base)[2])
         return self._href
 
-    @property
+    @lazy
     def abs_href(self):
         """The application URL"""
         if not self._abs_href:

Added: incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/tests/wiki/formatter.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/tests/wiki/formatter.py?rev=1449046&view=auto
==============================================================================
--- incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/tests/wiki/formatter.py
(added)
+++ incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/tests/wiki/formatter.py
Fri Feb 22 14:02:25 2013
@@ -0,0 +1,135 @@
+
+#  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.
+
+"""Tests for Apache(TM) Bloodhound's wiki formatters in product environments"""
+
+import os.path
+import re
+import unittest
+
+from trac.wiki.tests import formatter
+
+from multiproduct.env import ProductEnvironment
+from tests.env import MultiproductTestCase
+
+class ProductWikiTestCase(formatter.WikiTestCase, MultiproductTestCase):
+
+    maxDiff = None
+
+    @property
+    def env(self):
+        env = getattr(self, '_env', None)
+        if env is None:
+            all_test_components = [
+                    formatter.HelloWorldMacro, formatter.DivHelloWorldMacro, 
+                    formatter.TableHelloWorldMacro, formatter.DivCodeMacro, 
+                    formatter.DivCodeElementMacro, formatter.DivCodeStreamMacro,
+                    formatter.NoneMacro, formatter.WikiProcessorSampleMacro, 
+                    formatter.SampleResolver]
+            self.global_env = self._setup_test_env(
+                    enable=['trac.*', 'multiproduct.*'] + all_test_components
+                )
+            self._upgrade_mp(self.global_env)
+            self._load_product_from_data(self.global_env, self.default_product)
+            self._env = env = ProductEnvironment(
+                    self.global_env, self.default_product)
+        return env
+
+    @env.setter
+    def env(self, value):
+        pass
+
+    def setUp(self):
+        self._setup_test_log(self.global_env)
+        formatter.WikiTestCase.setUp(self)
+
+    def tearDown(self):
+        self.global_env.reset_db()
+        self.global_env = self._env = None
+
+    def __init__(self, title, input, correct, file, line, setup=None,
+                 teardown=None, context=None):
+        MultiproductTestCase.__init__(self, 'test')
+        formatter.WikiTestCase.__init__(self, title, input, correct, file, line, 
+                setup, teardown, context)
+
+class ProductOneLinerTestCase(ProductWikiTestCase):
+    formatter = formatter.OneLinerTestCase.formatter.im_func
+
+class ProductEscapeNewLinesTestCase(ProductWikiTestCase):
+    generate_opts = formatter.EscapeNewLinesTestCase.generate_opts 
+    formatter = formatter.EscapeNewLinesTestCase.formatter.im_func
+
+class ProductOutlineTestCase(ProductWikiTestCase):
+    formatter = formatter.OutlineTestCase.formatter.im_func
+
+
+def test_suite(data=None, setup=None, file=formatter.__file__, 
+        teardown=None, context=None):
+    suite = unittest.TestSuite()
+    def add_test_cases(data, filename):
+        tests = re.compile('^(%s.*)$' % ('=' * 30), re.MULTILINE).split(data)
+        next_line = 1
+        line = 0
+        for title, test in zip(tests[1::2], tests[2::2]):
+            title = title.lstrip('=').strip()
+            if line != next_line:
+                line = next_line
+            if not test or test == '\n':
+                continue
+            next_line += len(test.split('\n')) - 1
+            if 'SKIP' in title or 'WONTFIX' in title:
+                continue
+            blocks = test.split('-' * 30 + '\n')
+            if len(blocks) < 5:
+                blocks.extend([None,] * (5 - len(blocks)))
+            input, page, oneliner, page_escape_nl, outline = blocks[:5]
+            if page:
+                page = ProductWikiTestCase(
+                    title, input, page, filename, line, setup,
+                    teardown, context)
+            if oneliner:
+                oneliner = ProductOneLinerTestCase(
+                    title, input, oneliner[:-1], filename, line, setup,
+                    teardown, context)
+            if page_escape_nl:
+                page_escape_nl = ProductEscapeNewLinesTestCase(
+                    title, input, page_escape_nl, filename, line, setup,
+                    teardown, context)
+            if outline:
+                outline = ProductOutlineTestCase(
+                    title, input, outline, filename, line, setup,
+                    teardown, context)
+            for tc in [page, oneliner, page_escape_nl, outline]:
+                if tc:
+                    suite.addTest(tc)
+    if data:
+        add_test_cases(data, file)
+    else:
+        for f in ('wiki-tests.txt', 'wikicreole-tests.txt'):
+            testfile = os.path.join(os.path.split(file)[0], f)
+            if os.path.exists(testfile):
+                data = open(testfile, 'r').read().decode('utf-8')
+                add_test_cases(data, testfile)
+            else:
+                print 'no ', testfile
+    return suite
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')
+



Mime
View raw message