Implement a safer and more predictable interpolation approach.

Closes SF bug #511737.
This commit is contained in:
Fred Drake 2002-10-25 21:52:00 +00:00
parent 98e3b29b59
commit 0eebd5cef9
3 changed files with 74 additions and 1 deletions

View file

@ -289,10 +289,25 @@ class RawConfigParserTestCase(TestCaseBase):
('name', 'value')])
class SafeConfigParserTestCase(ConfigParserTestCase):
config_class = ConfigParser.SafeConfigParser
def test_safe_interpolation(self):
# See http://www.python.org/sf/511737
cf = self.fromstring("[section]\n"
"option1=xxx\n"
"option2=%(option1)s/xxx\n"
"ok=%(option1)s/%%s\n"
"not_ok=%(option2)s/%%s")
self.assertEqual(cf.get("section", "ok"), "xxx/%s")
self.assertEqual(cf.get("section", "not_ok"), "xxx/xxx/%s")
def test_main():
suite = unittest.TestSuite()
suite.addTests([unittest.makeSuite(ConfigParserTestCase),
unittest.makeSuite(RawConfigParserTestCase)])
unittest.makeSuite(RawConfigParserTestCase),
unittest.makeSuite(SafeConfigParserTestCase)])
test_support.run_suite(suite)
if __name__ == "__main__":