[Python-checkins] python/dist/src/Lib/test test_cfgparser.py,1.17,1.18

fdrake@users.sourceforge.net fdrake@users.sourceforge.net
2002年10月25日 14:52:03 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv25460/Lib/test
Modified Files:
	test_cfgparser.py 
Log Message:
Implement a safer and more predictable interpolation approach.
Closes SF bug #511737.
Index: test_cfgparser.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_cfgparser.py,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** test_cfgparser.py	25 Oct 2002 20:42:44 -0000	1.17
--- test_cfgparser.py	25 Oct 2002 21:52:00 -0000	1.18
***************
*** 290,297 ****
 
 
 def test_main():
 suite = unittest.TestSuite()
 suite.addTests([unittest.makeSuite(ConfigParserTestCase),
! unittest.makeSuite(RawConfigParserTestCase)])
 test_support.run_suite(suite)
 
--- 290,312 ----
 
 
+ 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(SafeConfigParserTestCase)])
 test_support.run_suite(suite)
 

AltStyle によって変換されたページ (->オリジナル) /