[Zope3-checkins] CVS: Packages/ZConfig/tests - test_schema.py:1.1.2.37

Fred L. Drake, Jr. fred@zope.com
Fri, 3 Jan 2003 00:50:45 -0500


Update of /cvs-repository/Packages/ZConfig/tests
In directory cvs.zope.org:/tmp/cvs-serv21242/tests

Modified Files:
      Tag: zconfig-schema-devel-branch
	test_schema.py 
Log Message:
Add the methods getSectionName() and getSectionType() to SectionValue.
Disallow attribute names starting with "getSection" in the schema so there
is some reserved namespace for future expansion of the set of method for
accessing section metadata.


=== Packages/ZConfig/tests/test_schema.py 1.1.2.36 => 1.1.2.37 ===
--- Packages/ZConfig/tests/test_schema.py:1.1.2.36	Fri Jan  3 00:23:04 2003
+++ Packages/ZConfig/tests/test_schema.py	Fri Jan  3 00:50:42 2003
@@ -331,15 +331,17 @@
                                      "<t2>\n k2 value2\n </t2>\n")
         eq = self.assertEqual
         eq(len(conf.g), 4)
-        self.assert_(conf.g[0].__type__ is t1)
-        self.assert_(conf.g[1].__type__ is t1)
-        self.assert_(conf.g[2].__type__ is t2)
-        self.assert_(conf.g[3].__type__ is t2)
         eq(conf.g[0].k1, "default1")
         eq(conf.g[1].k1, "value1")
         eq(conf.g[2].k2, "default2")
         eq(conf.g[3].k2, "value2")
 
+        # white box:
+        self.assert_(conf.g[0]._type is t1)
+        self.assert_(conf.g[1]._type is t1)
+        self.assert_(conf.g[2]._type is t2)
+        self.assert_(conf.g[3]._type is t2)
+
     def test_arbitrary_key(self):
         schema = self.load_schema_text(
             "<schema>"
@@ -443,7 +445,7 @@
             "</schema>")
         conf = self.load_config_text(schema, "<sect name/>")
         self.assertEqual(conf.attr.key, "value")
-        self.assertEqual(conf.attr.__name__, "name")
+        self.assertEqual(conf.attr.getSectionName(), "name")
 
         # if we omit the name, it's an error
         self.assertRaises(ZConfig.ConfigurationError,
@@ -461,6 +463,25 @@
             "  <section type='abstract' name='*' attribute='s2'/>"
             "</schema>")
         conf = self.load_config_text(schema, "<t2>\n <t1 s1/>\n</t2>")
+
+    def test_reserved_attribute_prefix(self):
+        template = ("<schema>\n"
+                    "  <sectiontype type='s'/>\n"
+                    "  %s\n"
+                    "</schema>")
+        def check(thing, self=self, template=template):
+            text = template % thing
+            self.assertRaises(ZConfig.SchemaError,
+                              self.load_schema_text, text)
+
+        check("<key name='a' attribute='getSection'/>")
+        check("<key name='a' attribute='getSectionThing'/>")
+        check("<multikey name='a' attribute='getSection'/>")
+        check("<multikey name='a' attribute='getSectionThing'/>")
+        check("<section type='s' name='*' attribute='getSection'/>")
+        check("<section type='s' name='*' attribute='getSectionThing'/>")
+        check("<multisection type='s' name='*' attribute='getSection'/>")
+        check("<multisection type='s' name='*' attribute='getSectionThing'/>")
 
 
 def test_suite():