[Zope3-checkins] CVS: Packages/ZConfig/tests - testSubstitution.py:1.7

Fred L. Drake, Jr. fred@zope.com
Wed, 4 Dec 2002 17:48:32 -0500


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

Modified Files:
	testSubstitution.py 
Log Message:
Clean out a bunch of the ZConfig.Substitution module that is no longer
useful now that %define and substitution is built into the basic handling
of the configuration files.


=== Packages/ZConfig/tests/testSubstitution.py 1.6 => 1.7 ===
--- Packages/ZConfig/tests/testSubstitution.py:1.6	Wed Dec  4 15:59:14 2002
+++ Packages/ZConfig/tests/testSubstitution.py	Wed Dec  4 17:48:31 2002
@@ -5,18 +5,7 @@
 
 import unittest
 
-from types import StringType
-from UserDict import UserDict
-
-from ZConfig.Substitution import get, getnames, isname, 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.Substitution import isname, substitute, SubstitutionSyntaxError
 
 
 class SubstitutionTestCase(unittest.TestCase):
@@ -52,16 +41,13 @@
     def test_syntax_errors(self):
         d = {"name": "${next"}
         def check(s):
-            self.check_error_context(SubstitutionSyntaxError, None,
-                                     substitute, s, d)
+            self.assertRaises(SubstitutionSyntaxError,
+                              substitute, s, d)
         check("${")
         check("${name")
         check("${1name}")
         check("${ name}")
 
-        self.check_error_context(SubstitutionSyntaxError, ["name"],
-                                 get, d, "name")
-
     def test_edge_cases(self):
         # It's debatable what should happen for these cases, so we'll
         # follow the lead of the Bourne shell here.
@@ -74,66 +60,6 @@
     def test_non_nesting(self):
         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.check_error_context(SubstitutionRecursionError, ["name", "splat"],
-                                 get, d, "name")
-        d = {"name": "$splat",
-             "splat": "$splat"}
-        self.check_error_context(SubstitutionRecursionError, ["name", "splat"],
-                                 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 check_error_context(self, exc, context, callable, *args, **kw):
-        try:
-            callable(*args, **kw)
-        except exc, e:
-            self.assertEqual(e.context, context)
-        else:
-            if isinstance(exc, StringType):
-                name = `exc`
-            elif exc.module == "exceptions":
-                # Built-in exceptions
-                name = exc.__name__
-            else:
-                name = exc.__module__ + "." + exc.__name__
-            self.fail("expected exception " + name)
-
-    def test_getnames(self):
-        self.assertEqual(getnames(""), [])
-        self.assertEqual(getnames("abc"), [])
-        self.assertEqual(getnames("$"), [])
-        self.assertEqual(getnames("$$"), [])
-        self.assertEqual(getnames("$abc"), ["abc"])
-        self.assertEqual(getnames("$abc$abc"), ["abc"])
-        self.assertEqual(getnames("$abc$def"), ["abc", "def"])
-        self.assertEqual(getnames("${abc}${def}"), ["abc", "def"])
-        self.assertEqual(getnames("$abc xyz${def}pqr$def"), ["abc", "def"])
-        self.assertEqual(getnames("$ABC xyz${def}pqr$DEF"), ["abc", "def"])
-        self.assertRaises(SubstitutionSyntaxError, getnames, "${")
-        self.assertRaises(SubstitutionSyntaxError, getnames, "${name")
-        self.assertRaises(SubstitutionSyntaxError, getnames, "${1name}")
-        self.assertRaises(SubstitutionSyntaxError, getnames, "${ name}")
 
     def test_isname(self):
         self.assert_(isname("abc"))