[Zope3-checkins] CVS: Zope/lib/python/ZConfig/tests - testConfig.py:1.1.4.8 testSchema.py:1.1.2.12 testSubstitution.py:1.3.6.2

Fred L. Drake, Jr. fred@zope.com
Fri, 6 Dec 2002 11:06:26 -0500


Update of /cvs-repository/Zope/lib/python/ZConfig/tests
In directory cvs.zope.org:/tmp/cvs-serv7113/ZConfig/tests

Modified Files:
      Tag: chrism-install-branch
	testConfig.py testSchema.py testSubstitution.py 
Log Message:
Merge ZConfig trunk into the chrism-install-branch.

=== Zope/lib/python/ZConfig/tests/testConfig.py 1.1.4.7 => 1.1.4.8 ===
--- Zope/lib/python/ZConfig/tests/testConfig.py:1.1.4.7	Tue Nov 26 18:52:34 2002
+++ Zope/lib/python/ZConfig/tests/testConfig.py	Fri Dec  6 11:06:23 2002
@@ -23,8 +23,6 @@
 import ZConfig
 
 from ZConfig.Context import Context
-from ZConfig.Common import ConfigurationError, ConfigurationTypeError
-from ZConfig.Common import ConfigurationMissingSectionError
 
 try:
     __file__
@@ -50,6 +48,10 @@
         self.assert_(conf.delegate is None)
         return conf
 
+    def loadtext(self, text):
+        sio = StringIO.StringIO(text)
+        return ZConfig.loadfile(sio)
+
     def check_simple_gets(self, conf):
         self.assertEqual(conf.get('empty'), '')
         self.assertEqual(conf.getint('int-var'), 12)
@@ -133,7 +135,7 @@
 
     def test_missing_named_section(self):
         conf = self.load("simplesections.conf")
