[Zope-Checkins] CVS: Packages/ZConfig/tests - testConfig.py:1.2

Fred L. Drake, Jr. fdrake@acm.org
Thu, 10 Oct 2002 16:42:25 -0400


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

Modified Files:
	testConfig.py 
Log Message:
Allow ZContext.load() to take filesnames as well as URLs, by changing the
underlying Context.load() method.


=== Packages/ZConfig/tests/testConfig.py 1.1 => 1.2 ===
--- Packages/ZConfig/tests/testConfig.py:1.1	Tue Oct  8 17:42:17 2002
+++ Packages/ZConfig/tests/testConfig.py	Thu Oct 10 16:42:24 2002
@@ -13,15 +13,20 @@
 ##############################################################################
 """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
 
+warnings.filterwarnings("ignore", r".*\bmktemp\b.*",
+                        RuntimeWarning, __name__)
+
 if __name__ == "__main__":
     __file__ = sys.argv[0]
 
@@ -181,6 +186,35 @@
         self.assertEqual(conf.get("var1"), "abc")
         self.assertEqual(conf.get("var2"), "value2")
         self.assertEqual(conf.get("var3"), "value3")
+
+    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):