[Zodb-checkins] CVS: Packages/ZConfig/tests - testSubstitution.py:1.2

Fred L. Drake, Jr. fred@zope.com
Thu, 7 Nov 2002 13:54:40 -0500


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

Modified Files:
	testSubstitution.py 
Log Message:
During substitution, names are looked up from the container of a section if
they are not present in the section itself.


=== Packages/ZConfig/tests/testSubstitution.py 1.1 => 1.2 ===
--- Packages/ZConfig/tests/testSubstitution.py:1.1	Thu Nov  7 10:29:14 2002
+++ Packages/ZConfig/tests/testSubstitution.py	Thu Nov  7 13:54:39 2002
@@ -5,11 +5,19 @@
 
 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)
+
+
 class SubstitutionTestCase(unittest.TestCase):
     def test_simple_names(self):
         d = {"name": "value",
@@ -81,6 +89,16 @@
              "splat": "$splat"}
         self.assertRaises(SubstitutionRecursionError,
                           get, d, "name")
+
+    def test_container_search(self):
+        d1 = ContainerDict({"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_suite():