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

Chris McDonough chrism@zope.com
Sat, 26 Oct 2002 15:52:19 -0400


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

Modified Files:
      Tag: chrism-install-branch
	testConfig.py 
Log Message:
Merge with HEAD.  Again, sorry for the spew (what's left of it... someone seems to have filtered some of this branch's checkins out).


=== Zope/lib/python/ZConfig/tests/testConfig.py 1.1.4.2 => 1.1.4.3 ===
--- Zope/lib/python/ZConfig/tests/testConfig.py:1.1.4.2	Tue Oct 15 20:53:38 2002
+++ Zope/lib/python/ZConfig/tests/testConfig.py	Sat Oct 26 15:51:48 2002
@@ -14,9 +14,9 @@
 """Tests of the configuration data structures and loader."""
 
 import os
-import sys
 import tempfile
 import unittest
+import urllib
 import urlparse
 import warnings
 
@@ -27,14 +27,14 @@
 warnings.filterwarnings("ignore", r".*\bmktemp\b.*",
                         RuntimeWarning, __name__)
 
-if __name__ == "__main__":
+try:
+    __file__
+except NameError:
+    import sys
     __file__ = sys.argv[0]
 
-d = os.path.abspath(os.path.dirname(__file__)) + "/input/"
-if os.sep == "\\":
-    CONFIG_BASE = "file:" + d
-else:
-    CONFIG_BASE = "file://" + d
+d = os.path.abspath(os.path.join(os.path.dirname(__file__), "input"))
+CONFIG_BASE = "file://%s/" % urllib.pathname2url(d)
 
 
 class TestBase(unittest.TestCase):
@@ -52,6 +52,7 @@
         return conf
 
     def check_simple_gets(self, conf):
+        self.assertEqual(conf.get('empty'), '')
         self.assertEqual(conf.getint('int-var'), 12)
         self.assertEqual(conf.getint('neg-int'), -2)
         self.assertEqual(conf.getfloat('float-var'), 12.02)
@@ -62,13 +63,38 @@
         self.assert_(not conf.getbool('false-var-1'))
         self.assert_(not conf.getbool('false-var-2'))
         self.assert_(not conf.getbool('false-var-3'))
+        self.assertEqual(conf.getlist('list-1'), [])
+        self.assertEqual(conf.getlist('list-2'), ['abc'])
+        self.assertEqual(conf.getlist('list-3'), ['abc', 'def', 'ghi'])
+        self.assertEqual(conf.getlist('list-4'), ['[', 'what', 'now?', ']'])
+        self.assert_(conf.getlist('list-0') is None)
+        missing = Thing()
+        self.assert_(conf.getlist('list-0', missing) is missing)
+        self.assertEqual(conf.getlist('list-1', missing), [])
+        self.assertEqual(conf.getlist('list-2', missing), ['abc'])
+        self.assertEqual(conf.getlist('list-3', missing),
+                         ['abc', 'def', 'ghi'])
+        self.assertEqual(conf.getlist('list-4', missing),
+                         ['[', 'what', 'now?', ']'])
 
 
+class Thing:
+    pass
+
 class ConfigurationTestCase(TestBase):
 
     def test_simple_gets(self):
         conf = self.load("simple.conf")
         self.check_simple_gets(conf)
+
+    def test_simple_getitem(self):
+        conf = self.load("simple.conf")
+        self.assertEqual(conf['empty'], '')
+        self.assertEqual(conf['int-var'], '12')
+        self.assertEqual(conf['list-3'], 'abc def ghi')
+        def check(conf=conf):
+            conf['really-not-there']
+        self.assertRaises(KeyError, check)
 
     def test_type_errors(self):
         conf = self.load("simple.conf")