summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_cfgparser.py
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2002-12-31 06:57:25 (GMT)
committerFred Drake <fdrake@acm.org>2002-12-31 06:57:25 (GMT)
commit5478219e11ccd8230c07be731b4079832bd67c20 (patch)
treede3c3fa22aed97297b7aac6bb93adeeaafcb2b7d /Lib/test/test_cfgparser.py
parent00dc5a93c12484c3df57bd3bf2e0c6e78345a98b (diff)
downloadcpython-5478219e11ccd8230c07be731b4079832bd67c20.zip
cpython-5478219e11ccd8230c07be731b4079832bd67c20.tar.gz
cpython-5478219e11ccd8230c07be731b4079832bd67c20.tar.bz2
Add a test that InterpolationError is constructed properly and raised
when expected. Only applies to the ConfigParser and SafeConfigParser classes, not RawConfigParser.
Diffstat (limited to 'Lib/test/test_cfgparser.py')
-rw-r--r--Lib/test/test_cfgparser.py22
1 files changed, 20 insertions, 2 deletions
diff --git a/Lib/test/test_cfgparser.py b/Lib/test/test_cfgparser.py
index b221598..bc0ef5e 100644
--- a/Lib/test/test_cfgparser.py
+++ b/Lib/test/test_cfgparser.py
@@ -149,7 +149,13 @@ class TestCaseBase(unittest.TestCase):
self.get_error(ConfigParser.NoOptionError, "foo", "bar")
def get_error(self, exc, section, option):
- self.assertRaises(exc, self.cf.get, section, option)
+ try:
+ self.cf.get(section, option)
+ except exc, e:
+ return e
+ else:
+ self.fail("expected exception type %s.%s"
+ % (exc.__module__, exc.__name__))
def test_boolean(self):
cf = self.fromstring(
@@ -227,7 +233,11 @@ class TestCaseBase(unittest.TestCase):
"\n"
"[Mutual Recursion]\n"
"foo=%(bar)s\n"
- "bar=%(foo)s\n",
+ "bar=%(foo)s\n"
+ "\n"
+ "[Interpolation Error]\n"
+ "name=%(reference)s\n",
+ # no definition for 'reference'
defaults={"getname": "%(__name__)s"})
def check_items_config(self, expected):
@@ -257,6 +267,14 @@ class ConfigParserTestCase(TestCaseBase):
"something with lots of interpolation (10 steps)")
self.get_error(ConfigParser.InterpolationDepthError, "Foo", "bar11")
+ def test_interpolation_missing_value(self):
+ cf = self.get_interpolation_config()
+ e = self.get_error(ConfigParser.InterpolationError,
+ "Interpolation Error", "name")
+ self.assertEqual(e.reference, "reference")
+ self.assertEqual(e.section, "Interpolation Error")
+ self.assertEqual(e.option, "name")
+
def test_items(self):
self.check_items_config([('default', '<default>'),
('getdefault', '|<default>|'),