[Python-checkins] python/dist/src/Lib/test test_cfgparser.py, 1.21, 1.22 (original) (raw)
fdrake at users.sourceforge.net fdrake at users.sourceforge.net
Mon May 17 23:29:54 EDT 2004
- Previous message: [Python-checkins] python/dist/src/Lib ConfigParser.py,1.64,1.65
- Next message: [Python-checkins] python/dist/src/Doc/lib libcfgparser.tex, 1.36, 1.37
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Update of /cvsroot/python/python/dist/src/Lib/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11581/Lib/test
Modified Files: test_cfgparser.py Log Message: ConfigParser:
- don't allow setting options to non-string values; raise TypeError when the value is set, instead of raising an arbitrary exception later (such as when string interpolation is performed)
- add tests, documentation (closes SF bug #810843)
Index: test_cfgparser.py
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_cfgparser.py,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** test_cfgparser.py 18 May 2004 02:25:51 -0000 1.21 --- test_cfgparser.py 18 May 2004 03:29:52 -0000 1.22
*** 212,215 **** --- 212,246 ---- )
def test_set_string_types(self):
cf = self.fromstring("[sect]\n"
"option1=foo\n")
# Check that we don't get an exception when setting values in
# an existing section using strings:
class mystr(str):
pass
cf.set("sect", "option1", "splat")
cf.set("sect", "option1", mystr("splat"))
cf.set("sect", "option2", "splat")
cf.set("sect", "option2", mystr("splat"))
try:
unicode
except NameError:
pass
else:
cf.set("sect", "option1", unicode("splat"))
cf.set("sect", "option2", unicode("splat"))
def test_set_nonstring_types(self):
cf = self.fromstring("[sect]\n"
"option1=foo\n")
# Check that we get a TypeError when setting non-string values
# in an existing section:
self.assertRaises(TypeError, cf.set, "sect", "option1", 1)
self.assertRaises(TypeError, cf.set, "sect", "option1", 1.0)
self.assertRaises(TypeError, cf.set, "sect", "option1", object())
self.assertRaises(TypeError, cf.set, "sect", "option2", 1)
self.assertRaises(TypeError, cf.set, "sect", "option2", 1.0)
self.assertRaises(TypeError, cf.set, "sect", "option2", object())
# shared by subclasses def get_interpolation_config(self):
- Previous message: [Python-checkins] python/dist/src/Lib ConfigParser.py,1.64,1.65
- Next message: [Python-checkins] python/dist/src/Doc/lib libcfgparser.tex, 1.36, 1.37
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]