[Zope3-checkins] CVS: Zope/lib/python/ZConfig/tests - testConfig.py:1.1.4.5

Chris McDonough chrism@zope.com
Sun, 24 Nov 2002 18:28:46 -0500


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

Modified Files:
      Tag: chrism-install-branch
	testConfig.py 
Log Message:
Merge with head.


=== Zope/lib/python/ZConfig/tests/testConfig.py 1.1.4.4 => 1.1.4.5 ===
--- Zope/lib/python/ZConfig/tests/testConfig.py:1.1.4.4	Fri Nov 15 20:26:18 2002
+++ Zope/lib/python/ZConfig/tests/testConfig.py	Sun Nov 24 18:28:44 2002
@@ -26,9 +26,6 @@
 from ZConfig.Context import Context
 from ZConfig.Common import ConfigurationError, ConfigurationTypeError
 
-warnings.filterwarnings("ignore", r".*\bmktemp\b.*",
-                        RuntimeWarning, __name__)
-
 try:
     __file__
 except NameError:
@@ -135,17 +132,25 @@
                          [("var", "bar"), ("var-one", "splat"),
                           ("var-two", "stuff")])
 
+    def has_key(self):
+        conf = self.load("simplesections.conf")
+        sect = conf.getSection("section", "name")
+        for key in ("var", "var-one", "var-two"):
+            self.assert_(sect.has_key(key))
+            self.assert_(sect.has_key(key.upper()))
+        self.assert_(not sect.has_key("var-three"))
+
     def test_keys(self):
         conf = self.load("simplesections.conf")
         self.assertEqual(sorted_keys(conf),
                          ["var", "var-0", "var-1", "var-2", "var-3",
                           "var-4", "var-5", "var-6"])
-        sect = conf.getSection("section", "name")
+        sect = conf.getSection("section", "Name")
         self.assertEqual(sorted_keys(sect),
                          ["var", "var-one", "var-two"])
-        sect = conf.getSection("section", "delegate")
+        sect = conf.getSection("Section", "delegate")
         self.assertEqual(sorted_keys(sect), ["var", "var-two"])
-        sect = conf.getSection("section", "another")
+        sect = conf.getSection("SECTION", "ANOTHER")
         self.assertEqual(sorted_keys(sect), ["var", "var-three"])
         L = [sect for sect in conf.getChildSections() if not sect.name]
         self.assertEqual(len(L), 3)
@@ -171,20 +176,28 @@
         for k, v in [("var", "bar"), ("var-one", "splat"),
                      ("var-two", "stuff")]:
             self.assertEqual(sect.get(k), v)
+            self.assertEqual(sect.get(k.upper()), v)
         self.assert_(sect.get("not-there") is None)
         sect = conf.getSection("section", "delegate")
         for k, v in [("var", "spam"), ("var-two", "stuff")]:
             self.assertEqual(sect.get(k), v)
-        self.assert_(sect.get("var-one") is None)
+            self.assertEqual(sect.get(k.upper()), v)
+        self.assert_(sect.get("Var-One") is None)
+        L = []
         for sect in conf.getChildSections():
             if sect.type == "trivial":
+                L.append(sect)
                 self.assertEqual(sect.get("var"), "triv")
                 break
+        L2 = conf.getChildSections("TRIVIAL")
+        self.assertEqual(L, L2)
 
     def test_basic_import(self):
         conf = self.load("importer.conf")
         self.assertEqual(conf.get("var1"), "def")
+        self.assertEqual(conf.get("VAR1"), "def")
         self.assertEqual(conf.get("int-var"), "12")
+        self.assertEqual(conf.get("INT-VAR"), "12")
 
     def test_imported_section_override(self):
         conf = self.load("importsections.conf")
@@ -215,8 +228,53 @@
     def test_include(self):
         conf = self.load("include.conf")
         self.assertEqual(conf.get("var1"), "abc")
+        self.assertEqual(conf.get("VAR1"), "abc")
         self.assertEqual(conf.get("var2"), "value2")
+        self.assertEqual(conf.get("VAR2"), "value2")
         self.assertEqual(conf.get("var3"), "value3")
+        self.assertEqual(conf.get("VAR3"), "value3")
+
+    def test_fragment_ident_disallowed(self):
+        self.assertRaises(ConfigurationError,
+                          self.load, "simplesections.conf#another")
+
+    def test_load_from_abspath(self):
+        fn = self.write_tempfile()
+        try:
+            self.check_load_from_path(fn)
+        finally:
+            os.unlink(fn)
+
+    def test_load_from_relpath(self):
+        fn = self.write_tempfile()
+        dir, name = os.path.split(fn)
+        pwd = os.getcwd()
+        try:
+            os.chdir(dir)
+            self.check_load_from_path(name)
+        finally:
+            os.chdir(pwd)
+            os.unlink(fn)
+
+    def test_load_from_fileobj(self):
+        sio = StringIO.StringIO("name value\n"
+                                "<section>\n"
+                                "  name value2\n"
+                                "</section>\n")
+        cf = ZConfig.loadfile(sio)
+        self.assertEqual(cf.get("Name"), "value")
+        self.assertEqual(cf.getSection("Section").get("Name"), "value2")
+
+    def write_tempfile(self):
+        fn = tempfile.mktemp()
+        fp = open(fn, "w")
+        fp.write("key value\n")
+        fp.close()
+        return fn
+
+    def check_load_from_path(self, path):
+        context = Context()
+        context.load(path)
 
     def test_fragment_ident_disallowed(self):
         self.assertRaises(ConfigurationError,