[Zope-Checkins] CVS: Zope/lib/python/ZConfig/tests - testConfig.py:1.1.4.2

Chris McDonough chrism@zope.com
Tue, 15 Oct 2002 20:53:39 -0400


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

Modified Files:
      Tag: chrism-install-branch
	testConfig.py 
Log Message:
Merging ZConfig on chrism-install-branch with its HEAD.


=== Zope/lib/python/ZConfig/tests/testConfig.py 1.1.4.1 => 1.1.4.2 ===
--- Zope/lib/python/ZConfig/tests/testConfig.py:1.1.4.1	Thu Oct 10 14:29:12 2002
+++ Zope/lib/python/ZConfig/tests/testConfig.py	Tue Oct 15 20:53:38 2002
@@ -13,20 +13,28 @@
 ##############################################################################
 """Tests of the configuration data structures and loader."""
 
-import os.path
+import os
 import sys
+import tempfile
 import unittest
 import urlparse
+import warnings
 
 import ZConfig
 from ZConfig.Context import Context
-from ZConfig.Common import ConfigurationTypeError
+from ZConfig.Common import ConfigurationError, ConfigurationTypeError
+
+warnings.filterwarnings("ignore", r".*\bmktemp\b.*",
+                        RuntimeWarning, __name__)
 
 if __name__ == "__main__":
     __file__ = sys.argv[0]
 
-CONFIG_BASE = ("file://" + os.path.abspath(os.path.dirname(__file__))
-               + "/input/")
+d = os.path.abspath(os.path.dirname(__file__)) + "/input/"
+if os.sep == "\\":
+    CONFIG_BASE = "file:" + d
+else:
+    CONFIG_BASE = "file://" + d
 
 
 class TestBase(unittest.TestCase):
@@ -181,6 +189,39 @@
         self.assertEqual(conf.get("var1"), "abc")
         self.assertEqual(conf.get("var2"), "value2")
         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 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)
 
 
 class NoDelegationContext(Context):