-        self.assertRaises(ConfigurationMissingSectionError,
+        self.assertRaises(ZConfig.ConfigurationMissingSectionError,
                           conf.getSection, "section", "does-not-exist")
 
     def test_keys(self):
@@ -219,7 +221,7 @@
     def test_no_delegation(self):
         url = urlparse.urljoin(CONFIG_BASE, "simplesections.conf")
         context = NoDelegationContext()
-        self.assertRaises(ConfigurationTypeError, context.load, url)
+        self.assertRaises(ZConfig.ConfigurationTypeError, context.load, url)
 
     def test_include(self):
         conf = self.load("include.conf")
@@ -230,8 +232,24 @@
         self.assertEqual(conf.get("var3"), "value3")
         self.assertEqual(conf.get("VAR3"), "value3")
 
+    def test_define(self):
+        conf = self.load("simple.conf")
+        self.assertEqual(conf.get("getname"), "value")
+        self.assertEqual(conf.get("getnametwice"), "valuevalue")
+        self.assertEqual(conf.get("getdollars"), "$$")
+        self.assertEqual(conf.get("getempty"), "xy")
+        self.assertEqual(conf.get("getwords"), "abc two words def")
+
+    def test_define_errors(self):
+        self.assertRaises(ZConfig.ConfigurationSyntaxError,
+                          self.loadtext, "%define\n")
+        self.assertRaises(ZConfig.ConfigurationSyntaxError,
+                          self.loadtext, "%define abc-def\n")
+        self.assertRaises(ZConfig.ConfigurationSyntaxError,
+                          self.loadtext, "%define a value\n%define a value\n")
+
     def test_fragment_ident_disallowed(self):
-        self.assertRaises(ConfigurationError,
+        self.assertRaises(ZConfig.ConfigurationError,
                           self.load, "simplesections.conf#another")
 
     def test_load_from_abspath(self):


=== Zope/lib/python/ZConfig/tests/testSchema.py 1.1.2.11 => 1.1.2.12 ===
--- Zope/lib/python/ZConfig/tests/testSchema.py:1.1.2.11	Tue Nov 26 18:52:34 2002
+++ Zope/lib/python/ZConfig/tests/testSchema.py	Fri Dec  6 11:06:23 2002
@@ -28,7 +28,7 @@
 from ZConfig.SchemaParser import ConfigRoot, ConfigKey, ConfigSection,\
      ConfigMultiSection, ConfigMultiKey, ConfigFreeformSection
 
-from ZConfig.Common import ConfigurationError, ConfigurationTypeError
+from ZConfig import ConfigurationError, ConfigurationTypeError
 
 try:
     __file__


=== Zope/lib/python/ZConfig/tests/testSubstitution.py 1.3.6.1 => 1.3.6.2 ===
--- Zope/lib/python/ZConfig/tests/testSubstitution.py:1.3.6.1	Fri Nov 15 20:26:18 2002
+++ Zope/lib/python/ZConfig/tests/testSubstitution.py	Fri Dec  6 11:06:23 2002
@@ -5,17 +5,8 @@
 
 import unittest
 
-from UserDict import UserDict
-
-from ZConfig.Substitution import get, substitute
-from ZConfig.Substitution import SubstitutionRecursionError
-from ZConfig.Substitution import SubstitutionSyntaxError
-
-
-class ContainerDict(UserDict):
-    def __init__(self, mapping=None, container=None):
-        self.container = container
-        UserDict.__init__(self, mapping)
+from ZConfig import SubstitutionReplacementError, SubstitutionSyntaxError
+from ZConfig.Substitution import isname, substitute
 
 
 class SubstitutionTestCase(unittest.TestCase):
@@ -44,12 +35,15 @@
 
     def test_undefined_names(self):
         d = {"name": "value"}
-        self.assertEqual(substitute("$splat", d), "")
-        self.assertEqual(substitute("$splat1", d), "")
-        self.assertEqual(substitute("$splat_", d), "")
+        self.assertRaises(SubstitutionReplacementError,
+                          substitute, "$splat", d)
+        self.assertRaises(SubstitutionReplacementError,
+                          substitute, "$splat1", d)
+        self.assertRaises(SubstitutionReplacementError,
+                          substitute, "$splat_", d)
 
     def test_syntax_errors(self):
-        d = {"name": "value"}
+        d = {"name": "${next"}
         def check(s):
             self.assertRaises(SubstitutionSyntaxError,
                               substitute, s, d)
@@ -62,7 +56,8 @@
         # It's debatable what should happen for these cases, so we'll
         # follow the lead of the Bourne shell here.
         def check(s):
-            self.assertEqual(substitute(s, {}), s)
+            self.assertRaises(SubstitutionSyntaxError,
+                              substitute, s, {})
         check("$1")
         check("$")
         check("$ stuff")
@@ -71,34 +66,15 @@
         d = {"name": "$value"}
         self.assertEqual(substitute("$name", d), "$value")
 
-    def test_simple_nesting(self):
-        d = {"name": "value",
-             "nest": "$splat",
-             "splat": "nested"}
-        def check(name, value):
-            self.assertEqual(get(d, name), value)
-        check("name", "value")
-        check("nest", "nested")
-
-    def test_nesting_errors(self):
-        d = {"name": "$splat",
-             "splat": "$name"}
-        self.assertRaises(SubstitutionRecursionError,
-                          get, d, "name")
-        d = {"name": "$splat",
-             "splat": "$splat"}
-        self.assertRaises(SubstitutionRecursionError,
-                          get, d, "name")
-
-    def test_container_search(self):
-        d1 = {"outer": "outervalue",
-              "inner": "inner-from-outer"}
-        d2 = ContainerDict({"inner": "inner-from-inner",
-                            "bogus": "${nothere}",
-                            "both": "${inner} ${outer}"}, d1)
-        self.assertEqual(get(d2, "both"),
-                         "inner-from-inner outervalue")
-        self.assertEqual(get(d2, "bogus"), "")
+    def test_isname(self):
+        self.assert_(isname("abc"))
+        self.assert_(isname("abc_def"))
+        self.assert_(isname("_abc"))
+        self.assert_(isname("abc_"))
+        self.assert_(not isname("abc-def"))
+        self.assert_(not isname("-def"))
+        self.assert_(not isname("abc-"))
+        self.assert_(not isname(""))
 
 
 def test_suite():