[Zconfig] SVN: ZConfig/trunk/ Fixed support for schema descriptions that override descriptions from a base

Fred L. Drake, Jr. fdrake at gmail.com
Fri Dec 5 14:29:46 EST 2008


Log message for revision 93689:
  Fixed support for schema descriptions that override descriptions from a base
  schema.  If multiple base schema provide descriptions but the derived schema
  does not, the first base mentioned that provides a description wins.
  
  https://bugs.launchpad.net/zconfig/+bug/259475
  

Changed:
  U   ZConfig/trunk/NEWS.txt
  U   ZConfig/trunk/ZConfig/schema.py
  U   ZConfig/trunk/ZConfig/tests/input/base.xml
  U   ZConfig/trunk/ZConfig/tests/test_schema.py

-=-
Modified: ZConfig/trunk/NEWS.txt
===================================================================
--- ZConfig/trunk/NEWS.txt	2008-12-05 19:27:50 UTC (rev 93688)
+++ ZConfig/trunk/NEWS.txt	2008-12-05 19:29:46 UTC (rev 93689)
@@ -5,6 +5,11 @@
 ZConfig 2.6.1 (2008/12/05)
 --------------------------
 
+- Fixed support for schema descriptions that override descriptions from a base
+  schema.  If multiple base schema provide descriptions but the derived schema
+  does not, the first base mentioned that provides a description wins.
+  https://bugs.launchpad.net/zconfig/+bug/259475
+
 - Fixed compatibility bug with Python 2.5.0.
 
 - No longer trigger deprecation warnings under Python 2.6.

Modified: ZConfig/trunk/ZConfig/schema.py
===================================================================
--- ZConfig/trunk/ZConfig/schema.py	2008-12-05 19:27:50 UTC (rev 93688)
+++ ZConfig/trunk/ZConfig/schema.py	2008-12-05 19:29:46 UTC (rev 93689)
@@ -468,6 +468,7 @@
         self._extending_parser = extending_parser
         self._base_keytypes = []
         self._base_datatypes = []
+        self._descriptions = []
 
     def start_schema(self, attrs):
         self.push_prefix(attrs)
@@ -524,7 +525,6 @@
             self._extending_parser._base_keytypes.append(keytype)
             self._extending_parser._base_datatypes.append(datatype)
 
-
     def extendSchema(self, src):
         parser = SchemaParser(self._loader, src, self)
         r = self._loader.openResource(src)
@@ -538,6 +538,16 @@
         assert not self._stack
         self.pop_prefix()
         assert not self._prefixes
+        schema = self._schema
+        if self._extending_parser is None:
+            # Top-level schema:
+            if self._descriptions and not schema.description:
+                # Use the last one, since the base schemas are processed in
+                # reverse order.
+                schema.description = self._descriptions[-1]
+        elif schema.description:
+            self._extending_parser._descriptions.append(schema.description)
+            schema.description = None
 
 
 class ComponentParser(BaseParser):

Modified: ZConfig/trunk/ZConfig/tests/input/base.xml
===================================================================
--- ZConfig/trunk/ZConfig/tests/input/base.xml	2008-12-05 19:27:50 UTC (rev 93688)
+++ ZConfig/trunk/ZConfig/tests/input/base.xml	2008-12-05 19:29:46 UTC (rev 93689)
@@ -1,3 +1,7 @@
 <schema>
+  <description>
+    <!-- This description is referenced from a test. -->
+    base description
+  </description>
   <sectiontype name="type-X"/>
 </schema>

Modified: ZConfig/trunk/ZConfig/tests/test_schema.py
===================================================================
--- ZConfig/trunk/ZConfig/tests/test_schema.py	2008-12-05 19:27:50 UTC (rev 93688)
+++ ZConfig/trunk/ZConfig/tests/test_schema.py	2008-12-05 19:29:46 UTC (rev 93689)
@@ -1013,6 +1013,29 @@
                           self.load_schema_text,
             "<schema extends='%s/library.xml#foo'/>" % CONFIG_BASE)
 
+    def test_extends_description_override(self):
+        schema = self.load_schema_text("""\
+           <schema extends='%s/base.xml %s/library.xml'>
+             <description>
+               overriding description
+             </description>
+             <section name='A' type='type-a' />
+             <section name='X' type='type-X' />
+           </schema>
+           """ % (CONFIG_BASE, CONFIG_BASE))
+        description = schema.description.strip()
+        self.assertEqual(description, "overriding description")
+
+    def test_extends_description_first_extended_wins(self):
+        schema = self.load_schema_text("""\
+           <schema extends='%s/base.xml %s/library.xml'>
+             <section name='A' type='type-a' />
+             <section name='X' type='type-X' />
+           </schema>
+           """ % (CONFIG_BASE, CONFIG_BASE))
+        description = schema.description.strip()
+        self.assertEqual(description, "base description")
+
     def test_multi_extends_implicit_OK(self):
         self.load_schema_text("""\
            <schema extends='%s/base.xml %s/library.xml'>



More information about the ZConfig mailing list